-
Couldn't load subscription status.
- Fork 79
WIP: Fixing EBI code #1540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Fixing EBI code #1540
Changes from 5 commits
f45e4ec
4701ee7
2613d8d
9e67451
18161b6
a2f2a59
42adced
ebddbe0
3eb8431
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -327,6 +327,16 @@ def test_can_be_submitted_to_ebi(self): | |
| self.assertTrue(qdb.artifact.Artifact(3).can_be_submitted_to_ebi) | ||
| self.assertFalse(qdb.artifact.Artifact(4).can_be_submitted_to_ebi) | ||
|
|
||
| def test_is_submitted_to_ebi(self): | ||
| with self.assertRaises( | ||
| qdb.exceptions.QiitaDBOperationNotPermittedError): | ||
| qdb.artifact.Artifact(1).is_submitted_to_ebi | ||
| self.assertTrue(qdb.artifact.Artifact(2).is_submitted_to_ebi) | ||
| self.assertFalse(qdb.artifact.Artifact(3).is_submitted_to_ebi) | ||
| with self.assertRaises( | ||
| qdb.exceptions.QiitaDBOperationNotPermittedError): | ||
| qdb.artifact.Artifact(4).is_submitted_to_ebi | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Completely optional - I personally like to create separate tests for assertRaises and other checks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
|
||
| def test_ebi_run_accessions(self): | ||
| exp = {'1.SKB1.640202': 'ERR0000001', | ||
| '1.SKB2.640194': 'ERR0000002', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,7 @@ | |
| from qiita_db.logger import LogEntry | ||
| from qiita_db.ontology import Ontology | ||
| from qiita_db.util import convert_to_id, get_mountpoint | ||
| from qiita_db.study import Study | ||
| from qiita_db.data import PreprocessedData | ||
| from qiita_db.metadata_template import PrepTemplate, SampleTemplate | ||
| from qiita_db.artifact import Artifact | ||
|
|
||
|
|
||
| def clean_whitespace(text): | ||
|
|
@@ -42,7 +40,7 @@ def clean_whitespace(text): | |
| class EBISubmission(object): | ||
| """Define an EBI submission, generate submission files and submit | ||
|
|
||
| Submit a preprocessed data to EBI | ||
| Submit an artifact to EBI | ||
|
|
||
| The steps for EBI submission are: | ||
| 1. Validate that we have all required info to submit | ||
|
|
@@ -53,8 +51,8 @@ class EBISubmission(object): | |
|
|
||
| Parameters | ||
| ---------- | ||
| preprocessed_data_id : int | ||
| The preprocesssed data id to submit | ||
| artifact_id : int | ||
| The artifact id to submit | ||
| action : str | ||
| The action to perform. Valid options see | ||
| EBISubmission.valid_ebi_actions | ||
|
|
@@ -63,9 +61,11 @@ class EBISubmission(object): | |
| ------ | ||
| EBISubmissionError | ||
| - If the action is not in EBISubmission.valid_ebi_actions | ||
| - If the preprocessed data has been already submitted to EBI | ||
| - If the status of the study attached to the preprocessed data is | ||
| submitting | ||
| - If the artifact cannot be submitted to EBI | ||
| - If the artifact has more than one prep template | ||
| - If the artifact has been already submitted to EBI and the action | ||
| is different from 'MODIFY' | ||
| - If the status of the study attached to the artifact is `submitting` | ||
| - If the prep template investigation type is not in the | ||
| ena_ontology.terms or not in the ena_ontology.user_defined_terms | ||
| - If the submission is missing required EBI fields either in the sample | ||
|
|
@@ -93,7 +93,7 @@ class EBISubmission(object): | |
| xsi_noNSL = "ftp://ftp.sra.ebi.ac.uk/meta/xsd/sra_1_3/SRA.%s.xsd" | ||
| experiment_library_fields = ['library_strategy'] | ||
|
|
||
| def __init__(self, preprocessed_data_id, action): | ||
| def __init__(self, artifact_id, action): | ||
| error_msgs = [] | ||
|
|
||
| if action not in self.valid_ebi_actions: | ||
|
|
@@ -105,14 +105,28 @@ def __init__(self, preprocessed_data_id, action): | |
|
|
||
| ena_ontology = Ontology(convert_to_id('ENA', 'ontology')) | ||
| self.action = action | ||
| self.preprocessed_data = PreprocessedData(preprocessed_data_id) | ||
| self.study = Study(self.preprocessed_data.study) | ||
| self.sample_template = SampleTemplate(self.study.sample_template) | ||
| self.prep_template = PrepTemplate(self.preprocessed_data.prep_template) | ||
|
|
||
| if self.preprocessed_data.is_submitted_to_ebi and action != 'MODIFY': | ||
| error_msg = ("Cannot resubmit! Preprocessed data %d has already " | ||
| "been submitted to EBI.") | ||
| self.artifact = Artifact(artifact_id) | ||
| if not self.artifact.can_be_submitted_to_ebi: | ||
| error_msg = ("Artifact %d cannot be submitted to EBI" | ||
| % self.artifact.id) | ||
| LogEntry.create('Runtime', error_msg) | ||
| raise EBISubmissionError(error_msg) | ||
|
|
||
| self.study = self.artifact.study | ||
| self.sample_template = self.study.sample_template | ||
| prep_templates = self.artifact.prep_templates | ||
| if len(prep_templates) > 1: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After discussing offline with @josenavas we agreed that this is a redundant verification as can_be_submitted_to_ebi is set to False for those cases where prep_template>1 during creation. |
||
| error_msg = ("Cannot submit Artifact %d to EBI - it has more than" | ||
| " one prep template: %s" | ||
| % (self.artifact.id, | ||
| ', '.join([str(pt.id) for pt in prep_templates]))) | ||
| LogEntry.create('Runtime', error_msg) | ||
| raise EBISubmissionError(error_msg) | ||
| self.prep_template = prep_templates[0] | ||
|
|
||
| if self.artifact.is_submitted_to_ebi and action != 'MODIFY': | ||
| error_msg = ("Cannot resubmit! Artifact %d has already " | ||
| "been submitted to EBI." % artifact_id) | ||
| LogEntry.create('Runtime', error_msg) | ||
| raise EBISubmissionError(error_msg) | ||
|
|
||
|
|
@@ -123,7 +137,7 @@ def __init__(self, preprocessed_data_id, action): | |
| LogEntry.create('Runtime', error_msg) | ||
| raise EBISubmissionError(error_msg) | ||
|
|
||
| self.preprocessed_data_id = preprocessed_data_id | ||
| self.artifact_id = artifact_id | ||
| self.study_title = self.study.title | ||
| self.study_abstract = self.study.info['study_abstract'] | ||
|
|
||
|
|
@@ -141,7 +155,7 @@ def __init__(self, preprocessed_data_id, action): | |
| "one of the user-defined terms in the ENA " | ||
| "ontology." % it) | ||
| _, base_fp = get_mountpoint("preprocessed_data")[0] | ||
| self.ebi_dir = '%d_ebi_submission' % preprocessed_data_id | ||
| self.ebi_dir = '%d_ebi_submission' % artifact_id | ||
| self.full_ebi_dir = join(base_fp, self.ebi_dir) | ||
| self.ascp_reply = join(self.full_ebi_dir, 'ascp_reply.txt') | ||
| self.curl_reply = join(self.full_ebi_dir, 'curl_reply.xml') | ||
|
|
@@ -208,8 +222,8 @@ def __init__(self, preprocessed_data_id, action): | |
| "model: %s" % (', '.join(nvim))) | ||
| if error_msgs: | ||
| error_msgs = ("Errors found during EBI submission for study #%d, " | ||
| "preprocessed data #%d and prep template #%d:\n%s" | ||
| % (self.study.id, preprocessed_data_id, | ||
| "artifact #%d and prep template #%d:\n%s" | ||
| % (self.study.id, artifact_id, | ||
| self.prep_template.id, '\n'.join(error_msgs))) | ||
| LogEntry.create('Runtime', error_msgs) | ||
| raise EBISubmissionError(error_msgs) | ||
|
|
@@ -224,21 +238,21 @@ def __init__(self, preprocessed_data_id, action): | |
| self.prep_template.ebi_experiment_accessions | ||
|
|
||
| def _get_study_alias(self): | ||
| """Format alias using ``self.preprocessed_data_id``""" | ||
| """Format alias using ``self.study_id``""" | ||
| study_alias_format = '%s_sid_%s' | ||
| return study_alias_format % ( | ||
| qiita_config.ebi_organization_prefix, | ||
| escape(clean_whitespace(str(self.study.id)))) | ||
|
|
||
| def _get_sample_alias(self, sample_name): | ||
| """Format alias using ``self.preprocessed_data_id``, `sample_name`""" | ||
| """Format alias using ``self.study_id``, `sample_name`""" | ||
| alias = "%s:%s" % (self._get_study_alias(), | ||
| escape(clean_whitespace(str(sample_name)))) | ||
| self._sample_aliases[alias] = sample_name | ||
| return alias | ||
|
|
||
| def _get_experiment_alias(self, sample_name): | ||
| """Format alias using ``self.preprocessed_data_id``, and `sample_name` | ||
| """Format alias using ``self.prep_template.id``, and `sample_name` | ||
|
|
||
| Currently, this is identical to _get_sample_alias above, since we are | ||
| only going to allow submission of one prep for each sample | ||
|
|
@@ -252,19 +266,19 @@ def _get_experiment_alias(self, sample_name): | |
| return alias | ||
|
|
||
| def _get_submission_alias(self): | ||
| """Format alias using ``self.preprocessed_data_id``""" | ||
| safe_preprocessed_data_id = escape( | ||
| clean_whitespace(str(self.preprocessed_data_id))) | ||
| """Format alias using ``self.artifact_id``""" | ||
| safe_artifact_id = escape( | ||
| clean_whitespace(str(self.artifact_id))) | ||
| submission_alias_format = '%s_submission_%s' | ||
| return submission_alias_format % (qiita_config.ebi_organization_prefix, | ||
| safe_preprocessed_data_id) | ||
| safe_artifact_id) | ||
|
|
||
| def _get_run_alias(self, sample_name): | ||
| """Format alias using `sample_name` | ||
| """ | ||
| alias = '%s_ppdid_%s:%s' % ( | ||
| qiita_config.ebi_organization_prefix, | ||
| escape(clean_whitespace(str(self.preprocessed_data_id))), | ||
| escape(clean_whitespace(str(self.artifact_id))), | ||
| sample_name) | ||
| self._run_aliases[alias] = sample_name | ||
| return alias | ||
|
|
@@ -922,13 +936,13 @@ def generate_demultiplexed_fastq(self, rewrite_fastq=False, mtime=None): | |
| - The demux file couldn't be read | ||
| - All samples are removed | ||
| """ | ||
| ppd = self.preprocessed_data | ||
| ar = self.artifact | ||
|
|
||
| dir_not_exists = not isdir(self.full_ebi_dir) | ||
| if dir_not_exists or rewrite_fastq: | ||
| makedirs(self.full_ebi_dir) | ||
|
|
||
| demux = [path for _, path, ftype in ppd.get_filepaths() | ||
| demux = [path for _, path, ftype in ar.get_filepaths() | ||
| if ftype == 'preprocessed_demux'][0] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why only the first There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be only one. |
||
|
|
||
| demux_samples = set() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raises -> Raises ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done