Skip to content

Commit

Permalink
some cleanup + sample_info PrepTemplateDataHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
antgonza committed Dec 12, 2023
1 parent baf66af commit e8997e0
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
9 changes: 8 additions & 1 deletion qiita_db/handlers/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,16 @@ def get(self, prep_id):
dict
The contents of the prep information keyed by sample id
"""
sample_info = self.get_argument('sample_information', False)

with qdb.sql_connection.TRN:
pt = _get_prep_template(prep_id)
response = {'data': pt.to_dataframe().to_dict(orient='index')}
if not sample_info:
response = {'data': pt.to_dataframe().to_dict(orient='index')}
else:
ST = qdb.metadata_template.sample_template.SampleTemplate
response = {'data': ST(pt.study_id).to_dataframe(
samples=list(pt)).to_dict(orient='index')}

self.write(response)

Expand Down
35 changes: 35 additions & 0 deletions qiita_db/handlers/tests/test_prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,41 @@ def test_get(self):
'qiita_prep_id': '1'}
self.assertEqual(obs, exp)

def test_get_sample_information(self):
obs = self.get(
'/qiita_db/prep_template/1/data/?sample_information=true',
headers=self.header)
self.assertEqual(obs.code, 200)

obs = loads(obs.body)
self.assertCountEqual(obs.keys(), ['data'])

# let's just check that the samples and the keys from the first element
# match - this assures us that is the sample_info, the rest is
# basically the same as the regular prep_info
obs = obs['data']
exp = ['1.SKB2.640194', '1.SKM4.640180', '1.SKB3.640195',
'1.SKB6.640176', '1.SKD6.640190', '1.SKM6.640187',
'1.SKD9.640182', '1.SKM8.640201', '1.SKM2.640199',
'1.SKD2.640178', '1.SKB7.640196', '1.SKD4.640185',
'1.SKB8.640193', '1.SKM3.640197', '1.SKD5.640186',
'1.SKB1.640202', '1.SKM1.640183', '1.SKD1.640179',
'1.SKD3.640198', '1.SKB5.640181', '1.SKB4.640189',
'1.SKB9.640200', '1.SKM9.640192', '1.SKD8.640184',
'1.SKM5.640177', '1.SKM7.640188', '1.SKD7.640191']
self.assertCountEqual(list(obs.keys()), exp)
exp = ['ph', 'temp', 'depth', 'country', 'texture', 'altitude',
'latitude', 'taxon_id', 'elevation', 'env_biome', 'longitude',
'tot_nitro', 'host_taxid', 'common_name', 'description',
'env_feature', 'env_package', 'sample_type', 'tot_org_carb',
'dna_extracted', 'samp_salinity', 'anonymized_name',
'host_subject_id', 'scientific_name', 'assigned_from_geo',
'season_environment', 'water_content_soil',
'collection_timestamp', 'description_duplicate',
'physical_specimen_location', 'physical_specimen_remaining',
'qiita_study_id']
self.assertCountEqual(obs['1.SKB2.640194'].keys(), exp)


class PrepTemplateAPItestHandlerTests(OauthTestingBase):
def test_post(self):
Expand Down
2 changes: 1 addition & 1 deletion qiita_db/metadata_template/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def columns_restrictions(self):
Returns
-------
dict
The dict of restictions based on the data_type
The dict of restrictions based on the data_type
"""
pt_cols = deepcopy(PREP_TEMPLATE_COLUMNS)
if self.data_type() in TARGET_GENE_DATA_TYPES:
Expand Down
2 changes: 1 addition & 1 deletion qiita_db/metadata_template/sample_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def columns_restrictions(self):
Returns
-------
dict
The dict of restictions
The dict of restrictions
"""
return qdb.metadata_template.constants.SAMPLE_TEMPLATE_COLUMNS

Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/workflows.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h5>Hover on the spheres to get more information</h5>
<h4>
Application: {{', '.join(w['data_types'])}} ->
{% if w['parameters_sample'] or w['parameters_prep'] %}
parameter restictions:
parameter restrictions:
<br/>
<ul>
{% if w['parameters_sample'] %}
Expand Down
2 changes: 1 addition & 1 deletion qiita_ware/ebi.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __init__(self, artifact_id, action):
st_restrictions = [self.sample_template.columns_restrictions['EBI']]
pt_restrictions = [self.prep_template.columns_restrictions['EBI']]
if self.artifact.data_type in TARGET_GENE_DATA_TYPES:
# adding restictions on primer and barcode as these are
# adding restrictions on primer and barcode as these are
# conditionally requiered for target gene
pt_restrictions.append(
PREP_TEMPLATE_COLUMNS_TARGET_GENE['demultiplex'])
Expand Down

0 comments on commit e8997e0

Please sign in to comment.