Skip to content

Commit 149120d

Browse files
anupriyatripathiElDeveloper
authored andcommitted
Tree fixes (Critical) (#99)
* deleting old test data * use solid branch lines only for MS/MS matches * set taxonomy = unclassified when empty set returned by classyfire * taxonomy fixes * unclassified taxonomy when classyfire returns an empty dict * add case where classyfire returns empty dict * remove print statement * check for NaNs in classification, there shouldnt be any * deconvolute if else condensed form for readability * remove redundant .keys() call for dict
1 parent a71d8c5 commit 149120d

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

q2_qemistree/_classyfire.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,18 @@ def get_classyfire_taxonomy(feature_data: pd.DataFrame) -> pd.DataFrame:
7878
response = requests.get(to_classyfire+str(inchikey)+'.json')
7979
if response.status_code == 200:
8080
response = response.json()
81-
classyfire_levels_sub = [level for level in classyfire_levels
82-
if level in response.keys()]
83-
if len(classyfire_levels_sub) == 0:
81+
sublevels = [level for level in classyfire_levels
82+
if level in response]
83+
if len(sublevels) == 0:
84+
classyfire[idx] = 'unclassified'
8485
continue
85-
taxonomy = [response[level]['name']
86-
if bool(response) and response[level] is not None
87-
else 'unclassified'
88-
for level in classyfire_levels_sub]
86+
taxonomy = []
87+
for level in classyfire_levels:
88+
if (response and level in sublevels and
89+
response[level] is not None):
90+
taxonomy.append(response[level]['name'])
91+
else:
92+
taxonomy.append('unclassified')
8993
classyfire[idx] = taxonomy
9094
elif response.status_code == 404:
9195
classyfire[idx] = 'unclassified'

q2_qemistree/_itol_metadata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def get_itol_visualization(classified_feature_data: str,
8181
if fdata.loc[idx, 'annotation_type'] == 'MS2':
8282
fh.write(idx + '\t' + 'clade\t' +
8383
color + '\tnormal\t6\n')
84-
if fdata.loc[idx, 'annotation_type'] == 'CSIFingerID':
84+
else:
8585
fh.write(idx + '\t' + 'clade\t' +
8686
color + '\tdashed\t4\n')
8787
if label_file_path:
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
label #featureID csi_smiles ms2_smiles table_number
2-
3638d9b9658b202f9c773e5e43206d32 3 1
3-
c8f6e296c0bacf58cfec06b333fd2015 7 CCCCCCCCCCCCCCCC(=O)OCC(COP(=O)([O-])OCC[N+](C)(C)C)O 1
4-
a500d26568f130313bdb70e3ae7d2ade 2 1
2+
featurehash1 3 1
3+
featurehash2 7 CCCCCCCCCCCCCCCC(=O)OCC(COP(=O)([O-])OCC[N+](C)(C)C)O 1
4+
featurehash3 2 1
5+
featurehash4 5 CC(=NC(=O)CC(=NC(=O)C)OOC(=O)C)O 1

q2_qemistree/tests/test_classyfire.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_malformed_smiles(self):
5454
def test_classyfire_output(self):
5555
classified = get_classyfire_taxonomy(self.smiles)
5656
classified_mols = classified[classified['kingdom'] != 'unclassified']
57-
self.assertTrue(len(classified_mols) == 1)
57+
self.assertTrue(pd.isna(classified_mols).shape, 0)
5858
self.assertTrue(classified_mols.loc[1,
5959
'kingdom'] == 'Organic compounds')
6060
self.assertTrue((self.levels.issubset(set(classified.columns))))

0 commit comments

Comments
 (0)