diff --git a/qiita_ware/commands.py b/qiita_ware/commands.py
index dc8928022..5ff3cf88f 100644
--- a/qiita_ware/commands.py
+++ b/qiita_ware/commands.py
@@ -7,7 +7,7 @@
# -----------------------------------------------------------------------------
from os.path import join, isdir
-from os import makedirs
+from os import makedirs, remove
from functools import partial
from tempfile import mkdtemp
from gzip import open as gzopen
@@ -43,6 +43,11 @@ def submit_EBI(preprocessed_data_id, action, send, fastq_dir_fp=None):
True to actually send the files
fastq_dir_fp : str, optional
The fastq filepath
+
+ Notes
+ -----
+ If fastq_dir_fp is passed, it must not contain any empty files, or
+ gzipped empty files
"""
preprocessed_data = PreprocessedData(preprocessed_data_id)
preprocessed_data_id_str = str(preprocessed_data_id)
@@ -99,9 +104,14 @@ def submit_EBI(preprocessed_data_id, action, send, fastq_dir_fp=None):
list(sample_template)):
demux_samples.add(samp)
sample_fp = join(fastq_dir_fp, "%s.fastq.gz" % samp)
+ wrote_sequences = False
with gzopen(sample_fp, 'w') as fh:
for record in iterator:
fh.write(record)
+ wrote_sequences = True
+
+ if not wrote_sequences:
+ remove(sample_fp)
output_dir = fastq_dir_fp + '_submission'
diff --git a/qiita_ware/test/test_data/__init__.py b/qiita_ware/test/test_data/__init__.py
deleted file mode 100644
index 744315f60..000000000
--- a/qiita_ware/test/test_data/__init__.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from __future__ import division
-
-# -----------------------------------------------------------------------------
-# Copyright (c) 2014--, The Qiita Development Team.
-#
-# Distributed under the terms of the BSD 3-clause License.
-#
-# The full license is in the file LICENSE, distributed with this software.
-# -----------------------------------------------------------------------------
-
-# Do not modify this file as TestEBISubmission.test_generate_run_xml depends
-# on this file having a constant MD5 sum.
diff --git a/qiita_ware/test/test_data/demux.fastq b/qiita_ware/test/test_data/demux.fastq
deleted file mode 100644
index ac9efe4ac..000000000
--- a/qiita_ware/test/test_data/demux.fastq
+++ /dev/null
@@ -1,24 +0,0 @@
-@sample1_1
-ATC
-+
-ABC
-@sample1_2
-AGT
-+
-ABC
-@sample2_1
-GCT
-+
-ABC
-@sample2_2
-CGT
-+
-ABC
-@sample3_1
-AAA
-+
-ABC
-@sample3_2
-AAA
-+
-ABC
diff --git a/qiita_ware/test/test_data/sample1.fastq b/qiita_ware/test/test_data/sample1.fastq
deleted file mode 100644
index 9868291fd..000000000
--- a/qiita_ware/test/test_data/sample1.fastq
+++ /dev/null
@@ -1 +0,0 @@
->sample1
diff --git a/qiita_ware/test/test_data/sample2.fastq b/qiita_ware/test/test_data/sample2.fastq
deleted file mode 100644
index 16638396d..000000000
--- a/qiita_ware/test/test_data/sample2.fastq
+++ /dev/null
@@ -1 +0,0 @@
->sample2
diff --git a/qiita_ware/test/test_data/sample3.fastq b/qiita_ware/test/test_data/sample3.fastq
deleted file mode 100644
index ea65e1bf9..000000000
--- a/qiita_ware/test/test_data/sample3.fastq
+++ /dev/null
@@ -1 +0,0 @@
->sample3
diff --git a/qiita_ware/test/test_data/test_ebi/sample1.fastq.gz b/qiita_ware/test/test_data/test_ebi/sample1.fastq.gz
new file mode 100644
index 000000000..2df9c489c
Binary files /dev/null and b/qiita_ware/test/test_data/test_ebi/sample1.fastq.gz differ
diff --git a/qiita_ware/test/test_data/test_ebi/sample2.fastq.gz b/qiita_ware/test/test_data/test_ebi/sample2.fastq.gz
new file mode 100644
index 000000000..cef3ddb66
Binary files /dev/null and b/qiita_ware/test/test_data/test_ebi/sample2.fastq.gz differ
diff --git a/qiita_ware/test/test_data/test_ebi/sample3.fastq.gz b/qiita_ware/test/test_data/test_ebi/sample3.fastq.gz
new file mode 100644
index 000000000..ee070043c
Binary files /dev/null and b/qiita_ware/test/test_data/test_ebi/sample3.fastq.gz differ
diff --git a/qiita_ware/test/test_ebi.py b/qiita_ware/test/test_ebi.py
index 3abe3dba9..372de4bd0 100644
--- a/qiita_ware/test/test_ebi.py
+++ b/qiita_ware/test/test_ebi.py
@@ -14,10 +14,10 @@
from os import close, remove, path
from os.path import join
from tempfile import mkstemp, gettempdir
-from shutil import rmtree
from unittest import TestCase, main
from xml.dom import minidom
from xml.etree import ElementTree as ET
+from functools import partial
from qiita_ware.ebi import (SampleAlreadyExistsError, NoXMLError,
EBISubmission)
@@ -26,15 +26,16 @@
class TestEBISubmission(TestCase):
def setUp(self):
- self.path = path.dirname(path.abspath(__file__)) + '/test_data'
- self.temp_dir = gettempdir()
- self.demux_output_dir = join(self.temp_dir, 'demux_output')
+ self.path = join(path.dirname(path.abspath(__file__)), 'test_data',
+ 'test_ebi')
+
+ ebi_test_file = partial(join, self.path)
- def tearDown(self):
- try:
- rmtree(self.demux_output_dir)
- except:
- pass
+ self.sample1_fp = ebi_test_file('sample1.fastq.gz')
+ self.sample2_fp = ebi_test_file('sample2.fastq.gz')
+ self.sample3_fp = ebi_test_file('sample3.fastq.gz')
+
+ self.temp_dir = gettempdir()
def test_init(self):
e = EBISubmission('2', 'Study Title', 'Study Abstract',
@@ -199,15 +200,18 @@ def test_add_sample_prep(self):
new_investigation_type='metagenome')
submission.add_sample('test1')
submission.add_sample('test2')
+
submission.add_sample_prep('test1', 'ILLUMINA', 'fastq',
- self.path, 'experiment description',
+ self.sample1_fp, 'experiment description',
'library protocol')
+
prep_info = submission.samples['test1']['prep']
self.assertEqual(prep_info['platform'], 'ILLUMINA')
- self.assertEqual(prep_info['file_path'], self.path)
+ self.assertEqual(prep_info['file_path'], self.sample1_fp)
with self.assertRaises(KeyError):
submission.add_sample_prep('test3', 'ILLUMINA', 'fastq',
- self.path, 'experiment description',
+ self.sample3_fp,
+ 'experiment description',
'library protocol')
def test_add_sample_prep_exception(self):
@@ -218,11 +222,13 @@ def test_add_sample_prep_exception(self):
submission.add_sample('test2')
with self.assertRaises(ValueError):
submission.add_sample_prep('test2', 'DOES-NOT-EXIST', 'fastq',
- self.path, 'experiment description',
+ self.sample1_fp,
+ 'experiment description',
'library protocol')
with self.assertRaises(KeyError):
submission.add_sample_prep('test3', 'DOES-NOT-EXIST', 'fastq',
- self.path, 'experiment description',
+ self.sample3_fp,
+ 'experiment description',
'library protocol')
def test_generate_library_descriptor(self):
@@ -253,14 +259,17 @@ def test_generate_experiment_xml(self):
new_investigation_type='metagenome')
submission.add_sample('test1')
submission.add_sample_prep('test1', 'ILLUMINA', 'fastq',
- 'fakepath',
+ self.sample1_fp,
'experiment description',
'library protocol')
xmlelement = submission.generate_experiment_xml()
xml = minidom.parseString(ET.tostring(xmlelement))
xmlstring = xml.toprettyxml(indent=' ', encoding='UTF-8')
obs_stripped = ''.join([l.strip() for l in xmlstring.splitlines()])
- exp_stripped = ''.join([l.strip() for l in EXPERIMENTXML.splitlines()])
+ exp = EXPERIMENTXML % {
+ 'path': self.sample1_fp,
+ 'organization_prefix': qiita_config.ebi_organization_prefix}
+ exp_stripped = ''.join([l.strip() for l in exp.splitlines()])
self.assertEqual(obs_stripped, exp_stripped)
def test_generate_run_xml(self):
@@ -269,7 +278,7 @@ def test_generate_run_xml(self):
new_investigation_type='metagenome')
submission.add_sample('test1')
submission.add_sample_prep('test1', 'ILLUMINA', 'fastq',
- join(self.path, '__init__.py'),
+ self.sample1_fp,
'experiment description',
'library protocol')
xmlelement = submission.generate_run_xml()
@@ -344,13 +353,16 @@ def test_write_experiment_xml(self):
new_investigation_type='metagenome')
submission.add_sample('test1')
submission.add_sample_prep('test1', 'ILLUMINA', 'fastq',
- 'fakepath', 'experiment description',
+ self.sample1_fp, 'experiment description',
'library protocol')
fh, output = mkstemp()
close(fh)
submission.write_experiment_xml(output)
obs_stripped = ''.join([l.strip() for l in open(output)])
- exp_stripped = ''.join([l.strip() for l in EXPERIMENTXML.splitlines()])
+ exp = EXPERIMENTXML % {
+ 'path': self.sample1_fp,
+ 'organization_prefix': qiita_config.ebi_organization_prefix}
+ exp_stripped = ''.join([l.strip() for l in exp.splitlines()])
self.assertEqual(obs_stripped, exp_stripped)
remove(output)
@@ -369,7 +381,7 @@ def test_add_samples_from_templates(self):
'ILLUMINA')
self.assertEqual(
submission.samples['sample2']['prep']['file_path'],
- self.path + '/sample2.fastq.gz')
+ self.sample2_fp)
with self.assertRaises(KeyError):
submission.samples['nothere']
@@ -394,7 +406,7 @@ def test_from_templates_and_per_sample_fastqs(self):
'ILLUMINA')
self.assertEqual(
submission.samples['sample2']['prep']['file_path'],
- self.path + '/sample2.fastq.gz')
+ self.sample2_fp)
with self.assertRaises(KeyError):
submission.samples['nothere']
@@ -559,7 +571,7 @@ def test_generate_curl_command(self):
file_path
- fakepath
+ %(path)s
file_type
@@ -576,18 +588,19 @@ def test_generate_curl_command(self):
-""" % {'organization_prefix': qiita_config.ebi_organization_prefix}
+"""
RUNXML = """
-
+
-