Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e592ad6
Modifying the DB schema
josenavas Sep 22, 2015
7c598bb
Fixing study table
josenavas Sep 23, 2015
4ca0ba0
Fixing sample_id type in ebi table
josenavas Sep 23, 2015
78fd8c8
Finishing up patch
josenavas Sep 23, 2015
8e76820
Fixing populate_test_db.sql
josenavas Sep 23, 2015
1435695
Fixing status values'
josenavas Sep 23, 2015
5f8b486
Fixing data tests
josenavas Sep 24, 2015
b79ed89
Fix test_get_info
josenavas Sep 25, 2015
7175a80
Fixing study tests
josenavas Sep 25, 2015
af75f0d
Adding EBI study accession and EBI submission status setters to the s…
josenavas Sep 25, 2015
7be4199
Fixing command tests and interface
josenavas Sep 25, 2015
d80944c
Fixing sample template tests
josenavas Sep 25, 2015
a8b0487
Fixing the prep template tests
josenavas Sep 25, 2015
b5509d3
Merge branch 'ebi-improvements' of https://github.com/biocore/qiita i…
josenavas Oct 1, 2015
f4405ba
Fixing bug in the DB layout
josenavas Oct 2, 2015
10921ff
Adding EBI information for the preprocessed data
josenavas Oct 2, 2015
909ed24
Adding ebi status to the preprocessed_data
josenavas Oct 2, 2015
e954fa2
Adding function to retrieve the EBI submission numbers
josenavas Oct 2, 2015
49bd40a
All ebi tests passing again
josenavas Oct 2, 2015
32771a0
Fix indentation
josenavas Oct 2, 2015
3c9e52b
Fixing aliases
josenavas Oct 2, 2015
0ae1073
Stubbing test for EBI reply parser
josenavas Oct 2, 2015
32aa0cb
Adding test for a success EBI submission parser
josenavas Oct 2, 2015
3e44782
Adding biosample accession number parser
josenavas Oct 2, 2015
9e5ffac
Adapting the EBI command
josenavas Oct 2, 2015
f2598d7
Adding biosample accession to the db and update the populate test db
josenavas Oct 2, 2015
a096e8c
Adding ebi accession properties to the templates and tests
josenavas Oct 2, 2015
604342f
Adding accession attributes setters and tests
josenavas Oct 3, 2015
5836e0b
Solving a bug and add a specific test
josenavas Oct 3, 2015
fd7ebd8
pep8ing
josenavas Oct 4, 2015
f707095
Solving merge conflicts
josenavas Oct 5, 2015
b8db07a
Addressing @antgonza's comments
josenavas Oct 5, 2015
8aba8d5
Doing the forgotten TODO
josenavas Oct 5, 2015
1699a8a
Differentiating the errors in the parsing
josenavas Oct 5, 2015
0116e55
Solving merge conflicts
josenavas Oct 5, 2015
bcda0de
Addressing @ElDeveloper comments
josenavas Oct 6, 2015
8bc5aff
Fixing doc
josenavas Oct 6, 2015
e8808e3
Pep8ing
josenavas Oct 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions qiita_db/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,42 +102,37 @@ def get_optional(name):


def load_preprocessed_data_from_cmd(study_id, params_table, filedir,
filepathtype, params_id,
submitted_to_insdc_status,
filepath_type, params_id,
prep_template_id, data_type):
r"""Adds preprocessed data to the database

Parameters
----------
study_id : int
The study id to which the preprocessed data belongs
params_table : str
The name of the table which contains the parameters of the
preprocessing
filedir : str
Directory path of the preprocessed data
filepathtype: str
filepath_type: str
The filepath_type of the preprecessed data
params_table_name : str
The name of the table which contains the parameters of the
preprocessing
params_id : int
The id of parameters int the params_table
submitted_to_insdc_status : str, {'not submitted', 'submitting', \
'success', 'failed'}
INSDC submission status
prep_template_id : int
Prep template id associated with data
data_type : str
The data type of the template
"""
with TRN:
fp_types_dict = get_filepath_types()
fp_type = fp_types_dict[filepathtype]
fp_type = fp_types_dict[filepath_type]
filepaths = [(join(filedir, fp), fp_type) for fp in listdir(filedir)]
pt = (None if prep_template_id is None
else PrepTemplate(prep_template_id))
return PreprocessedData.create(
Study(study_id), params_table, params_id, filepaths,
prep_template=pt,
submitted_to_insdc_status=submitted_to_insdc_status,
data_type=data_type)


