Skip to content

Commit

Permalink
Interesting eval approach
Browse files Browse the repository at this point in the history
Finally fixed!
  • Loading branch information
iquasere committed Nov 21, 2023
1 parent b3586cf commit 46fa183
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions upimapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,22 +508,22 @@ def select_columns(columns):
'Taxonomic lineage (SPECIES)', 'Taxonomic lineage (Ids)'])]
taxids_cols = [col for col in columns if (
'Taxonomic lineage IDs (' in col and col not in 'Taxonomic lineage IDs (SPECIES)')]
for col in ['Entry', 'Entry Name']:
for col in ['Entry Name', 'Entry']:
if col not in columns:
columns = [col] + columns
columns.insert(0, col)
new_cols = [col for col in columns if col not in tax_cols + taxids_cols + [
'Taxonomic lineage (SPECIES)', 'Taxonomic lineage IDs (SPECIES)']]
col_conversion = {'Organism': 'Taxonomic lineage (SPECIES)', 'Organism (ID)': 'Taxonomic lineage IDs (SPECIES)'}
for k, v in col_conversion.items():
if v in columns and k not in new_cols:
new_cols.append(k)
conditions = {
len(tax_cols) > 0 and 'Taxonomic lineage' not in new_cols: 'Taxonomic lineage',
len(taxids_cols) > 0 and 'Taxonomic lineage (Ids)' not in new_cols: 'Taxonomic lineage (Ids)',
'Taxonomic lineage (SPECIES)' in columns and 'Organism' not in new_cols: 'Organism',
'Taxonomic lineage IDs (SPECIES)' in columns and 'Organism (ID)' not in new_cols: 'Organism (ID)'}
'len(tax_cols) > 0 and "Taxonomic lineage" not in new_cols': 'Taxonomic lineage',
'len(taxids_cols) > 0 and "Taxonomic lineage (Ids)" not in new_cols': 'Taxonomic lineage (Ids)',
'"Taxonomic lineage (SPECIES)" in columns and "Organism" not in new_cols': 'Organism',
'"Taxonomic lineage IDs (SPECIES)" in columns and "Organism (ID)" not in new_cols': 'Organism (ID)'}
for cond, col in conditions.items(): # check if cond (key) is True, then append or not the col (value)
if cond:
if eval(cond):
new_cols.append(col)
for col in ['Entry Name', 'Entry']: # UPIMAPI requires these two columns to be present
if col not in new_cols:
Expand Down

0 comments on commit 46fa183

Please sign in to comment.