-
Notifications
You must be signed in to change notification settings - Fork 7
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
Covid19 #140
Merged
Merged
Covid19 #140
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a64e1e0
increased max kmer freq to 10000000 for high coverage amplicon datasets
jrober84 6c5b566
increased max kmer freq to 10000000 for high coverage amplicon datasets
jrober84 0f45df1
removed qc_message column from k-mer results because it is highly red…
jrober84 34d8e99
removed qc_message column from k-mer results because it is highly red…
jrober84 37afbea
added minimum k-mer fraction as additional filtering option
jrober84 cdc7004
improved documentation of the new kmer filtering function
jrober84 cb9f22e
fixed issue with using count of position instead of frequency
jrober84 a4d5572
enhanced detailed report with additional information and df no longer…
jrober84 8a1c62c
updated tests with new fields for read kmer reports
jrober84 15aa720
simplified calc kmer fraction function
jrober84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,30 @@ def parallel_query_reads(reads: List[Tuple[List[str], str]], | |
outputs = [x.get() for x in res] | ||
return outputs | ||
|
||
def calc_kmer_fraction(df,min_kmer_frac=0.05): | ||
"""Calculate the percentage each k-mer frequence represents for a given position | ||
|
||
Args: | ||
df: BioHansel k-mer frequence pandas df | ||
min_kmer_frac: float 0 - 1 on the minimum fraction a kmer needs to be to be considered valid | ||
|
||
Returns: | ||
- pd.DataFrame with k-mers with kmer_fraction column | ||
""" | ||
position_frequencies = df[['refposition','freq']].groupby(['refposition']).sum().reset_index() | ||
percentages = [] | ||
total_refposition_kmer_frequencies = [] | ||
for index,row in df.iterrows(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend using for row in df.itertuples():
refposition = row.refposition # cannot do string based access (row['refposition']) with tuples You could also look into using apply instead of using a for-loop: def get_kmer_fraction(row):
total_freq = position_frequencies.get(row.refposition, 0)
return row.freq / total_freq if total_freq > 0 else 0.0
df['kmer_fraction'] = df.apply(get_kmer_fraction, axis=1)
df['total_refposition_kmer_frequency'] = df.apply(lambda row: position_frequencies.get(row.refposition, 0), axis=1) |
||
total_freq = position_frequencies.loc[position_frequencies['refposition'] == row['refposition'], 'freq'].iloc[0] | ||
if total_freq > 0: | ||
percentages.append(row['freq'] / total_freq) | ||
else: | ||
percentages.append(0.0) | ||
total_refposition_kmer_frequencies.append(total_freq) | ||
df['kmer_fraction'] = percentages | ||
df['total_refposition_kmer_frequency'] = total_refposition_kmer_frequencies | ||
return df | ||
|
||
|
||
def subtype_reads(reads: Union[str, List[str]], | ||
genome_name: str, | ||
|
@@ -285,9 +309,12 @@ def subtype_reads(reads: Union[str, List[str]], | |
df['subtype'] = subtypes | ||
df['is_pos_kmer'] = ~df.kmername.str.contains('negative') | ||
df['is_kmer_freq_okay'] = (df.freq >= subtyping_params.min_kmer_freq) & (df.freq <= subtyping_params.max_kmer_freq) | ||
#apply a scaled approach for filtering of k-mers required for high coverage amplicon data | ||
df = calc_kmer_fraction(df,subtyping_params.min_kmer_frac) | ||
df['is_kmer_fraction_okay'] = df.kmer_fraction >= subtyping_params.min_kmer_frac | ||
st.avg_kmer_coverage = df['freq'].mean() | ||
st, df = process_subtyping_results(st, df[df.is_kmer_freq_okay], scheme_subtype_counts) | ||
st.qc_status, st.qc_message = perform_quality_check(st, df, subtyping_params) | ||
st, filtered_df = process_subtyping_results(st, df[(df.is_kmer_freq_okay & df.is_kmer_fraction_okay)], scheme_subtype_counts) | ||
st.qc_status, st.qc_message = perform_quality_check(st, filtered_df, subtyping_params) | ||
df['file_path'] = str(st.file_path) | ||
df['sample'] = genome_name | ||
df['scheme'] = scheme_name or scheme | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be easier to use a dict:
The dict should have
refposition
keys and summed frequency values, so gettingtotal_freq
would be easier and clearer: