Skip to content

Merge relax-md-req into master #1122

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

Merged
merged 98 commits into from
Apr 29, 2015
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
94bf806
Modifying the database
josenavas Apr 17, 2015
b3aa78d
Fixing populate_test_db.sql
josenavas Apr 17, 2015
fd13c59
Renaming tables as the old names do not make sense now
josenavas Apr 17, 2015
cf85cfd
Merge branch 'fix-extend' into fix-metadata-creation
josenavas Apr 17, 2015
b677ba0
Fixing sample obj tests
josenavas Apr 17, 2015
7896e22
Correctly merging the column values in the sample template
josenavas Apr 17, 2015
86f6474
Merge branch 'relax-db' into fix-sample-obj
josenavas Apr 17, 2015
cc3b359
Fixing latitude/longitude types on populate
josenavas Apr 17, 2015
de3659e
Merge branch 'relax-db' into fix-sample-obj
josenavas Apr 17, 2015
6472cf3
Fixing ReadOnly tests for PrepSample
josenavas Apr 17, 2015
4e87d20
Fixing ReadWrite tests for PrepSample
josenavas Apr 17, 2015
8ec3b27
Adding the column_restriction module
josenavas Apr 17, 2015
a13a7b8
Fixing SampleTemplate ReadOnly tests
josenavas Apr 17, 2015
c64ab6c
Fixng all SampleTemplate tests
josenavas Apr 17, 2015
5f23a55
Removing column restriction as it can be added in constants
josenavas Apr 17, 2015
ef284f3
Fixing TestPrepTemplateReadOnly
josenavas Apr 17, 2015
694f4ab
Fixing all prep template object tests
josenavas Apr 17, 2015
3728f63
All tests under metadata_template passing
josenavas Apr 17, 2015
b145fca
Fixing flake8
josenavas Apr 17, 2015
85a32dc
Merge branch 'master' of https://github.com/biocore/qiita into relax-db
josenavas Apr 21, 2015
4ea0312
Merge branch 'master' of https://github.com/biocore/qiita into fix-sa…
josenavas Apr 21, 2015
2990e23
Merge remote-tracking branch 'upstream/cart-branch' into relax-md-req
josenavas Apr 22, 2015
af248cf
Preparing files for the merge
josenavas Apr 22, 2015
b2721eb
Solving the hell of the merge conflict
josenavas Apr 22, 2015
771c27d
Merge branch 'relax-db' into fix-sample-obj
josenavas Apr 22, 2015
78f763a
Fix merge conflicts
josenavas Apr 23, 2015
fbdf463
Fixing test_setup.py
josenavas Apr 23, 2015
ff4aae6
Fixing util.py
josenavas Apr 23, 2015
f7e62bd
Fixing data.py
josenavas Apr 23, 2015
10d9a0e
Fixing search.py
josenavas Apr 23, 2015
299c52f
Chaning queue name
josenavas Apr 23, 2015
18efa9c
Adding the missing prep template to the DB
josenavas Apr 23, 2015
e845794
Fixing type on populate_test_db.sql
josenavas Apr 23, 2015
a8b7d98
Doing all the patch in SQL
josenavas Apr 24, 2015
8772f32
Merge branch 'relax-db' into fix-sample-obj
josenavas Apr 24, 2015
013d126
Merge branch 'fix-sample-obj' into fix-metadata-obj
josenavas Apr 24, 2015
e65a41d
Merge branch 'fix-metadata-obj' into fix-qiita-db-tests
josenavas Apr 24, 2015
c6147b0
Merge branch 'fix-qiita-db-tests' into fix-analysis-tests
josenavas Apr 24, 2015
0ddb98a
Atatching the new prep template file to the prep template
josenavas Apr 24, 2015
5d7a752
fixing test_setup.py
josenavas Apr 24, 2015
e9fab3e
Fixing test_reference.py by removing magic numbers
josenavas Apr 24, 2015
ff305f9
Fixing test_job.py by removing magic numbers
josenavas Apr 24, 2015
01ec8bc
Fixing test_prep_template.py by removing magic numbers
josenavas Apr 24, 2015
69cfcc1
Fixing test_meta_util.py
josenavas Apr 24, 2015
c5f3107
Adding the qiime mapping file
josenavas Apr 24, 2015
4ef8b42
Fixing all the analysis tests. Fixes partially #247. Fixes #465
josenavas Apr 24, 2015
847485b
Fixing tests due to the addition of the mapping file
josenavas Apr 25, 2015
5ee643f
addressing @squirrelo's comments
josenavas Apr 25, 2015
3d4cd42
Removing patch as per @squirrelo's suggestion
josenavas Apr 25, 2015
e75c372
Fixing qiita ware test util
josenavas Apr 25, 2015
fa4a68b
Fixing qiita ware tests
josenavas Apr 25, 2015
b43c3cc
Flake8
josenavas Apr 25, 2015
69395bf
Merge branch 'relax-db' into fix-sample-obj
josenavas Apr 25, 2015
ba49dc5
Reading python patch as now it has the needed functionality
josenavas Apr 25, 2015
3d4d7dd
Merge branch 'fix-metadata-obj' into fix-qiita-db-tests
josenavas Apr 25, 2015
e7cefb0
Merge branch 'fix-qiita-db-tests' into fix-analysis-tests
josenavas Apr 25, 2015
658a5b5
Merge branch 'fix-analysis-tests' into fix-qiita-ware-tests
josenavas Apr 25, 2015
6177e4e
Merge pull request #1073 from josenavas/relax-db
antgonza Apr 27, 2015
0439de9
Merge branch 'relax-md-req' of https://github.com/biocore/qiita into …
josenavas Apr 27, 2015
157b60a
Adding qiime-map property to the prep template
josenavas Apr 27, 2015
2c5027e
Merge pull request #1074 from josenavas/fix-sample-obj
adamrp Apr 27, 2015
57ed605
Merge branch 'master' of https://github.com/biocore/qiita into fix-me…
josenavas Apr 27, 2015
2a29012
Merge branch 'relax-md-req' of https://github.com/biocore/qiita into …
josenavas Apr 27, 2015
b2c4f70
Merge branch 'master' of https://github.com/biocore/qiita into relax-…
josenavas Apr 27, 2015
0cfab56
Merge branch 'relax-md-req' of https://github.com/biocore/qiita into …
josenavas Apr 27, 2015
62f0d3e
Merge branch 'relax-md-req' of https://github.com/biocore/qiita into …
josenavas Apr 27, 2015
f81caa9
Fixing call to clean validate template
josenavas Apr 27, 2015
134678d
Removing all warnings from tests
josenavas Apr 27, 2015
6aa5335
Fixing create qiime mapping file add_filepath call
josenavas Apr 27, 2015
1cc26e9
Addressing comments
josenavas Apr 27, 2015
2d3df08
Reducing the rename_cols dict
josenavas Apr 28, 2015
79256ff
Merge pull request #1075 from josenavas/fix-metadata-obj
antgonza Apr 28, 2015
0829f95
Merge branch 'relax-md-req' of https://github.com/biocore/qiita into …
josenavas Apr 28, 2015
d777469
Addressing comments from @ElDeveloper and @squirrelo
josenavas Apr 28, 2015
b26a867
Merge pull request #1099 from josenavas/fix-qiita-db-tests
squirrelo Apr 28, 2015
e76a10c
Merge branch 'relax-md-req' of https://github.com/biocore/qiita into …
josenavas Apr 28, 2015
d1bee5e
Addressing @ElDeveloper comments
josenavas Apr 28, 2015
8be914f
Removing inference - good catch @ElDeveloper\!
josenavas Apr 28, 2015
b604ae1
Merge pull request #1106 from josenavas/fix-analysis-tests
ElDeveloper Apr 28, 2015
a663d33
Merge branch 'relax-md-req' of https://github.com/biocore/qiita into …
josenavas Apr 28, 2015
b19b60c
Merge branch 'relax-md-req' of https://github.com/biocore/qiita into …
josenavas Apr 28, 2015
e7363a3
Merge branch 'add-qiime-map-func' into fix-qiita-ware-tests
josenavas Apr 28, 2015
d464237
Fixing bug in add filepath
josenavas Apr 28, 2015
84beb81
Fixing _get_qiime_minimal_mapping
josenavas Apr 28, 2015
c30dd8c
Fixing qiime map parsing
josenavas Apr 28, 2015
e5ae3e4
Removing warnings from tests:
josenavas Apr 28, 2015
14b0c49
Addressing comments
josenavas Apr 29, 2015
0c9a47a
Adding test with reverse linker primer
josenavas Apr 29, 2015
6c83ba4
Fixing WTF failures
josenavas Apr 29, 2015
7390538
Merge pull request #1107 from josenavas/fix-qiita-ware-tests
ElDeveloper Apr 29, 2015
a546233
Reverting the comment from @squirrelo on search for JOIN...ON -> USIN…
josenavas Apr 29, 2015
402003a
Removing the ambiguity
josenavas Apr 29, 2015
d87890b
Removing join as now all the columns are in the dynamic table...
josenavas Apr 29, 2015
f73887f
Execute the tests even if you change the format... there might be a s…
josenavas Apr 29, 2015
4830b24
Merge branch 'master' of https://github.com/biocore/qiita into join-u…
josenavas Apr 29, 2015
7a29adc
Fixing bug in _build_mapping_file and create a test for it
josenavas Apr 29, 2015
fa2392c
Adding tests for test_build_biom_tables
josenavas Apr 29, 2015
1a163fb
Merge pull request #1126 from josenavas/join-using-instead-on-db-issues
antgonza Apr 29, 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
13 changes: 11 additions & 2 deletions qiita_db/metadata_template/base_metadata_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ def _clean_validate_template(cls, md_template, study_id, restriction_dict):
-------
md_template : DataFrame
Cleaned copy of the input md_template

