From: Diane Trout Date: Sat, 10 Jan 2015 00:28:26 +0000 (-0800) Subject: Convert experiments modules to use factories instead of fixtures. X-Git-Url: http://woldlab.caltech.edu/gitweb/?a=commitdiff_plain;h=a9469e1ba2604307a0c4a0b41639aa11632b4151;p=htsworkflow.git Convert experiments modules to use factories instead of fixtures. And then propogate those changes throughout the test cases --- diff --git a/experiments/experiments_factory.py b/experiments/experiments_factory.py new file mode 100644 index 0000000..49421ee --- /dev/null +++ b/experiments/experiments_factory.py @@ -0,0 +1,85 @@ +import datetime + +import factory +from factory.django import DjangoModelFactory +from . import models +from samples.samples_factory import LibraryFactory + + +class ClusterStationFactory(DjangoModelFactory): + class Meta: + model = models.ClusterStation + + name = factory.Sequence(lambda x: 'cluster station %d' % (x,)) + isdefault = True + + +class SequencerFactory(DjangoModelFactory): + class Meta: + model = models.Sequencer + + name = factory.Sequence(lambda x: 'sequencer %d' % (x,)) + instrument_name = factory.Sequence(lambda x: 'instrument name %d' % (x,)) + serial_number = factory.Sequence(lambda x: 'squencer serial number %d' % (x,)) + model = 'HiSeq 1' + active = True + isdefault = True + comment = 'example sequencer' + + +class FlowCellFactory(DjangoModelFactory): + class Meta: + model = models.FlowCell + + flowcell_id = '1234AAAAXX' + run_date = datetime.datetime.now() + advanced_run = False + paired_end = True + read_length = 100 + control_lane = 0 + cluster_station = factory.SubFactory(ClusterStationFactory) + sequencer = factory.SubFactory(SequencerFactory) + notes = 'flowcell notes' + + +class LaneFactory(DjangoModelFactory): + class Meta: + model = models.Lane + + flowcell = factory.SubFactory(FlowCellFactory) + lane_number = 1 + library = factory.SubFactory(LibraryFactory) + pM = 1.2 + cluster_estimate = 12345 + status = 2 + comment = 'lane comment' + + +class DataRunFactory(DjangoModelFactory): + class Meta: + model = models.DataRun + + flowcell = factory.SubFactory(FlowCellFactory) + runfolder_name = '102030_UAW-EAS22_1234AAAAXX' + result_dir = runfolder_name + '/Unaligned' + run_start_time = datetime.datetime.now() + cycle_start = 1 + cycle_stop = 101 + run_status = 2 + image_software = 'RTA' + image_version = '1.1' + basecall_software = 'RTA' + basecall_version = '2.2' + alignment_software = 'eland' + alignment_version = '2.2' + comment = 'comment' + + +class FileTypeFactory(DjangoModelFactory): + class Meta: + model = models.FileType + + name = 'file type' + mimetype = 'application/file' + regex = '.file$' + diff --git a/experiments/fixtures/initial_data.json b/experiments/fixtures/initial_data.json deleted file mode 100644 index f364502..0000000 --- a/experiments/fixtures/initial_data.json +++ /dev/null @@ -1,122 +0,0 @@ -[ - { "model": "experiments.FileType", - "pk": 1, - "fields": { - "name": "run_xml", - "mimetype": "application/vnd.htsworkflow-run-xml", - "regex": "run.*\\.xml\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 2, - "fields": { - "name": "Summary.htm", - "mimetype": "text/html", - "regex": "Summary\\.htm\\Z(?ms)" - } - }, - - { "model": "experiments.FileType", - "pk": 3, - "fields": { - "name": "IVC All", - "mimetype": "image/png", - "regex": "s_(?P[0-9])_all\\.png\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 4, - "fields": { - "name": "IVC Call", - "mimetype": "image/png", - "regex": "s_(?P[0-9])_call\\.png\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 5, - "fields": { - "name": "IVC Percent All", - "mimetype": "image/png", - "regex": "s_(?P[0-9])_percent_all\\.png\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 6, - "fields": { - "name": "IVC Percent Base", - "mimetype": "image/png", - "regex": "s_(?P[0-9])_percent_base\\.png\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 7, - "fields": { - "name": "IVC Percent Call", - "mimetype": "image/png", - "regex": "s_(?P[0-9])_percent_call\\.png\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 8, - "fields": { - "name": "GERALD Scores", - "regex": "scores\\.tar\\.bz2\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 9, - "fields": { - "name": "ELAND Result", - "mimetype": "chemical/seq-na-eland", - "regex": "s_(?P[0-9])((?P[1-4])_)?_eland_result\\.txt\\.bz2\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 10, - "fields": { - "name": "ELAND Multi", - "mimetype": "chemical/seq-na-eland", - "regex": "s_(?P[0-9])((?P[1-4])_)?_eland_multi\\.txt\\.bz2\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 11, - "fields": { - "name": "ELAND Extended", - "mimetype": "chemical/seq-na-eland", - "regex": "s_(?P[0-9])((?P[1-4])_)?_eland_extended\\.txt\\.bz2\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 12, - "fields": { - "name": "ELAND Export", - "mimetype": "chemical/seq-na-eland", - "regex": "s_(?P[0-9])((?P[1-4])_)?_export\\.txt\\.bz2\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 13, - "fields": { - "name": "SRF", - "mimetype": "chemical/seq-na-srf", - "regex": ".*_(?P[1-8])\\.srf\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 14, - "fields": { - "name": "QSEQ tarfile", - "mimetype": "chemical/seq-na-qseq", - "regex": ".*_l(?P[1-8])_r(?P[1-4])\\.tar\\.bz2\\Z(?ms)" - } - }, - { "model": "experiments.FileType", - "pk": 15, - "fields": { - "name": "HiSeq Fastq", - "mimetype": "chemical/seq-na-fastq", - "regex": "(?P[0-9]+)_(NoIndex|[AGCT]+)_L(?P[0-9]+)_R(?P[12])_(?P[0-9]+)\\.fastq\\.gz" - } - } -] diff --git a/experiments/fixtures/test_flowcells.json b/experiments/fixtures/test_flowcells.json deleted file mode 100644 index 15d00c6..0000000 --- a/experiments/fixtures/test_flowcells.json +++ /dev/null @@ -1,1273 +0,0 @@ -[ - {"pk": 5, "model": "auth.user", - "fields": { - "username": "test", - "first_name": "", - "last_name": "", - "is_active": true, - "is_superuser": false, - "is_staff": false, - "last_login": "2009-01-01T00:00:01-0800", - "groups": [], - "user_permissions": [], - "password": "sha1$foo$5e4eefec1144a04becfb7da79244f07c487fc345", - "email": "", - "date_joined": "2009-01-01T00:01:01-0800" - } - }, - {"pk": 5, "model": "samples.htsuser", - "fields" : {} - }, - {"pk": 6, "model": "auth.user", - "fields": { - "username": "admintest", - "first_name": "", - "last_name": "", - "is_active": true, - "is_superuser": false, - "is_staff": true, - "last_login": "2009-01-01T00:00:01-0800", - "groups": [], - "user_permissions": [], - "password": "sha1$foo$5e4eefec1144a04becfb7da79244f07c487fc345", - "email": "", - "date_joined": "2009-01-01T00:01:01-0800" - } - }, - {"pk": 6, "model": "samples.htsuser", - "fields" : {} - }, - {"pk": 7, "model": "auth.user", - "fields": { - "username": "supertest", - "first_name": "", - "last_name": "", - "is_active": true, - "is_superuser": true, - "is_staff": true, - "last_login": "2009-01-01T00:00:01-0800", - "groups": [], - "user_permissions": [], - "password": "sha1$foo$5e4eefec1144a04becfb7da79244f07c487fc345", - "email": "", - "date_joined": "2009-01-01T00:01:01-0800" - } - }, - {"pk": 7, "model": "samples.htsuser", - "fields" : {} - }, - {"pk": 1, "model": "samples.affiliation", - "fields": { - "users": [5], - "contact": "group 1", - "name": "affiliation 1", - "email": "pk1@example.com" - } - }, - {"pk": 2, "model": "samples.affiliation", - "fields": { - "users": [6], - "contact": "group 2", - "name": "affiliation 2", - "email": "pk2@example.com" - } - }, - {"pk": 3, "model": "samples.affiliation", - "fields": { - "users": [], - "contact": "group 3", - "name": "affiliation 3", - "email": "pk3@example.com" - } - }, - {"pk": 4, "model": "samples.affiliation", - "fields": { - "users": [], - "contact": "group 4", - "name": "affiliation 4", - "email": "pk1@example.com" - } - }, - {"pk": 5, "model": "samples.affiliation", - "fields": { - "users": [], - "contact": "group 5", - "name": "affiliation 5", - "email": "pk5@example.com" - } - }, - {"pk": 1, "model": "experiments.clusterstation", - "fields": {"name": "old", "isdefault": false}}, - {"pk": 2, "model": "experiments.clusterstation", - "fields": {"name": "loaner", "isdefault": true}}, - {"pk": 3, "model": "experiments.clusterstation", - "fields": {"name": "new", "isdefault": false}}, - {"pk": 1, "model": "experiments.sequencer", - "fields": { "name": "Rotifer (HWI-EAS229)", - "model": "Illumina Genome Analyzer I", - "active": false, - "isdefault": false }}, - {"pk": 2, "model": "experiments.sequencer", - "fields": {"name": "Tardigrade", - "instrument_name": "ILLUMINA-EC5D15", - "model": "Illumina Genome Analyzer IIx", - "active": true, - "isdefault": true} - }, - {"pk": 3, "model": "experiments.sequencer", - "fields": {"name": "Sequenced somewhere else.", - "model": "Unknown", - "active": true, - "isdefault": false}}, - {"pk": 153, "model": "experiments.flowcell", - "fields": { - "paired_end": true, - "run_date": "2007-09-27T22:12:13-0800", - "read_length": 36, - "notes": "", - "advanced_run": false, - "control_lane": 2, - "cluster_station": 3, - "sequencer": 2, - "flowcell_id": "FC12150" - } - }, - {"pk": 1193, "model": "experiments.lane", - "fields": { - "comment": "No change in cluster numbers, despite slight increase in pM", - "library": "10981", - "cluster_estimate": 129000, - "flowcell": 153, - "lane_number": 1, - "pM": "8" - } - }, - {"pk": 1192, "model": "experiments.lane", - "fields": { - "comment": "Other library", - "library": "11070", - "cluster_estimate": 132000, - "flowcell": 153, - "lane_number": 1, - "pM": "7" - } - }, - - {"pk": "10981", "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 400, - "library_name": "Paired End Multiplexed Sp-BAC", - "creation_date": "2009-07-21", - "cell_line": 1, - "library_species": 10, - "library_type": null, - "made_by": "Igor", - "affiliations": [ - 1,2 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "Done", - "tags": [], - "made_for": "Andy Cameron", - "amplified_from_sample": null, - "notes": "Combined 10957-10968", - "undiluted_concentration": "5.1", - "successful_pM": null, - "experiment_type": 10, - "antibody": null - } - }, - {"pk": 1194, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11016", - "cluster_estimate": 152000, - "flowcell": 153, - "lane_number": 2, - "pM": "7" - } - }, - { - "pk": "11006", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 325, - "library_name": "Paired End Pfl #3 MP 7/24/9", - "creation_date": "2009-08-05", - "cell_line": 1, - "library_species": 8, - "library_type": 2, - "made_by": "Lorian", - "affiliations": [ - 3 - ], - "replicate": 1, - "condition": 1, - "hidden": true, - "stopping_point": "1A", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "7/31/2009 16:08:22\tColor: Blue", - "undiluted_concentration": null, - "successful_pM": null, - "experiment_type": 8, - "antibody": null - } - }, - { - "pk": "11016", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 325, - "library_name": "Paired End Pfl #3 MP 7/24/9 a", - "creation_date": "2009-08-06", - "cell_line": 1, - "library_species": 2, - "library_type": 2, - "made_by": "Lorian", - "affiliations": [ - 2 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "", - "amplified_from_sample": 11006, - "notes": "7/31/2009 16:08:22\tColor: Blue", - "undiluted_concentration": "35.5", - "successful_pM": null, - "experiment_type": 8, - "antibody": null - } - }, - {"pk": 1195, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "SL039", - "cluster_estimate": 162000, - "flowcell": 153, - "lane_number": 3, - "pM": "7" - } - }, - { - "pk": "SL039", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 99 GM12892", - "creation_date": "2009-08-25", - "cell_line": 1, - "library_species": 8, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 3,4 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": 11006, - "notes": "fragment size = 300 bp, Amicon filtered\r\nnanodrop: 56.3", - "undiluted_concentration": "28.7", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 1196, "model": "experiments.lane", - "fields": { - "comment": "This lane's library had the second lowest concentration of all the libraries built at the same time (2.05ng/ul)", - "library": "11060", - "cluster_estimate": 24000, - "flowcell": 153, - "lane_number": 4, - "pM": "7" - } - }, - { - "pk": "11060", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 100 VC_CN_4_M_MBB1185_s1", - "creation_date": "2009-09-01", - "cell_line": 1, - "library_species": 8, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 5 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": 11006, - "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 24.2", - "undiluted_concentration": "2.05", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 1197, "model": "experiments.lane", - "fields": { - "comment": "stuff", - "library": "11061", - "cluster_estimate": 140000, - "flowcell": 153, - "lane_number": 5, - "pM": "7", - "status": 2 - } - }, - { - "pk": "11061", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 101 VC_CN_4_M_MBB1185_s2", - "creation_date": "2009-09-01", - "cell_line": 1, - "library_species": 8, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 2,4 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": null, - "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 33.1", - "undiluted_concentration": "12.9", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 1198, "model": "experiments.lane", - "fields": { - "comment": "This lane's library had the lowest concentration of all the libraries built at the same time (1.2ng/ul)", - "library": "11062", - "cluster_estimate": 2000, - "flowcell": 153, - "lane_number": 6, - "pM": "7", - "status": 0 - } - }, - { - "pk": "11062", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 102 VC_AU_8_M_MBB4721_s1", - "creation_date": "2009-09-01", - "cell_line": 1, - "library_species": 8, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 4,5 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": null, - "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 13.9", - "undiluted_concentration": "1.2", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 1199, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11063", - "cluster_estimate": 120000, - "flowcell": 153, - "lane_number": 7, - "pM": "7" - } - }, - { - "pk": "11063", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 103 VC_AU_8_M_MBB4721_s2", - "creation_date": "2009-09-01", - "cell_line": 1, - "library_species": 8, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 1,3 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": null, - "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 46.9", - "undiluted_concentration": "24.5", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 1200, "model": "experiments.lane", - "fields": { - "comment": "This lane's library had the third lowest concentration of all the libraries built at the same time (5.21ng/ul), but gave perfectly normal cluster numbers", - "library": "11064", - "cluster_estimate": 157000, - "flowcell": 153, - "lane_number": 8, - "pM": "7" - } - }, - { - "pk": "11064", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 104 VC_CN_7_M_MBB4898_s1", - "creation_date": "2009-09-01", - "cell_line": 1, - "library_species": 8, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 3,5 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": null, - "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 20.4", - "undiluted_concentration": "5.21", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 152, "model": "experiments.flowcell", - "fields": { - "paired_end": false, - "run_date": "2009-09-10T18:30:15-0800", - "read_length": 38, - "notes": "328461 4897273 RGT-0248815\r\n328479 4897265 RGT-0249274\r\n330421 4822845 SR-0005496", - "advanced_run": false, - "control_lane": 4, - "cluster_station": 3, - "sequencer": 1, - "flowcell_id": "42JTNAAXX" - } - }, - {"pk": 1185, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11035", - "cluster_estimate": 174000, - "flowcell": 152, - "lane_number": 1, - "pM": "7" - } - }, - { - "pk": "11035", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 95 Gilberto_d3_control_LTA", - "creation_date": "2009-08-25", - "cell_line": 1, - "library_species": 9, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 3 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": null, - "notes": "fragment size = 300 bp, Amicon filtered\r\nnanodrop: 67.1", - "undiluted_concentration": "28.5", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 1186, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11037", - "cluster_estimate": 173000, - "flowcell": 152, - "lane_number": 2, - "pM": "7" - } - }, - { - "pk": "11037", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 97 Kuntz_PDHT", - "creation_date": "2009-08-25", - "cell_line": 1, - "library_species": 3, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 4 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": null, - "notes": "fragment size = 300 bp, Amicon filtered\r\nnanodrop: 52.7", - "undiluted_concentration": "25.5", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 1187, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11045", - "cluster_estimate": 198000, - "flowcell": 152, - "lane_number": 3, - "pM": "7" - } - }, - { - "pk": "11045", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 250, - "library_name": "FLDN1 8/3/9 anti-AcH3 chip B6 a", - "creation_date": "2009-08-26", - "cell_line": null, - "library_species": 9, - "library_type": 1, - "made_by": "Lorian", - "affiliations": [ - 5 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "2A", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/21/2009 11:57:54\tColor: Yellow", - "undiluted_concentration": "20.5", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - {"pk": 1188, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11046", - "cluster_estimate": 212000, - "flowcell": 152, - "lane_number": 4, - "pM": "7"} - }, - { - "pk": "11046", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 250, - "library_name": "FLDN1 7/8/9 anti-DiMeH3K4 chip B6 a", - "creation_date": "2009-08-26", - "cell_line": null, - "library_species": 9, - "library_type": 1, - "made_by": "Lorian", - "affiliations": [ - 4 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "2A", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/21/2009 11:57:54\tColor: Blue", - "undiluted_concentration": "23.9", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - {"pk": 1189, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11054", - "cluster_estimate": 49000, - "flowcell": 152, - "lane_number": 5, - "pM": "7" - } - }, - { - "pk": "11054", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 225, - "library_name": "HNDHT HLH hnd-1 strain HT115 fed anti-hlh-1 2% fix plate a", - "creation_date": "2009-08-31", - "cell_line": null, - "library_species": 3, - "library_type": 1, - "made_by": "Lorian", - "affiliations": [ - 1 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/26/2009 14:46:56\tColor: Purple", - "undiluted_concentration": "1.47", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - {"pk": 1190, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11056", - "cluster_estimate": 48000, - "flowcell": 152, - "lane_number": 6, - "pM": "7" - } - }, - { - "pk": "11056", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 225, - "library_name": "HNDM3 HLH hnd-1 strain mex-3 fed anti-hlh-1 2% fix plate a", - "creation_date": "2009-08-31", - "cell_line": null, - "library_species": 3, - "library_type": 1, - "made_by": "Lorian", - "affiliations": [ - 2 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/26/2009 14:46:56\tColor: Black", - "undiluted_concentration": "1.42", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - {"pk": 1191, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11057", - "cluster_estimate": 4000, - "flowcell": 152, - "lane_number": 7, - "pM": "7" - } - }, - { - "pk": "11057", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 225, - "library_name": "HNDM3 4H8 hnd-1 strain mex-3 fed 4H8 2% fix plate a", - "creation_date": "2009-08-31", - "cell_line": null, - "library_species": 3, - "library_type": 1, - "made_by": "Lorian", - "affiliations": [ - 3 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/26/2009 14:46:56\tColor: Orange.", - "undiluted_concentration": "1.3", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - {"pk": 1192, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11065", - "cluster_estimate": 5000, - "flowcell": 152, - "lane_number": 8, - "pM": "7" - } - }, - { - "pk": "11065", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 105 Kuntz PDM3", - "creation_date": "2009-09-01", - "cell_line": 1, - "library_species": 3, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 4 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": null, - "notes": "300 bp gel fragment, Amicon filtered\r\nnanodrop: 30.5", - "undiluted_concentration": "2.47", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 151, "model": "experiments.flowcell", - "fields": { - "paired_end": false, - "run_date": "2009-09-08T15:39:28-0800", - "read_length": 38, - "notes": "Rebuild of broken flowcell\r\n\r\n328461 4820241 RGT-0215719\r\n328479 4897265 RGT-0249510\r\n330421 4822845 SR-0005402\r\n", - "advanced_run": false, - "control_lane": 5, - "cluster_station": 3, - "sequencer": 2, - "flowcell_id": "42JU1AAXX" - } - }, - {"pk": 1177, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11034", - "cluster_estimate": 177000, - "flowcell": 151, - "lane_number": 1, - "pM": "7" - } - }, - {"pk": 1178, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11036", - "cluster_estimate": 169000, - "flowcell": 151, - "lane_number": 2, - "pM": "7" - } - }, - { - "pk": "11036", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 96 Kuntz_PDE1", - "creation_date": "2009-08-25", - "cell_line": 1, - "library_species": 3, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 5 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": null, - "notes": "fragment size = 300 bp", - "undiluted_concentration": "30.6", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - { - "pk": "11034", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired ends 94 Gilberto_d3_denerv_LTA", - "creation_date": "2009-08-25", - "cell_line": 1, - "library_species": 9, - "library_type": 2, - "made_by": "Brian Williams", - "affiliations": [ - 1 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "Brian Williams", - "amplified_from_sample": null, - "notes": "fragment size = 300 bp", - "undiluted_concentration": "27", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - { - "pk": "12044", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 225, - "library_name": "Pooled Indexed Test", - "creation_date": "2009-08-26", - "cell_line": null, - "library_species": 9, - "library_type": 5, - "multiplex_id": "1,2,3", - "made_by": "Lorian", - "affiliations": [ - 2 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "2A", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/21/2009 11:57:54\tColor: Orange", - "undiluted_concentration": "22.4", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - { - "pk": "13044", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 225, - "library_name": "Dual Indexed Test", - "creation_date": "2009-08-26", - "cell_line": null, - "library_species": 9, - "library_type": 9, - "multiplex_id": "N701-N501", - "made_by": "Lorian", - "affiliations": [ - 2 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "2A", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/21/2009 11:57:54\tColor: Orange", - "undiluted_concentration": "22.4", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - { - "pk": "11045", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 225, - "library_name": "Simple Indexed Test", - "creation_date": "2009-08-26", - "cell_line": null, - "library_species": 9, - "library_type": 5, - "multiplex_id": "1", - "made_by": "Lorian", - "affiliations": [ - 2 - ], - "replicate": 2, - "condition": null, - "hidden": false, - "stopping_point": "2A", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/21/2009 11:57:54\tColor: Orange", - "undiluted_concentration": "22.4", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - {"pk": 1179, - "model": "experiments.lane", - "fields": { - "comment": "", - "library": "12044", - "cluster_estimate": 196000, - "flowcell": 151, - "lane_number": 3, - "pM": "7" - } - }, - {"pk": 1279, - "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11045", - "cluster_estimate": 196000, - "flowcell": 151, - "lane_number": 3, - "pM": "7" - } - }, - {"pk": 1379, - "model": "experiments.lane", - "fields": { - "comment": "", - "library": "13044", - "cluster_estimate": 196000, - "flowcell": 151, - "lane_number": 4, - "pM": "7" - } - }, - - { - "pk": "11044", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 225, - "library_name": "p300 60h C2 FA KF 12/22/8 a", - "creation_date": "2009-08-26", - "cell_line": null, - "library_species": 9, - "library_type": 1, - "made_by": "Lorian", - "affiliations": [ - 3 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "2A", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/21/2009 11:57:54\tColor: Orange.", - "undiluted_concentration": "22.4", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - {"pk": 1180, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11047", - "cluster_estimate": 200000, - "flowcell": 151, - "lane_number": 4, - "pM": "7" - } - }, - { - "pk": "11047", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 250, - "library_name": "FLDN1 7/8/9 anti-TriMeH3K27 chip B6 a", - "creation_date": "2009-08-26", - "cell_line": null, - "library_species": 9, - "library_type": 1, - "made_by": "Lorian", - "affiliations": [ - 4 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "2A", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/21/2009 11:57:54\tColor: Green", - "undiluted_concentration": "24.9", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - {"pk": 1181, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11055", - "cluster_estimate": 104000, - "flowcell": 151, - "lane_number": 5, - "pM": "7" - } - }, - { - "pk": "11055", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 225, - "library_name": "HNDHT 4H8 hnd-1 strain HT115 fed 4H8 2% fix plate a", - "creation_date": "2009-08-31", - "cell_line": null, - "library_species": 3, - "library_type": 1, - "made_by": "Lorian", - "affiliations": [ - 5 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "1Aa", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "8/26/2009 14:46:56\tColor: White.", - "undiluted_concentration": "2.17", - "successful_pM": null, - "experiment_type": 2, - "antibody": null - } - }, - {"pk": 1182, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11067", - "cluster_estimate": 168000, - "flowcell": 151, - "lane_number": 6, - "pM": "7" - } - }, - { - "pk": "11067", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 325, - "library_name": "Paired End SP-BAC Barcoding test 250-300 bp", - "creation_date": "2009-09-03", - "cell_line": 1, - "library_species": 10, - "library_type": 2, - "made_by": "Igor", - "affiliations": [ - 1 - ], - "replicate": 1, - "condition": 1, - "hidden": false, - "stopping_point": "Done", - "tags": [], - "made_for": "Andy Cameron", - "amplified_from_sample": null, - "notes": "12 SP BACs", - "undiluted_concentration": "1.45", - "successful_pM": null, - "experiment_type": 8, - "antibody": null - } - }, - {"pk": 1183, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11069", - "cluster_estimate": 184000, - "flowcell": 151, - "lane_number": 7, - "pM": "7" - } - }, - { - "pk": "11069", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired End AG-3d-1 AG domain of floral meristem day 3, rep 1", - "creation_date": "2009-09-02", - "cell_line": null, - "library_species": 6, - "library_type": 2, - "made_by": "Yuling Jiao", - "affiliations": [ - 2 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "Done", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "nanodrop: Xng/ul.", - "undiluted_concentration": "18.3", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 1184, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11070", - "cluster_estimate": 182000, - "flowcell": 151, - "lane_number": 8, - "pM": "7" - } - }, - { - "pk": "11070", - "model": "samples.library", - "fields": { - "ten_nM_dilution": false, - "gel_cut_size": 300, - "library_name": "Paired End AG-5d-1 AG domain of floral meristem day 5, rep 1", - "creation_date": "2009-09-02", - "cell_line": null, - "library_species": 6, - "library_type": 2, - "made_by": "Yuling Jiao", - "affiliations": [ - 3 - ], - "replicate": 1, - "condition": null, - "hidden": false, - "stopping_point": "Done", - "tags": [], - "made_for": "", - "amplified_from_sample": null, - "notes": "nanodrop: 40ng/ul\r\nCalibrated qbit with standards.\r\nMeasured 2ul library with qbit using HS kit.\r\n", - "undiluted_concentration": "20.3", - "successful_pM": null, - "experiment_type": 4, - "antibody": null - } - }, - {"pk": 200, "model": "experiments.flowcell", - "fields": { - "paired_end": true, - "run_date": "2007-09-27T22:12:13-0800", - "read_length": 36, - "notes": "", - "advanced_run": false, - "control_lane": 2, - "cluster_station": 3, - "sequencer": 2, - "flowcell_id": "30012AAXX (failed)" - } - }, - {"pk": 201, "model": "experiments.lane", - "fields": { - "comment": "", - "library": "11070", - "cluster_estimate": 182000, - "flowcell": 200, - "lane_number": 8, - "pM": "7" - } - } -] diff --git a/experiments/fixtures/woldlab.json b/experiments/fixtures/woldlab.json deleted file mode 100644 index b058925..0000000 --- a/experiments/fixtures/woldlab.json +++ /dev/null @@ -1,89 +0,0 @@ -[ { "model": "experiments.Sequencer", - "pk": 1, - "fields": { - "name": "Rotifer", - "instrument_name": "ILLUMINA-33A494", - "serial_number": "", - "model": "Illumina Genome Analyzer II", - "active": false, - "isdefault": false, - "comment": "after 2010 pipeline name, was exchanged for hiseq" - } - }, - { "model": "experiments.Sequencer", - "pk": 2, - "fields": { - "name": "Tardigrade", - "instrument_name": "ILLUMINA-EC5D15", - "serial_number": "", - "model": "Illumina Genome Analyzer IIx", - "active": true, - "isdefault": false, - "comment": "after 2010 pipeline name" - } - }, - { "model": "experiments.Sequencer", - "pk": 3, - "fields": { - "name": "Elsewhere", - "instrument_name": "", - "serial_number": "", - "model": "Unknown", - "active": false, - "isdefault": false, - "comment": "Sequenced somewhere else" - } - }, - { "model": "experiments.Sequencer", - "pk": 4, - "fields": { - "name": "Volvox", - "instrument_name": "HWI-ST0787", - "serial_number": "", - "model": "Illumina HiSeq 2000", - "active": true, - "isdefault": true, - "comment": "" - } - }, - { "model": "experiments.Sequencer", - "pk": 5, - "fields": { - "name": "Tardigrade (older)", - "instrument_name": "HWUSI-EAS627", - "serial_number": "", - "model": "Illumina Genome Analyzer II", - "active": false, - "isdefault": false, - "comment": "earlier version of tardigrade" - } - }, - { "model": "experiments.Sequencer", - "pk": 6, - "fields": { - "name": "Rotifer (older)", - "instrument_name": "HWUSI-EAS229", - "serial_number": "", - "model": "Illumina Genome Analyzer II", - "active": false, - "isdefault": false, - "comment": "earlier rotifer name" - } - }, - { "model": "experiments.Sequencer", - "pk": 7, - "fields": { - "name": "First sequencer", - "instrument_name": "USI-EAS44", - "serial_number": "", - "model": "Illumina Genome Analyzer I", - "active": false, - "isdefault": false, - "comment": "our first sequencer" - } - }, - { "model": "experiments.ClusterStation", - "pk": 3, - "fields": { "name": "new", "isdefault": false } - } -] diff --git a/experiments/test_experiments.py b/experiments/test_experiments.py index ba27db4..f0c3610 100644 --- a/experiments/test_experiments.py +++ b/experiments/test_experiments.py @@ -20,9 +20,14 @@ from django.test.utils import setup_test_environment, teardown_test_environment from django.db import connection from django.conf import settings -from .models import ClusterStation, DataRun, Sequencer, FlowCell, FileType, \ +from .models import ClusterStation, cluster_station_default, \ + DataRun, Sequencer, FlowCell, FileType, \ find_file_type_metadata_from_filename +from samples.models import HTSUser from .experiments import flowcell_information, lanes_for +from .experiments_factory import ClusterStationFactory, FlowCellFactory, LaneFactory +from samples.samples_factory import AffiliationFactory, HTSUserFactory, \ + LibraryFactory, LibraryTypeFactory, MultiplexIndexFactory from htsworkflow.auth import apidata from htsworkflow.util.ethelp import validate_xhtml @@ -36,14 +41,23 @@ from django.db import connection class ExperimentsTestCases(TestCase): - fixtures = ['initial_data.json', - 'test_flowcells.json', - ] - def setUp(self): + # Generate at least one fleshed out example flowcell self.tempdir = tempfile.mkdtemp(prefix='htsw-test-experiments-') settings.RESULT_HOME_DIR = self.tempdir + self.password = 'password' + self.user_odd = HTSUserFactory(username='user-odd') + self.user_odd.set_password(self.password) + self.affiliation_odd = AffiliationFactory(name='affiliation-odd', users=[self.user_odd]) + self.user_even = HTSUserFactory(username='user-even') + self.user_even.set_password(self.password) + self.affiliation_even = AffiliationFactory(name='affiliation-even', users=[self.user_even]) + self.admin = HTSUserFactory.create(username='admin', is_staff=True, is_superuser=True) + self.admin.set_password(self.password) + self.admin.save() + + self.fc12150 = FlowCellFactory(flowcell_id='FC12150') self.fc1_id = 'FC12150' self.fc1_root = os.path.join(self.tempdir, self.fc1_id) os.mkdir(self.fc1_root) @@ -53,12 +67,30 @@ class ExperimentsTestCases(TestCase): shutil.copy(os.path.join(TESTDATA_DIR, runxml), os.path.join(self.fc1_dir, runxml)) for i in range(1,9): + affiliation = self.affiliation_odd if i % 2 == 1 else self.affiliation_even + library = LibraryFactory(id="1215" + str(i)) + library.affiliations.add(affiliation) + lane = LaneFactory(flowcell=self.fc12150, lane_number=i, library=library) shutil.copy( os.path.join(TESTDATA_DIR, 'woldlab_070829_USI-EAS44_0017_FC11055_1.srf'), os.path.join(self.fc1_dir, 'woldlab_070829_SERIAL_FC12150_%d.srf' %(i,)) ) + self.fc12150.save() + + self.fc42jtn = FlowCellFactory(flowcell_id='42JTNAAXX') + self.fc42jtn_lanes = [] + for i in range(1,9): + affiliation = self.affiliation_odd if i % 2 == 1 else self.affiliation_even + library_type = LibraryTypeFactory(can_multiplex=True) + multiplex_index = MultiplexIndexFactory(adapter_type=library_type) + library = LibraryFactory(id="1300" + str(i), + library_type=library_type, + multiplex_id=multiplex_index.multiplex_id) + library.affiliations.add(affiliation) + lane = LaneFactory(flowcell=self.fc42jtn, lane_number=(i % 2) + 1, library=library) + self.fc42jtn_lanes.append(lane) self.fc2_dir = os.path.join(self.tempdir, '42JTNAAXX') os.mkdir(self.fc2_dir) @@ -73,6 +105,10 @@ class ExperimentsTestCases(TestCase): """ Check the code that packs the django objects into simple types. """ + fc12150 = self.fc12150 + fc42jtn = self.fc42jtn + fc42ju1 = FlowCellFactory(flowcell_id='42JU1AAXX') + for fc_id in [u'FC12150', u"42JTNAAXX", "42JU1AAXX"]: fc_dict = flowcell_information(fc_id) fc_django = FlowCell.objects.get(flowcell_id=fc_id) @@ -142,15 +178,16 @@ class ExperimentsTestCases(TestCase): self.assertEqual(response.status_code, 200) flowcell = json.loads(response.content)['result'] + # library id is 12150 + lane number (1-8), so 12153 lane_contents = flowcell['lane_set']['3'] lane_library = lane_contents[0] - self.assertEqual(lane_library['library_id'], 'SL039') + self.assertEqual(lane_library['library_id'], '12153') - response = self.client.get('/samples/library/SL039/json', apidata) + response = self.client.get('/samples/library/12153/json', apidata) self.assertEqual(response.status_code, 200) - library_sl039 = json.loads(response.content)['result'] + library_12153 = json.loads(response.content)['result'] - self.assertEqual(library_sl039['library_id'], 'SL039') + self.assertEqual(library_12153['library_id'], '12153') def test_raw_id_field(self): """ @@ -164,10 +201,9 @@ class ExperimentsTestCases(TestCase): This tests to make sure that the value entered in the raw library id field matches the library id looked up. """ - expected_ids = [u'10981',u'11016',u'SL039',u'11060', - u'11061',u'11062',u'11063',u'11064'] - self.client.login(username='supertest', password='BJOKL5kAj6aFZ6A5') - response = self.client.get('/admin/experiments/flowcell/153/') + expected_ids = [ u'1215{}'.format(i) for i in range(1,9) ] + self.assertTrue(self.client.login(username=self.admin.username, password=self.password)) + response = self.client.get('/admin/experiments/flowcell/{}/'.format(self.fc12150.id)) tree = fromstring(response.content) for i in range(0,8): @@ -185,8 +221,8 @@ class ExperimentsTestCases(TestCase): Make sure the library page includes links to the flowcell pages. That work with flowcell IDs that have parenthetical comments. """ - self.client.login(username='supertest', password='BJOKL5kAj6aFZ6A5') - response = self.client.get('/library/11070/') + self.assertTrue(self.client.login(username=self.admin.username, password=self.password)) + response = self.client.get('/library/12151/') self.assertEqual(response.status_code, 200) status = validate_xhtml(response.content) if status is not None: self.assertTrue(status) @@ -194,45 +230,41 @@ class ExperimentsTestCases(TestCase): tree = fromstring(response.content) flowcell_spans = tree.xpath('//span[@property="libns:flowcell_id"]', namespaces=NSMAP) - self.assertEqual(flowcell_spans[1].text, '30012AAXX (failed)') + self.assertEqual(flowcell_spans[1].text, 'FC12150') failed_fc_span = flowcell_spans[1] failed_fc_a = failed_fc_span.getparent() # make sure some of our RDF made it. self.assertEqual(failed_fc_a.get('typeof'), 'libns:IlluminaFlowcell') - self.assertEqual(failed_fc_a.get('href'), '/flowcell/30012AAXX/') + self.assertEqual(failed_fc_a.get('href'), '/flowcell/FC12150/') fc_response = self.client.get(failed_fc_a.get('href')) self.assertEqual(fc_response.status_code, 200) status = validate_xhtml(response.content) if status is not None: self.assertTrue(status) - fc_lane_response = self.client.get('/flowcell/30012AAXX/8/') + fc_lane_response = self.client.get('/flowcell/FC12150/8/') self.assertEqual(fc_lane_response.status_code, 200) status = validate_xhtml(response.content) if status is not None: self.assertTrue(status) - def test_pooled_multiplex_id(self): - fc_dict = flowcell_information('42JU1AAXX') - lane_contents = fc_dict['lane_set'][3] - self.assertEqual(len(lane_contents), 2) - lane_dict = multi_lane_to_dict(lane_contents) - - self.assertEqual(lane_dict['12044']['index_sequence'], - {u'1': u'ATCACG', - u'2': u'CGATGT', - u'3': u'TTAGGC'}) - self.assertEqual(lane_dict['11045']['index_sequence'], - {u'1': u'ATCACG'}) + fc_dict = flowcell_information(self.fc42jtn.flowcell_id) + lane_contents = fc_dict['lane_set'][2] + self.assertEqual(len(lane_contents), len(self.fc42jtn_lanes) / 2) + lane_dict = multi_lane_to_dict(lane_contents) + self.assertTrue(self.fc42jtn_lanes[0].library.multiplex_id in \ + lane_dict['13001']['index_sequence']) + self.assertTrue(self.fc42jtn_lanes[2].library.multiplex_id in \ + lane_dict['13003']['index_sequence']) def test_lanes_for(self): """ Check the code that packs the django objects into simple types. """ - user = 'test' + user = self.user_odd.username lanes = lanes_for(user) - self.assertEqual(len(lanes), 5) + self.assertEqual(len(lanes), 8) response = self.client.get('/experiments/lanes_for/%s/json' % (user,), apidata) lanes_json = json.loads(response.content)['result'] @@ -247,12 +279,12 @@ class ExperimentsTestCases(TestCase): """ Do we get something meaningful back when the user isn't attached to anything? """ - user = 'supertest' - lanes = lanes_for(user) + user = HTSUserFactory.create(username='supertest') + lanes = lanes_for(user.username) self.assertEqual(len(lanes), 0) response = self.client.get('/experiments/lanes_for/%s/json' % (user,), apidata) - lanes_json = json.loads(response.content) + self.assertEqual(response.status_code, 404) def test_lanes_for_no_user(self): """ @@ -291,11 +323,11 @@ class ExperimentsTestCases(TestCase): srf4 = result_dict['FC12150/C1-37/woldlab_070829_SERIAL_FC12150_4.srf'] self.assertEqual(srf4.file_type, srf_file_type) - self.assertEqual(srf4.library_id, '11060') + self.assertEqual(srf4.library_id, '12154') self.assertEqual(srf4.data_run.flowcell.flowcell_id, 'FC12150') self.assertEqual( srf4.data_run.flowcell.lane_set.get(lane_number=4).library_id, - '11060') + '12154') self.assertEqual( srf4.pathname, os.path.join(settings.RESULT_HOME_DIR, srf4.relative_pathname)) @@ -346,15 +378,15 @@ class ExperimentsTestCases(TestCase): model = get_model() - expected = {'1': ['11034'], - '2': ['11036'], - '3': ['12044','11045'], - '4': ['11047','13044'], - '5': ['11055'], - '6': ['11067'], - '7': ['11069'], - '8': ['11070']} - url = '/flowcell/42JU1AAXX/' + expected = {'1': ['12151'], + '2': ['12152'], + '3': ['12153'], + '4': ['12154'], + '5': ['12155'], + '6': ['12156'], + '7': ['12157'], + '8': ['12158']} + url = '/flowcell/{}/'.format(self.fc12150.flowcell_id) response = self.client.get(url) self.assertEqual(response.status_code, 200) status = validate_xhtml(response.content) @@ -378,18 +410,14 @@ class ExperimentsTestCases(TestCase): count = 0 for r in query.execute(model): count += 1 - self.assertEqual(fromTypedNode(r['flowcell_id']), u'42JU1AAXX') + self.assertEqual(fromTypedNode(r['flowcell_id']), u'FC12150') lane_id = fromTypedNode(r['lane_id']) library_id = fromTypedNode(r['library_id']) self.assertTrue(library_id in expected[lane_id]) - self.assertEqual(count, 10) + self.assertEqual(count, 8) class TestFileType(TestCase): - fixtures = ['initial_data.json', - 'test_flowcells.json', - ] - def test_file_type_unicode(self): file_type_objects = FileType.objects name = 'QSEQ tarfile' @@ -448,34 +476,56 @@ class TestFileType(TestCase): self.assertEqual(result.get('end', None), end) class TestEmailNotify(TestCase): - fixtures = ['initial_data.json', - 'test_flowcells.json'] + def setUp(self): + self.password = 'foo27' + self.user = HTSUserFactory.create(username='test') + self.user.set_password(self.password) + self.user.save() + self.admin = HTSUserFactory.create(username='admintest', is_staff=True) + self.admin.set_password(self.password) + self.admin.save() + self.super = HTSUserFactory.create(username='supertest', is_staff=True, is_superuser=True) + self.super.set_password(self.password) + self.super.save() + + self.library = LibraryFactory.create() + self.affiliation = AffiliationFactory() + self.affiliation.users.add(self.user) + self.library.affiliations.add(self.affiliation) + self.fc = FlowCellFactory.create() + self.lane = LaneFactory(flowcell=self.fc, lane_number=1, library=self.library) + + self.url = '/experiments/started/{}/'.format(self.fc.id) def test_started_email_not_logged_in(self): - response = self.client.get('/experiments/started/153/') + response = self.client.get(self.url) self.assertEqual(response.status_code, 302) def test_started_email_logged_in_user(self): - self.client.login(username='test', password='BJOKL5kAj6aFZ6A5') - response = self.client.get('/experiments/started/153/') + self.assertTrue(self.client.login(username=self.user.username, password=self.password)) + response = self.client.get(self.url) self.assertEqual(response.status_code, 302) def test_started_email_logged_in_staff(self): - self.client.login(username='admintest', password='BJOKL5kAj6aFZ6A5') - response = self.client.get('/experiments/started/153/') + self.assertTrue(self.admin.is_staff) + admin = HTSUser.objects.get(username=self.admin.username) + self.assertTrue(admin.is_staff) + self.assertTrue(admin.check_password(self.password)) + self.assertTrue(self.client.login(username=self.admin.username, password=self.password)) + response = self.client.get(self.url) self.assertEqual(response.status_code, 200) def test_started_email_send(self): - self.client.login(username='admintest', password='BJOKL5kAj6aFZ6A5') - response = self.client.get('/experiments/started/153/') + self.assertTrue(self.client.login(username=self.admin.username, password=self.password)) + response = self.client.get(self.url) self.assertEqual(response.status_code, 200) - self.assertTrue('pk1@example.com' in response.content) - self.assertTrue('Lane #8 : (11064) Paired ends 104' in response.content) + self.assertTrue(self.affiliation.email in response.content) + self.assertTrue(self.library.library_name in response.content) - response = self.client.get('/experiments/started/153/', {'send':'1','bcc':'on'}) + response = self.client.get(self.url, {'send':'1','bcc':'on'}) self.assertEqual(response.status_code, 200) - self.assertEqual(len(mail.outbox), 4) + self.assertEqual(len(mail.outbox), 2) bcc = set(settings.NOTIFICATION_BCC).copy() bcc.update(set(settings.MANAGERS)) for m in mail.outbox: @@ -486,12 +536,14 @@ class TestEmailNotify(TestCase): """ Can we navigate between the flowcell and email forms properly? """ - self.client.login(username='supertest', password='BJOKL5kAj6aFZ6A5') - response = self.client.get('/experiments/started/153/') + admin_url = '/admin/experiments/flowcell/{}/'.format(self.fc.id) + self.client.login(username=self.admin.username, password=self.password) + response = self.client.get(self.url) self.assertEqual(response.status_code, 200) - self.assertTrue(re.search('Flowcell FC12150', response.content)) + #print("email navigation content:", response.content) + self.assertTrue(re.search(self.fc.flowcell_id, response.content)) # require that navigation back to the admin page exists - self.assertTrue(re.search('[^<]+', response.content)) + self.assertTrue(re.search('[^<]+'.format(admin_url), response.content)) def multi_lane_to_dict(lane): """Convert a list of lane entries into a dictionary indexed by library ID @@ -499,9 +551,10 @@ def multi_lane_to_dict(lane): return dict( ((x['library_id'],x) for x in lane) ) class TestSequencer(TestCase): - fixtures = ['initial_data.json', - 'test_flowcells.json', - ] + def setUp(self): + self.fc12150 = FlowCellFactory(flowcell_id='FC12150') + self.library = LibraryFactory(id="12150") + self.lane = LaneFactory(flowcell=self.fc12150, lane_number=1, library=self.library) def test_name_generation(self): seq = Sequencer() @@ -512,11 +565,9 @@ class TestSequencer(TestCase): self.assertEqual(unicode(seq), "Seq1 (HWI-SEQ1)") def test_lookup(self): - fc = FlowCell.objects.get(pk=153) - self.assertEqual(fc.sequencer.model, - "Illumina Genome Analyzer IIx") - self.assertEqual(fc.sequencer.instrument_name, - "ILLUMINA-EC5D15") + fc = self.fc12150 + self.assertEqual(fc.sequencer.model, 'HiSeq 1') + self.assertTrue(fc.sequencer.instrument_name.startswith('instrument name')), # well actually we let the browser tack on the host name url = fc.get_absolute_url() self.assertEqual(url, '/flowcell/FC12150/') @@ -530,20 +581,21 @@ class TestSequencer(TestCase): self.assertEqual(seq_by[0].attrib['rel'], 'libns:sequenced_by') seq = seq_by[0].getchildren() self.assertEqual(len(seq), 1) - self.assertEqual(seq[0].attrib['about'], '/sequencer/2') + sequencer = '/sequencer/' + str(self.fc12150.sequencer.id) + self.assertEqual(seq[0].attrib['about'], sequencer) self.assertEqual(seq[0].attrib['typeof'], 'libns:Sequencer') name = seq[0].xpath('./span[@property="libns:sequencer_name"]') self.assertEqual(len(name), 1) - self.assertEqual(name[0].text, 'Tardigrade') + self.assertTrue(name[0].text.startswith('sequencer ')) instrument = seq[0].xpath( './span[@property="libns:sequencer_instrument"]') self.assertEqual(len(instrument), 1) - self.assertEqual(instrument[0].text, 'ILLUMINA-EC5D15') + self.assertTrue(instrument[0].text.startswith('instrument name')) model = seq[0].xpath( './span[@property="libns:sequencer_model"]') self.assertEqual(len(model), 1) - self.assertEqual(model[0].text, 'Illumina Genome Analyzer IIx') + self.assertEqual(model[0].text, 'HiSeq 1') def test_flowcell_with_rdf_validation(self): from htsworkflow.util.rdfhelp import add_default_schemas, \ @@ -578,7 +630,7 @@ class TestSequencer(TestCase): add_default_schemas(model) inference = Infer(model) - url = '/lane/1193' + url = '/lane/{}'.format(self.lane.id) response = self.client.get(url) self.assertEqual(response.status_code, 200) status = validate_xhtml(response.content)