Expand Down
213 changes: 68 additions & 145 deletions qiita_db/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,7 @@ class PreprocessedData(BaseData):

@classmethod
def create(cls, study, preprocessed_params_table, preprocessed_params_id,
filepaths, prep_template=None, data_type=None,
submitted_to_insdc_status='not submitted',
ebi_submission_accession=None,
ebi_study_accession=None):
filepaths, prep_template=None, data_type=None):
r"""Creates a new object with a new id on the storage system

Parameters
Expand All @@ -677,17 +674,11 @@ def create(cls, study, preprocessed_params_table, preprocessed_params_id,
filepaths : iterable of tuples (str, int)
The list of paths to the preprocessed files and its filepath type
identifier
submitted_to_insdc_status : str, {'not submitted', 'submitting', \
'success', 'failed'} optional
Submission status of the raw data files
prep_template : PrepTemplate, optional
The PrepTemplate object used to generate this preprocessed data
data_type : str, optional
The data_type of the preprocessed_data
ebi_submission_accession : str, optional
The ebi_submission_accession of the preprocessed_data
ebi_study_accession : str, optional
The ebi_study_accession of the preprocessed_data

Raises
------
Expand Down Expand Up @@ -724,13 +715,11 @@ def create(cls, study, preprocessed_params_table, preprocessed_params_id,
# and get the preprocessed data id back
sql = """INSERT INTO qiita.{0} (
preprocessed_params_table, preprocessed_params_id,
submitted_to_insdc_status, data_type_id,
ebi_submission_accession, ebi_study_accession)
VALUES (%s, %s, %s, %s, %s, %s)
data_type_id)
VALUES (%s, %s, %s)
RETURNING preprocessed_data_id""".format(cls._table)
TRN.add(sql, [preprocessed_params_table, preprocessed_params_id,
submitted_to_insdc_status, data_type,
ebi_submission_accession, ebi_study_accession])
data_type])
ppd_id = TRN.execute_fetchlast()
ppd = cls(ppd_id)

Expand Down Expand Up @@ -783,16 +772,15 @@ def delete(cls, ppd_id):
if ppd.status != 'sandbox':
raise QiitaDBStatusError(
"Illegal operation on non sandboxed preprocessed data")
elif ppd.is_submitted_to_ebi:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell not all these cases are tested, right? Just want to confirm ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case already existed before (see line 791 in the old code) and it was already tested (they're the lines that I have commented out in the test - so it is tested here: https://github.com/biocore/qiita/pull/1481/files#diff-e54a9d2a89750a099959730f348c06e1R432)

raise QiitaDBStatusError(
"Illegal operation. This preprocessed data has been "
"added to EBI.")
elif ppd.submitted_to_vamps_status() not in \
valid_submission_states:
raise QiitaDBStatusError(
"Illegal operation. This preprocessed data has or is "
"being added to VAMPS.")
elif ppd.submitted_to_insdc_status() not in \
valid_submission_states:
raise QiitaDBStatusError(
"Illegal operation. This preprocessed data has or is "
"being added to EBI.")

sql = """SELECT processed_data_id
FROM qiita.preprocessed_processed_data
Expand Down Expand Up @@ -846,7 +834,12 @@ def prep_template(self):
WHERE preprocessed_data_id=%s""".format(
self._template_preprocessed_table)
TRN.add(sql, [self._id])
return TRN.execute_fetchlast()
result = TRN.execute_fetchindex()
# If there is no prep template with the preprocessed data
# result will be an empty list
if result:
result = result[0][0]
return result

@property
def study(self):
Expand All @@ -864,70 +857,6 @@ def study(self):
TRN.add(sql, [self._id])
return TRN.execute_fetchlast()

@property
def ebi_submission_accession(self):
r"""The ebi submission accession of this preprocessed data

Returns
-------
str
The ebi submission accession of this preprocessed data
"""
with TRN:
sql = """SELECT ebi_submission_accession
FROM qiita.{0}
WHERE preprocessed_data_id=%s""".format(self._table)
TRN.add(sql, [self.id])
return TRN.execute_fetchlast()

@property
def ebi_study_accession(self):
r"""The ebi study accession of this preprocessed data

Returns
-------
str
The ebi study accession of this preprocessed data
"""
with TRN:
sql = """SELECT ebi_study_accession
FROM qiita.{0}
WHERE preprocessed_data_id=%s""".format(self._table)
TRN.add(sql, [self.id])
return TRN.execute_fetchlast()

@ebi_submission_accession.setter
def ebi_submission_accession(self, new_ebi_submission_accession):
""" Sets the ebi_submission_accession for the preprocessed_data

