1818from unittest import TestCase , main
1919from xml .dom import minidom
2020from xml .etree import ElementTree as ET
21+ from functools import partial
2122
2223from qiita_ware .ebi import (SampleAlreadyExistsError , NoXMLError ,
2324 EBISubmission )
2627
2728class TestEBISubmission (TestCase ):
2829 def setUp (self ):
29- self .path = path .dirname (path .abspath (__file__ )) + \
30- '/test_data/test_ebi'
30+ self .path = join (path .dirname (path .abspath (__file__ )), 'test_data' ,
31+ 'test_ebi' )
32+
33+ ebi_test_file = partial (join , self .path )
34+
35+ self .sample1_fp = ebi_test_file ('sample1.fastq.gz' )
36+ self .sample2_fp = ebi_test_file ('sample2.fastq.gz' )
37+ self .sample3_fp = ebi_test_file ('sample3.fastq.gz' )
38+
3139 self .temp_dir = gettempdir ()
3240
3341 def test_init (self ):
@@ -193,15 +201,18 @@ def test_add_sample_prep(self):
193201 new_investigation_type = 'metagenome' )
194202 submission .add_sample ('test1' )
195203 submission .add_sample ('test2' )
204+
196205 submission .add_sample_prep ('test1' , 'ILLUMINA' , 'fastq' ,
197- self .path , 'experiment description' ,
206+ self .sample1_fp , 'experiment description' ,
198207 'library protocol' )
208+
199209 prep_info = submission .samples ['test1' ]['prep' ]
200210 self .assertEqual (prep_info ['platform' ], 'ILLUMINA' )
201- self .assertEqual (prep_info ['file_path' ], self .path )
211+ self .assertEqual (prep_info ['file_path' ], self .sample1_fp )
202212 with self .assertRaises (KeyError ):
203213 submission .add_sample_prep ('test3' , 'ILLUMINA' , 'fastq' ,
204- self .path , 'experiment description' ,
214+ self .sample3_fp ,
215+ 'experiment description' ,
205216 'library protocol' )
206217
207218 def test_add_sample_prep_exception (self ):
@@ -212,11 +223,13 @@ def test_add_sample_prep_exception(self):
212223 submission .add_sample ('test2' )
213224 with self .assertRaises (ValueError ):
214225 submission .add_sample_prep ('test2' , 'DOES-NOT-EXIST' , 'fastq' ,
215- self .path , 'experiment description' ,
226+ self .sample1_fp ,
227+ 'experiment description' ,
216228 'library protocol' )
217229 with self .assertRaises (KeyError ):
218230 submission .add_sample_prep ('test3' , 'DOES-NOT-EXIST' , 'fastq' ,
219- self .path , 'experiment description' ,
231+ self .sample3_fp ,
232+ 'experiment description' ,
220233 'library protocol' )
221234
222235 def test_generate_library_descriptor (self ):
@@ -247,14 +260,17 @@ def test_generate_experiment_xml(self):
247260 new_investigation_type = 'metagenome' )
248261 submission .add_sample ('test1' )
249262 submission .add_sample_prep ('test1' , 'ILLUMINA' , 'fastq' ,
250- 'fakepath' ,
263+ self . sample1_fp ,
251264 'experiment description' ,
252265 'library protocol' )
253266 xmlelement = submission .generate_experiment_xml ()
254267 xml = minidom .parseString (ET .tostring (xmlelement ))
255268 xmlstring = xml .toprettyxml (indent = ' ' , encoding = 'UTF-8' )
256269 obs_stripped = '' .join ([l .strip () for l in xmlstring .splitlines ()])
257- exp_stripped = '' .join ([l .strip () for l in EXPERIMENTXML .splitlines ()])
270+ exp = EXPERIMENTXML % {
271+ 'path' : self .sample1_fp ,
272+ 'organization_prefix' : qiita_config .ebi_organization_prefix }
273+ exp_stripped = '' .join ([l .strip () for l in exp .splitlines ()])
258274 self .assertEqual (obs_stripped , exp_stripped )
259275
260276 def test_generate_run_xml (self ):
@@ -263,7 +279,7 @@ def test_generate_run_xml(self):
263279 new_investigation_type = 'metagenome' )
264280 submission .add_sample ('test1' )
265281 submission .add_sample_prep ('test1' , 'ILLUMINA' , 'fastq' ,
266- join ( self .path , '__init__.py' ) ,
282+ self .sample1_fp ,
267283 'experiment description' ,
268284 'library protocol' )
269285 xmlelement = submission .generate_run_xml ()
@@ -338,13 +354,16 @@ def test_write_experiment_xml(self):
338354 new_investigation_type = 'metagenome' )
339355 submission .add_sample ('test1' )
340356 submission .add_sample_prep ('test1' , 'ILLUMINA' , 'fastq' ,
341- 'fakepath' , 'experiment description' ,
357+ self . sample1_fp , 'experiment description' ,
342358 'library protocol' )
343359 fh , output = mkstemp ()
344360 close (fh )
345361 submission .write_experiment_xml (output )
346362 obs_stripped = '' .join ([l .strip () for l in open (output )])
347- exp_stripped = '' .join ([l .strip () for l in EXPERIMENTXML .splitlines ()])
363+ exp = EXPERIMENTXML % {
364+ 'path' : self .sample1_fp ,
365+ 'organization_prefix' : qiita_config .ebi_organization_prefix }
366+ exp_stripped = '' .join ([l .strip () for l in exp .splitlines ()])
348367 self .assertEqual (obs_stripped , exp_stripped )
349368 remove (output )
350369
@@ -363,7 +382,7 @@ def test_add_samples_from_templates(self):
363382 'ILLUMINA' )
364383 self .assertEqual (
365384 submission .samples ['sample2' ]['prep' ]['file_path' ],
366- self .path + '/sample2.fastq.gz' )
385+ self .sample2_fp )
367386 with self .assertRaises (KeyError ):
368387 submission .samples ['nothere' ]
369388
@@ -388,7 +407,7 @@ def test_from_templates_and_per_sample_fastqs(self):
388407 'ILLUMINA' )
389408 self .assertEqual (
390409 submission .samples ['sample2' ]['prep' ]['file_path' ],
391- self .path + '/sample2.fastq.gz' )
410+ self .sample2_fp )
392411 with self .assertRaises (KeyError ):
393412 submission .samples ['nothere' ]
394413
@@ -553,7 +572,7 @@ def test_generate_curl_command(self):
553572 </EXPERIMENT_ATTRIBUTE>
554573 <EXPERIMENT_ATTRIBUTE>
555574 <TAG>file_path</TAG>
556- <VALUE>fakepath </VALUE>
575+ <VALUE>%(path)s </VALUE>
557576 </EXPERIMENT_ATTRIBUTE>
558577 <EXPERIMENT_ATTRIBUTE>
559578 <TAG>file_type</TAG>
@@ -563,25 +582,29 @@ def test_generate_curl_command(self):
563582 <TAG>library_construction_protocol</TAG>
564583 <VALUE>library protocol</VALUE>
565584 </EXPERIMENT_ATTRIBUTE>
585+ <EXPERIMENT_ATTRIBUTE>
586+ <TAG>md5</TAG>
587+ <VALUE>506d31c82999a2cbcda138a369955e7d</VALUE>
588+ </EXPERIMENT_ATTRIBUTE>
566589 <EXPERIMENT_ATTRIBUTE>
567590 <TAG>platform</TAG>
568591 <VALUE>ILLUMINA</VALUE>
569592 </EXPERIMENT_ATTRIBUTE>
570593 </EXPERIMENT_ATTRIBUTES>
571594 </EXPERIMENT>
572595</EXPERIMENT_SET>
573- """ % { 'organization_prefix' : qiita_config . ebi_organization_prefix }
596+ """
574597
575598RUNXML = """
576599<?xml version="1.0" encoding="UTF-8"?>
577600<RUN_SET xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:no\
578601 NamespaceSchemaLocation="ftp://ftp.sra.ebi.ac.uk/meta/xsd/sra_1_3/SRA.run.xsd">
579- <RUN alias="%(study_alias)s___init__.py_run " center_name="CCME-COLORADO">
602+ <RUN alias="%(study_alias)s_sample1.fastq.gz_run " center_name="CCME-COLORADO">
580603 <EXPERIMENT_REF refname="%(organization_prefix)s_ppdid_001:test1"/>
581604 <DATA_BLOCK>
582605 <FILES>
583- <FILE checksum="612cbff13a4f0e236e5e62ac2e00329a " checksum_method=\
584- "MD5" filename="%(ebi_dir)s/__init__.py " filetype="fastq" \
606+ <FILE checksum="506d31c82999a2cbcda138a369955e7d " checksum_method=\
607+ "MD5" filename="%(ebi_dir)s/sample1.fastq.gz " filetype="fastq" \
585608 quality_scoring_system="phred"/>
586609 </FILES>
587610 </DATA_BLOCK>
0 commit comments