-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from maxibor/dev
Dev
- Loading branch information
Showing
23 changed files
with
328 additions
and
193 deletions.
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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
__version__ = "0.50beta" | ||
from pydamage.main import analyze | ||
__version__ = "0.60" | ||
from pydamage.main import pydamage_analyze |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def get_citation(): | ||
BIB = """ | ||
@article{Borry2021_pydamage, | ||
author = {Borry, Maxime and Huebner, Alexander and Rohrlach, Adam B and Warinner, Christina G}, | ||
doi = {10.1101/2021.03.24.436838}, | ||
elocation-id = {2021.03.24.436838}, | ||
eprint = {https://www.biorxiv.org/content/early/2021/03/24/2021.03.24.436838.full.pdf}, | ||
journal = {bioRxiv}, | ||
publisher = {Cold Spring Harbor Laboratory}, | ||
title = {PyDamage: automated ancient damage identification and estimation for contigs in ancient DNA de novo assembly}, | ||
url = {https://www.biorxiv.org/content/early/2021/03/24/2021.03.24.436838}, | ||
year = {2021} | ||
} | ||
""" | ||
print(BIB) |
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from kneed import KneeLocator | ||
from numpy import arange | ||
from pydamage.utils import df_to_csv | ||
from pandas import read_csv | ||
|
||
|
||
def find_knee(pydam_df, min_knee=0.5, alpha=0.05): | ||
"""Find kneedle point in PyDamage results | ||
Finding the kneedle point to get the optimal | ||
tradeoff between FP and FN, for the predicted | ||
accurary threshold | ||
Args: | ||
pydam_df (pandas df): pydamage results | ||
min_knee (float, optional): Min pred_accuracy threshold. Defaults to 0.5 | ||
alpha(float, optional): Alpha q-value threshold | ||
""" | ||
thresholds = [i.round(2) for i in arange(min_knee, 1, 0.01)] | ||
nb_contigs = list() | ||
nb_contigs = [] | ||
for i in thresholds: | ||
nb_contigs.append( | ||
pydam_df.query(f"pred_accuracy >= {i} & qvalue <= {alpha}").shape[0] | ||
) | ||
kneedle = KneeLocator( | ||
thresholds, | ||
nb_contigs, | ||
S=1.0, | ||
curve="convex", | ||
direction="decreasing", | ||
online=True, | ||
) | ||
print(thresholds) | ||
print(nb_contigs) | ||
return kneedle.knee | ||
|
||
|
||
def filter_pydamage_results(pydam_df, acc_thresh, alpha=0.05): | ||
"""Filter pydamage results on pred_accuracy and qvalue | ||
Args: | ||
pydam_df (pandas df): pydamage results | ||
acc_thresh (float): predictiona accuracy threshold | ||
alpha (float, optional): Alpha q-value threshold. Defaults to 0.05. | ||
""" | ||
|
||
return pydam_df.query(f"pred_accuracy >= {acc_thresh} & qvalue <= {alpha}") | ||
|
||
|
||
def apply_filter(csv, outdir, alpha=0.05): | ||
"""Apply pydamage filtering | ||
Args: | ||
csv (str): path to pydamage result file | ||
outdir (str): Path to output directory | ||
alpha (float, optional): Alpha q-value threshold. Defaults to 0.05. | ||
""" | ||
|
||
df = read_csv(csv) | ||
outfile = "pydamage_filtered_results.csv" | ||
knee = find_knee(df) | ||
print(f"Optimal prediction accuracy threshold found to be: {knee}") | ||
filt_df = filter_pydamage_results(df, acc_thresh=knee) | ||
print( | ||
f"Filtering PyDamage results with qvalue <={alpha} and pred_accuracy >= {knee}" | ||
) | ||
df_to_csv(filt_df, outdir, outfile) | ||
print(f"Filtered PyDamage results written to {outdir}/{outfile}") | ||
return filt_df |
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
Oops, something went wrong.