4 from six.moves import StringIO
8 except ImportError as e:
9 import simplejson as json
11 from django.test import TestCase
13 from samples.samples_factory import LibraryFactory, LibraryTypeFactory, \
15 from experiments.experiments_factory import FlowCellFactory, LaneFactory
17 from htsworkflow.auth import apidata
18 from htsworkflow.pipelines.retrieve_config import \
19 format_gerald_config, \
24 class RetrieveTestCases(TestCase):
28 def test_format_gerald(self):
29 fc = FlowCellFactory.create(flowcell_id='FC12150')
30 library = LibraryFactory.create()
31 lane = LaneFactory(flowcell=fc, library=library, lane_number=3)
33 flowcell_request = self.client.get('/experiments/config/FC12150/json',
35 self.failUnlessEqual(flowcell_request.status_code, 200)
36 flowcell_info = json.loads(flowcell_request.content)['result']
38 options = getCombinedOptions(['-f','FC12150','-g',os.getcwd()])
39 genome_map = {library.library_species.scientific_name: '/tmp/build' }
41 config = format_gerald_config(options, flowcell_info, genome_map)
42 config_lines = config.split('\n')
43 lane3 = [ line for line in config_lines if re.search('Lane3', line) ]
44 self.failUnlessEqual(len(lane3), 1)
45 expected = '# Lane3: {} | {}'.format(library.id, library.library_name)
46 self.failUnlessEqual(lane3[0], expected)
47 human = [ line for line in config_lines if re.search('build', line) ]
48 self.failUnlessEqual(len(human), 1)
49 self.failUnlessEqual(human[0], '3:ELAND_GENOME /tmp/build')
52 def test_format_sample_sheet(self):
54 fc = FlowCellFactory.create(flowcell_id=fcid)
55 library_type = LibraryTypeFactory(can_multiplex=True)
56 multiplex_index1 = MultiplexIndexFactory(adapter_type=library_type)
57 multiplex_index2 = MultiplexIndexFactory(adapter_type=library_type)
59 library1 = LibraryFactory.create(
60 library_type=library_type,
61 multiplex_id=multiplex_index1.multiplex_id)
62 library2 = LibraryFactory.create(
63 library_type=library_type,
64 multiplex_id=multiplex_index2.multiplex_id)
66 lane1l1 = LaneFactory(flowcell=fc, library=library1, lane_number=1)
67 lane1l2 = LaneFactory(flowcell=fc, library=library2, lane_number=1)
68 lane2l1 = LaneFactory(flowcell=fc, library=library1, lane_number=2)
69 lane2l2 = LaneFactory(flowcell=fc, library=library2, lane_number=2)
71 url = '/experiments/config/%s/json' % (fcid,)
72 flowcell_request = self.client.get(url, apidata)
73 self.failUnlessEqual(flowcell_request.status_code, 200)
74 flowcell_info = json.loads(flowcell_request.content)['result']
76 options = getCombinedOptions(['-f',fcid,'-g',os.getcwd(),])
79 save_sample_sheet(output, options, flowcell_info)
82 sheet = list(csv.DictReader(output))
83 name1 = library1.id + '_index' + library1.index_sequences().keys()[0]
84 name2 = library2.id + '_index' + library2.index_sequences().keys()[0]
85 expected = [{'SampleProject': name1,
86 'Index': library1.index_sequences().values()[0],
89 {'SampleProject': name2,
90 'Index': library2.index_sequences().values()[0],
93 {'SampleProject': name1,
94 'Index': library1.index_sequences().values()[0],
97 {'SampleProject': name2,
98 'Index': library2.index_sequences().values()[0],
102 self.failUnlessEqual(len(sheet), len(expected))
103 for s, e in zip(sheet, expected):
105 self.failUnlessEqual(s[key], e[key],
106 "%s != %s for key %s" % (s[key],e[key], key))