Skip to content

Commit 63a587d

Browse files
committed
separate the calculate read threshold function out
1 parent 89170f8 commit 63a587d

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

q2_katharoseq/_methods.py

+38-3
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ def fit_lm(table,
9797
return lm, filtered, positive_controls
9898

9999

100-
def read_count_threshold(
101-
output_dir: str,
100+
def calculate_threshold(
102101
threshold: int,
103102
positive_control_value: str,
104103
positive_control_column: qiime2.CategoricalMetadataColumn,
105104
cell_count_column: qiime2.NumericMetadataColumn,
106105
table: pd.DataFrame,
107106
control: str,
108-
asv: str = None) -> None:
107+
asv: str = None):
108+
109109
if control == 'asv':
110110
if asv is None:
111111
raise ValueError("Control type set to asv but no asv provided")
@@ -187,6 +187,41 @@ def read_count_threshold(
187187
min_freq = get_threshold(katharo['log_asv_reads'],
188188
katharo['correct_assign'],
189189
threshold/100)
190+
return min_freq, popt, pcov, katharo, max_inputT
191+
192+
193+
def read_count_threshold(
194+
output_dir: str,
195+
threshold: int,
196+
positive_control_value: str,
197+
positive_control_column: qiime2.CategoricalMetadataColumn,
198+
cell_count_column: qiime2.NumericMetadataColumn,
199+
table: pd.DataFrame,
200+
control: str,
201+
asv: str = None) -> None:
202+
203+
min_freq, popt, pcov, katharo, max_inputT = \
204+
calculate_threshold(threshold,
205+
positive_control_value,
206+
positive_control_column,
207+
cell_count_column,
208+
table,
209+
control,
210+
asv)
211+
212+
213+
# PLOT
214+
x = np.linspace(0, 5, 50)
215+
y = allosteric_sigmoid(x, *popt)
216+
plt.plot(katharo['log_asv_reads'],
217+
katharo['correct_assign'],
218+
'o', label='data')
219+
plt.plot(x, y, label='fit')
220+
plt.ylim(0, 1.05)
221+
plt.legend(loc='best')
222+
plt.savefig(os.path.join(output_dir, 'fit.svg'))
223+
plt.close()
224+
190225

191226
# VISUALIZER
192227
max_input_html = q2templates.df_to_html(max_inputT.to_frame())

0 commit comments

Comments
 (0)