Parameters
----------
new_ebi_submission_accession: str
The new ebi submission accession
"""
with TRN:
sql = """UPDATE qiita.{0}
SET ebi_submission_accession = %s
WHERE preprocessed_data_id = %s""".format(self._table)
TRN.add(sql, [new_ebi_submission_accession, self._id])
TRN.execute()

@ebi_study_accession.setter
def ebi_study_accession(self, new_ebi_study_accession):
""" Sets the ebi_study_accession for the preprocessed_data

Parameters
----------
new_ebi_study_accession: str
The new ebi study accession
"""
with TRN:
sql = """UPDATE qiita.{0}
SET ebi_study_accession = %s
WHERE preprocessed_data_id = %s""".format(self._table)
TRN.add(sql, [new_ebi_study_accession, self._id])
TRN.execute()

def data_type(self, ret_id=False):
"""Returns the data_type or data_type_id

Expand All @@ -951,66 +880,6 @@ def data_type(self, ret_id=False):
TRN.add(sql, [self._id])
return TRN.execute_fetchlast()

def submitted_to_insdc_status(self):
r"""Tells if the raw data has been submitted to INSDC

Returns
-------
str
One of {'not submitted', 'submitting', 'success', 'failed'}
"""
with TRN:
sql = """SELECT submitted_to_insdc_status
FROM qiita.{0}
WHERE preprocessed_data_id=%s""".format(self._table)
TRN.add(sql, [self.id])
return TRN.execute_fetchlast()

def update_insdc_status(self, state, study_acc=None, submission_acc=None):
r"""Update the INSDC submission status

Parameters
----------
state : str, {'not submitted', 'submitting', 'success', 'failed'}
The current status of submission
study_acc : str, optional
The study accession from EBI. This is not optional if ``state`` is
``success``.
submission_acc : str, optional
The submission accession from EBI. This is not optional if
``state`` is ``success``.

Raises
------
ValueError
If the state is not known.
ValueError
If ``state`` is ``success`` and either ``study_acc`` or
``submission_acc`` are ``None``.
"""
with TRN:
if state not in ('not submitted', 'submitting', 'success',
'failed'):
raise ValueError("Unknown state: %s" % state)

if state == 'success':
if study_acc is None or submission_acc is None:
raise ValueError("study_acc or submission_acc is None!")

sql = """UPDATE qiita.{0}
SET (submitted_to_insdc_status,
ebi_study_accession,
ebi_submission_accession) = (%s, %s, %s)
WHERE preprocessed_data_id=%s""".format(self._table)
TRN.add(sql, [state, study_acc, submission_acc, self.id])
else:
sql = """UPDATE qiita.{0}
SET submitted_to_insdc_status = %s
WHERE preprocessed_data_id=%s""".format(self._table)
TRN.add(sql, [state, self.id])

TRN.execute()

def submitted_to_vamps_status(self):
r"""Tells if the raw data has been submitted to VAMPS

Expand Down Expand Up @@ -1116,6 +985,60 @@ def status(self):

return infer_status(TRN.execute_fetchindex())

@property
def preprocessing_info(self):
"""The preprocessing information

Returns
-------
tuple(str, int)
The preprocessing parameters table and
the preprocessing parameters id
"""
with TRN:
sql = """SELECT preprocessed_params_table, preprocessed_params_id
FROM qiita.{0}
WHERE preprocessed_data_id = %s""".format(self._table)
TRN.add(sql, [self.id])
result = TRN.execute_fetchflatten()
return tuple(result)

@property
def is_submitted_to_ebi(self):
"""Gets if the preprocessed data has been submitted to EBI or not

Returns
-------
bool
True if the preprocessed data has been submitted to EBI,
false otherwise.
"""
with TRN:
sql = """SELECT EXISTS(SELECT *
FROM qiita.ebi_run_accession
WHERE preprocessed_data_id = %s)"""
TRN.add(sql, [self.id])
is_submitted = TRN.execute_fetchlast()
return is_submitted

@property
def ebi_run_accessions(self):
"""The EBI run accessions attached to the preprocessed data

Returns
-------
list of str
The EBI run accessions
"""
with TRN:
sql = """SELECT ebi_run_accession
FROM qiita.ebi_run_accession
WHERE preprocessed_data_id = %s
ORDER BY ebi_run_accession"""
TRN.add(sql, [self.id])
accessions = TRN.execute_fetchflatten()
return accessions


class ProcessedData(BaseData):
r"""Object for dealing with processed data
Expand Down
Loading