Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate the calculate_threshold function out #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions q2_katharoseq/_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ def fit_lm(table,
return lm, filtered, positive_controls


def read_count_threshold(
output_dir: str,
def calculate_threshold(
threshold: int,
positive_control_value: str,
positive_control_column: qiime2.CategoricalMetadataColumn,
cell_count_column: qiime2.NumericMetadataColumn,
table: pd.DataFrame,
control: str,
asv: str = None) -> None:
asv: str = None):

if control == 'asv':
if asv is None:
raise ValueError("Control type set to asv but no asv provided")
Expand Down Expand Up @@ -187,6 +187,41 @@ def read_count_threshold(
min_freq = get_threshold(katharo['log_asv_reads'],
katharo['correct_assign'],
threshold/100)
return min_freq, popt, pcov, katharo, max_inputT


def read_count_threshold(
output_dir: str,
threshold: int,
positive_control_value: str,
positive_control_column: qiime2.CategoricalMetadataColumn,
cell_count_column: qiime2.NumericMetadataColumn,
table: pd.DataFrame,
control: str,
asv: str = None) -> None:

min_freq, popt, pcov, katharo, max_inputT = \
calculate_threshold(threshold,
positive_control_value,
positive_control_column,
cell_count_column,
table,
control,
asv)


# PLOT
x = np.linspace(0, 5, 50)
y = allosteric_sigmoid(x, *popt)
plt.plot(katharo['log_asv_reads'],
katharo['correct_assign'],
'o', label='data')
plt.plot(x, y, label='fit')
plt.ylim(0, 1.05)
plt.legend(loc='best')
plt.savefig(os.path.join(output_dir, 'fit.svg'))
plt.close()


# VISUALIZER
max_input_html = q2templates.df_to_html(max_inputT.to_frame())
Expand Down
Loading