Raises
------
QiitaDBColumnError
If the sample names in md_template contains invalid names
QiitaDBWarning
If there are missing columns required for some functionality
"""
cls._check_subclass()
invalid_ids = get_invalid_sample_names(md_template.index)
Expand Down Expand Up @@ -988,7 +995,8 @@ def to_file(self, fp, samples=None):
if samples is not None:
df = df.loc[samples]

# Apply some sorting to the dataframe
# Sorting the dataframe so multiple serializations of the metadata
# template are consistent.
df.sort_index(axis=0, inplace=True)
df.sort_index(axis=1, inplace=True)

Expand Down Expand Up @@ -1021,7 +1029,7 @@ def to_dataframe(self):

return df

def add_filepath(self, filepath, conn_handler=None):
def add_filepath(self, filepath, conn_handler=None, fp_id=None):
r"""Populates the DB tables for storing the filepath and connects the
`self` objects with this filepath"""
# Check that this function has been called from a subclass
Expand All @@ -1030,6 +1038,7 @@ def add_filepath(self, filepath, conn_handler=None):
# Check if the connection handler has been provided. Create a new
# one if not.
conn_handler = conn_handler if conn_handler else SQLConnectionHandler()
fp_id = self._fp_id if fp_id is None else fp_id

try:
fpp_id = insert_filepaths([(filepath, self._fp_id)], None,
Expand Down
14 changes: 10 additions & 4 deletions qiita_db/metadata_template/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

# A dict containing the restrictions that apply to the sample templates
SAMPLE_TEMPLATE_COLUMNS = {
# The following columns are required by EBI for submission
'EBI': Restriction(columns={'collection_timestamp': 'timestamp',
'physical_specimen_location': 'varchar'},
error_msg="EBI submission disabled"),
'Qiita_main': Restriction(columns={'sample_type': 'varchar',
# The following columns are required for the official main QIITA site
'qiita_main': Restriction(columns={'sample_type': 'varchar',
'description': 'varchar',
'physical_specimen_remaining': 'bool',
'dna_extracted': 'bool',
Expand All @@ -26,8 +28,9 @@
error_msg="Processed data approval disabled")
}

# A dict containing the restrictions that apply to the sample templates
# A dict containing the restrictions that apply to the prep templates
PREP_TEMPLATE_COLUMNS = {
# The following columns are required by EBI for submission
'EBI': Restriction(
columns={'primer': 'varchar',
'center_name': 'varchar',
Expand All @@ -43,12 +46,15 @@
TARGET_GENE_DATA_TYPES = ['16S', '18S', 'ITS']

PREP_TEMPLATE_COLUMNS_TARGET_GENE = {
'Demultiplex': Restriction(
# The following columns are required by QIIME to execute split libraries
'demultiplex': Restriction(
columns={'barcode': 'varchar',
'primer': 'varchar'},
error_msg="Demultiplexing disabled. You will not be able to "
"preprocess your raw data"),
'Demultiplex_multiple': Restriction(
# The following columns are required by Qiita to know how to execute split
# libraries using QIIME over a study with multiple illumina lanes
'demultiplex_multiple': Restriction(
columns={'barcode': 'varchar',
'primer': 'varchar',
'run_prefix': 'varchar'},
Expand Down
43 changes: 31 additions & 12 deletions qiita_db/metadata_template/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
from os.path import join
from time import strftime
from copy import deepcopy
import warnings

import pandas as pd

from qiita_core.exceptions import IncompetentQiitaDeveloperError
from qiita_db.exceptions import (QiitaDBColumnError, QiitaDBUnknownIDError,
QiitaDBError, QiitaDBExecutionError)
QiitaDBError, QiitaDBExecutionError,
QiitaDBWarning)
from qiita_db.sql_connection import SQLConnectionHandler
from qiita_db.ontology import Ontology
from qiita_db.util import (convert_to_id,
Expand Down Expand Up @@ -127,7 +129,7 @@ def create(cls, md_template, raw_data, study, data_type,
pt_cols.update(PREP_TEMPLATE_COLUMNS_TARGET_GENE)

md_template = cls._clean_validate_template(md_template, study.id,
PREP_TEMPLATE_COLUMNS)
pt_cols)

# Insert the metadata template
# We need the prep_id for multiple calls below, which currently is not
Expand Down Expand Up @@ -402,12 +404,20 @@ def create_qiime_mapping_file(self):
------
ValueError
If the prep template is not a subset of the sample template
QiitaDBWarning
If the QIIME-required columns are not present in the template

Notes
-----
We cannot ensure that the QIIME-required columns are present in the
metadata map. However, we have to generate a QIIME-compliant mapping
file. Since the user may need a QIIME mapping file, but not these
QIIME-required columns, we are going to create them and
populate them with the value XXQIITAXX.
"""
rename_cols = {
'barcode': 'BarcodeSequence',
'barcodesequence': 'BarcodeSequence',
'primer': 'LinkerPrimerSequence',
'linkerprimersequence': 'LinkerPrimerSequence',
'description': 'Description',
}

