-
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 #11 from maxibor/dev
Version 0.40
- Loading branch information
Showing
14 changed files
with
68,378 additions
and
138 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
Large diffs are not rendered by default.
Oops, something went wrong.
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.30' | ||
__version__ = "0.40" | ||
from pydamage.main import 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import pkg_resources | ||
import pandas as pd | ||
import numpy as np | ||
import pickle | ||
|
||
|
||
def load_model(): | ||
"""Returns the pmml model""" | ||
# This is a stream,like object. If you want the actual info, call | ||
# stream.read() | ||
stream = pkg_resources.resource_stream(__name__, "models/glm_accuracy_model.pickle") | ||
return pickle.load(stream) | ||
|
||
|
||
def prepare_data(pd_df): | ||
"""Prepare pydamage result data for accuracy modelling | ||
Args: | ||
pd_df (pandas DataFrame):pydamage df result | ||
""" | ||
coverage_bins = pd.IntervalIndex.from_tuples( | ||
[ | ||
(0, 2), | ||
(2, 3), | ||
(3, 5), | ||
(5, 10), | ||
(10, 20), | ||
(20, 50), | ||
(50, 100), | ||
(100, 200), | ||
(200, np.inf), | ||
] | ||
) | ||
coverage_bins_labels = [ | ||
"1-2", | ||
"2-3", | ||
"3-5", | ||
"5-10", | ||
"10-20", | ||
"20-50", | ||
"50-100", | ||
"100-200", | ||
"200-500", | ||
] | ||
|
||
reflen_bins = pd.IntervalIndex.from_tuples( | ||
[ | ||
(0, 1000), | ||
(1000, 2000), | ||
(2000, 5000), | ||
(5000, 10000), | ||
(10000, 20000), | ||
(20000, 50000), | ||
(50000, 100000), | ||
(100000, 200000), | ||
(200000, np.inf), | ||
] | ||
) | ||
|
||
reflen_bins_labels = [ | ||
"500-1000", | ||
"1000-2000", | ||
"2000-5000", | ||
"5000-10000", | ||
"10000-20000", | ||
"20000-50000", | ||
"50000-100000", | ||
"100000-200000", | ||
"200000-500000", | ||
] | ||
simu_cov = pd.cut(pd_df["coverage"], coverage_bins) | ||
simu_cov.cat.rename_categories(coverage_bins_labels, inplace=True) | ||
pd_df["simuCov"] = simu_cov | ||
|
||
simu_contig_length = pd.cut(pd_df["reflen"], reflen_bins) | ||
simu_contig_length.cat.rename_categories(reflen_bins_labels, inplace=True) | ||
|
||
pd_df["simuContigLength"] = simu_contig_length | ||
pd_df = pd_df[ | ||
["simuCov", "simuContigLength", "damage_model_pmax", "gc_content"] | ||
].rename(columns={"damage_model_pmax": "damage", "gc_content": "GCcontent"}) | ||
|
||
return pd_df | ||
|
||
|
||
def fit_model(df, model): | ||
"""Fit GLM model to data | ||
Args: | ||
df (pandas DataFrame): prepared pydamage results | ||
model (pypmml model): GLM accuracy model | ||
""" | ||
return model.predict(df).to_frame(name="pred_accuracy") |
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.