@@ -38,71 +38,73 @@ def classyfire_to_colors(classified_feature_data: pd.DataFrame,
38
38
help = 'Path to feature data with Classyfire taxonomy.' )
39
39
@click .option ('--feature-data-column' , default = 'class' , type = str ,
40
40
help = 'One of the columns in feature data table' )
41
+ @click .option ('--color-palette' , default = 'bright' , type = str ,
42
+ help = 'Color palette for tree clades. One of the options'
43
+ ' allowed by seaborn.color_palette()' )
41
44
@click .option ('--ms2-label' , default = True , type = bool ,
42
45
help = 'Option to label tree tips with MS/MS library match' )
43
- @click .option ('--color-file-path' , default = './itol_colors.txt' , type = str ,
46
+ @click .option ('--color-file-path' , default = None , type = str ,
44
47
help = 'Path to file with colors specifications for tree clades' )
45
- @click .option ('--label-file-path' , default = './itol_labels.txt' , type = str ,
48
+ @click .option ('--label-file-path' , default = None , type = str ,
46
49
help = 'Path to file with label specifications for tree tips' )
47
- @click .option ('--color-palette' , default = 'bright' , type = str ,
48
- help = 'Color palette for tree clades. One of the options'
49
- ' allowed by seaborn.color_palette()' )
50
- @click .option ('--sample-feature-table' , type = str ,
50
+ @click .option ('--feature-table' , default = None , type = str ,
51
51
help = 'Path to sample feature table.' )
52
- @click .option ('--sample-metadata' , type = str ,
52
+ @click .option ('--sample-metadata' , default = None , type = str ,
53
53
help = 'Path to sample metadata.' )
54
- @click .option ('--sample-metadata-column' , type = str ,
54
+ @click .option ('--sample-metadata-column' , default = None , type = str ,
55
55
help = 'Categorical sample metadata column.' )
56
- @click .option ('--barchart-file-path' , default = './itol_bars.txt' , type = str ,
56
+ @click .option ('--barchart-file-path' , default = None , type = str ,
57
57
help = 'Path to file with values for multi-value bar chart' )
58
58
def get_itol_visualization (classified_feature_data : str ,
59
59
feature_data_column : str = 'class' ,
60
60
ms2_label : bool = True ,
61
- color_file_path : str = './itol_colors.txt' ,
62
- label_file_path : str = './itol_labels.txt' ,
61
+ color_file_path : str = None ,
62
+ label_file_path : str = None ,
63
63
color_palette : str = 'husl' ,
64
- sample_feature_table : str = None ,
64
+ feature_table : str = None ,
65
65
sample_metadata : str = None ,
66
66
sample_metadata_column : str = None ,
67
- barchart_file_path : str = './itol_bars.qza' ):
67
+ barchart_file_path : str = None ):
68
68
'''This function creates iTOL metadata files to specify clade colors and
69
69
tip labels based on Classyfire annotations. It also adds bar plots of the
70
70
abundance of features stratified by user-specified sample metadata column.
71
71
'''
72
72
fdata = Artifact .load (classified_feature_data ).view (pd .DataFrame )
73
73
color_map = classyfire_to_colors (fdata , feature_data_column , color_palette )
74
- with open (color_file_path , 'w+' ) as fh :
75
- fh .write ('TREE_COLORS\n '
76
- 'SEPARATOR TAB\n '
77
- 'DATA\n ' )
78
- for idx in fdata .index :
79
- color = color_map [fdata .loc [idx , feature_data_column ]]
80
- if fdata .loc [idx , 'annotation_type' ] == 'MS2' :
81
- fh .write (idx + '\t ' + 'clade\t ' +
82
- color + '\t normal\t 6\n ' )
83
- if fdata .loc [idx , 'annotation_type' ] == 'CSIFingerID' :
84
- fh .write (idx + '\t ' + 'clade\t ' +
85
- color + '\t dashed\t 4\n ' )
86
- with open (label_file_path , 'w+' ) as fh :
87
- fh .write ('LABELS\n '
88
- 'SEPARATOR TAB\n '
89
- 'DATA\n ' )
90
- if ms2_label :
74
+ if color_file_path :
75
+ with open (color_file_path , 'w+' ) as fh :
76
+ fh .write ('TREE_COLORS\n '
77
+ 'SEPARATOR TAB\n '
78
+ 'DATA\n ' )
91
79
for idx in fdata .index :
92
- ms2_compound = fdata .loc [idx , 'ms2_compound' ]
93
- if pd .notna (ms2_compound ) and not ms2_compound .isspace ():
94
- label = ms2_compound
95
- else :
80
+ color = color_map [fdata .loc [idx , feature_data_column ]]
81
+ if fdata .loc [idx , 'annotation_type' ] == 'MS2' :
82
+ fh .write (idx + '\t ' + 'clade\t ' +
83
+ color + '\t normal\t 6\n ' )
84
+ if fdata .loc [idx , 'annotation_type' ] == 'CSIFingerID' :
85
+ fh .write (idx + '\t ' + 'clade\t ' +
86
+ color + '\t dashed\t 4\n ' )
87
+ if label_file_path :
88
+ with open (label_file_path , 'w+' ) as fh :
89
+ fh .write ('LABELS\n '
90
+ 'SEPARATOR TAB\n '
91
+ 'DATA\n ' )
92
+ if ms2_label :
93
+ for idx in fdata .index :
94
+ ms2_compound = fdata .loc [idx , 'ms2_compound' ]
95
+ if pd .notna (ms2_compound ) and not ms2_compound .isspace ():
96
+ label = ms2_compound
97
+ else :
98
+ label = fdata .loc [idx , feature_data_column ]
99
+ fh .write (idx + '\t ' + label + '\n ' )
100
+ else :
101
+ for idx in fdata .index :
96
102
label = fdata .loc [idx , feature_data_column ]
97
- fh .write (idx + '\t ' + label + '\n ' )
98
- else :
99
- for idx in fdata .index :
100
- label = fdata .loc [idx , feature_data_column ]
101
- fh .write (idx + '\t ' + label + '\n ' )
103
+ fh .write (idx + '\t ' + label + '\n ' )
102
104
103
105
# generate bar chart
104
106
if barchart_file_path :
105
- get_itol_barchart (fdata , sample_feature_table , sample_metadata ,
107
+ get_itol_barchart (fdata , feature_table , sample_metadata ,
106
108
sample_metadata_column , barchart_file_path )
107
109
108
110
0 commit comments