4 from StringIO import StringIO
9 import simplejson as json
11 from django.test import TestCase
13 from htsworkflow.frontend.auth import apidata
14 from htsworkflow.pipelines.retrieve_config import \
15 format_gerald_config, \
19 class RetrieveTestCases(TestCase):
20 fixtures = ['initial_data.json',
21 'test_flowcells.json']
26 def test_format_gerald(self):
27 flowcell_request = self.client.get('/experiments/config/FC12150/json', apidata)
28 self.failUnlessEqual(flowcell_request.status_code, 200)
29 flowcell_info = json.loads(flowcell_request.content)
31 options = getCombinedOptions(['-f','FC12150','-g',os.getcwd()])
32 genome_map = {u'Homo sapiens': '/tmp/hg18' }
34 config = format_gerald_config(options, flowcell_info, genome_map)
35 config_lines = config.split('\n')
36 lane3 = [ line for line in config_lines if re.search('Lane3', line) ]
37 self.failUnlessEqual(len(lane3), 1)
38 self.failUnlessEqual(lane3[0], '# Lane3: SL039 | Paired ends 99 GM12892')
39 human = [ line for line in config_lines if re.search('hg18', line) ]
40 self.failUnlessEqual(len(human), 1)
41 self.failUnlessEqual(human[0], '345678:ELAND_GENOME /tmp/hg18')
42 # we changed the api to force unknown genomes to be sequencing
43 sequencing = [ line for line in config_lines if re.search('sequence_pair', line) ]
44 self.failUnlessEqual(len(sequencing), 2)
47 def test_format_sample_sheet(self):
49 url = '/experiments/config/%s/json' % (fcid,)
50 flowcell_request = self.client.get(url, apidata)
51 self.failUnlessEqual(flowcell_request.status_code, 200)
52 flowcell_info = json.loads(flowcell_request.content)
54 options = getCombinedOptions(['-f',fcid,'-g',os.getcwd(),])
57 save_sample_sheet(output, options, flowcell_info)
60 sheet = list(csv.DictReader(output))
61 expected = [{'SampleProject': '12044_index1',
65 {'SampleProject': '12044_index2',
69 {'SampleProject': '12044_index3',
73 {'SampleProject': '11045_index1',
77 {'SampleProject': '13044_indexN701-N501',
78 'Index': 'TAAGGCGA-TAGATCGC',
82 self.failUnlessEqual(len(sheet), len(expected))
83 for s, e in zip(sheet, expected):
85 self.failUnlessEqual(s[key], e[key],
86 "%s != %s for key %s" % (s[key],e[key], key))