Expand All @@ -434,23 +444,30 @@ def create_qiime_mapping_file(self):
if not pt_sample_names.issubset(st_sample_names):
raise ValueError(
"Prep template is not a sub set of the sample template, files"
"%s - samples: %s" % (sample_template_fp,
str(pt_sample_names-st_sample_names)))
"%s - samples: %s"
% (sample_template_fp,
', '.join(pt_sample_names-st_sample_names)))

mapping = pt.join(st, lsuffix="_prep")
mapping.rename(columns=rename_cols, inplace=True)

# We cannot ensure that the QIIME-required columns are present in the
# metadata map. However, we have to generate a QIIME-compliant mapping
# file. Since the user may need a QIIME mapping file, but not these
# QIIME-required columns, we are going to create them here and
# populate them with the value XXQIITAXX
# Pre-populate the QIIME-required columns with the value XXQIITAXX
index = mapping.index
placeholder = ['XXQIITAXX'] * len(index)
missing = []
for val in viewvalues(rename_cols):
if val not in mapping:
missing.append(val)
mapping[val] = pd.Series(placeholder, index=index)

if missing:
warnings.warn(
"Some columns required to generate a QIIME-compliant mapping "
"file are not present in the template. A placeholder value "
"(XXQIITAXX) has been used to populate these columns. Missing "
"columns: %s" % ', '.join(missing),
QiitaDBWarning)

# Gets the orginal mapping columns and readjust the order to comply
# with QIIME requirements
cols = mapping.columns.values.tolist()
Expand All @@ -472,7 +489,9 @@ def create_qiime_mapping_file(self):
sep='\t')

# adding the fp to the object
self.add_filepath(filepath)
self.add_filepath(
filepath, conn_handler=conn_handler,
fp_id=convert_to_id("qiime_map", "filepath_type"))

return filepath

Expand Down
Loading