本文整理汇总了Python中easydev.Progress类的典型用法代码示例。如果您正苦于以下问题:Python Progress类的具体用法?Python Progress怎么用?Python Progress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Progress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_single_reads
def process_single_reads(reader, modifiers, filters, n_progress=-1):
"""
Loop over reads, find adapters, trim reads, apply modifiers and
output modified reads.
Return a Statistics object.
"""
n = 0 # no. of processed reads
total_bp = 0
if n_progress != -1:
try:
from easydev import Progress
pb = Progress(n_progress)
count = 0
except:
n_progress = -1
for read in reader:
n += 1
total_bp += len(read.sequence)
for modifier in modifiers:
read = modifier(read)
for filter in filters:
if filter(read):
break
if n_progress != -1:
count += 1
pb.animate(count)
return Statistics(n=n, total_bp1=total_bp, total_bp2=None)
示例2: compounds2accession
def compounds2accession(self, compounds):
"""For each compound, identifies the target and corresponding UniProt
accession number
This is not part of ChEMBL API
::
# we recommend to use cache if you use this method regularly
c = Chembl(cache=True)
drugs = c.get_approved_drugs()
# to speed up example
drugs = drugs[0:20]
IDs = [x['molecule_chembl_id] for x in drugs]
c.compounds2accession(IDs)
"""
# we jump from compounds to targets through activities
# Here this is a one to many mapping so we initialise a default
# dictionary.
from collections import defaultdict
compound2target = defaultdict(set)
filter = "molecule_chembl_id__in={}"
from easydev import Progress
pb = Progress(len(compounds))
for i in range(0, len(compounds)):
# FIXME could get activities by bunch using
# ",".join(compounds[i:i+10) for example
activities = self.get_activity(filters=filter.format(compounds[i]))
# get target ChEMBL IDs from activities
for act in activities:
compound2target[act['molecule_chembl_id']].add(act['target_chembl_id'])
pb.animate(i+1)
# What we need is to get targets for all targets found in the previous
# step. For each compound/drug there are hundreds of targets though. And
# we will call the get_target for each list of hundreds targets. This
# will take forever. Instead, because there are *only* 12,000 targets,
# let us download all of them ! This took about 4 minutes on this test but
# if you use the cache, next time it will be much much quicker. This is
# not down at the activities level because there are too many entries
targets = self.get_target(limit=-1)
# identifies all target chembl id to easily retrieve the entry later on
target_names = [target['target_chembl_id'] for target in targets]
# retrieve all uniprot accessions for all targets of each compound
for compound, targs in compound2target.items():
accessions = set()
for target in targs:
index = target_names.index(target)
accessions = accessions.union([comp['accession']
for comp in targets[index]['target_components']])
compound2target[compound] = accessions
return compound2target
示例3: _get_G
def _get_G(self, gold):
from easydev import Progress
import scipy.sparse
regulators = list(set(gold[0]))
targets = list(set(gold[[0,1]].stack()))
N, M = gold[0].max(), gold[1].max()
## A will store indices goind from 0 (not 1) to N-1
# hence the -1 indices when handling A if i,j are the
# values of the gene
A = np.zeros((N, M))
for row in gold[[0,1]].values:
i, j = row
A[i-1, j-1] = 1
A_sparse = scipy.sparse.csr_matrix(A)
#N, M = len(regulators), len(targets)
G = np.zeros((N, M))
pb = Progress(len(regulators), 1)
for i, x in enumerate(regulators):
for j, y in enumerate(targets):
if A[x-1, y-1] == 1:
G[x-1, y-1] = 1
elif x != y:
G[x-1, y-1] = -1
pb.animate(i+1)
return G
示例4: _opt_ridge_lasso
def _opt_ridge_lasso(self, drug_name, feature_name, method, alphas=None):
if alphas is None:
alphas = pylab.linspace(0,1, 20)
mses = []
params = []
method_buf = self.settings.regression_method
alpha_buf = self.settings.elastic_net.alpha
pb = Progress(len(alphas))
for j, alpha in enumerate(alphas):
self.settings.regression_method = method
self.settings.elastic_net.alpha = alpha
odof = self.anova_one_drug_one_feature(drug_name,
feature_name)
anova = self._get_anova_summary(self.data_lm,
output='dataframe')
#mses.append(anova.ix['Residuals']['Sum Sq'])
mses.append(anova.ix['tissue']['F value'])
#mses.append(anova['Sum Sq'].sum())
pb.animate(j+1)
params.append(self.data_lm.params)
self.settings.regression_method = method_buf
self.settings.elastic_net.alpha = alpha_buf
return alphas, mses, params
示例5: _score_challengeA_bunch
def _score_challengeA_bunch(self, filenames, subname):
from easydev import Progress
pb = Progress(5, 1)
pb.animate(0)
results = []
for i, filename in enumerate(filenames):
res = self.score_challengeA(filename, subname + "_" + str(i + 1))
pb.animate(i + 1)
results.append(res)
aupr_score = -np.mean(np.log10([x["p_auroc"] for x in results]))
auroc_score = -np.mean(np.log10([x["p_aupr"] for x in results]))
score = (aupr_score + auroc_score) / 2.0
df = pd.TimeSeries()
df["Overall Score"] = score
df["AUPR score (pval)"] = aupr_score
df["AUROC score (pval)"] = aupr_score
for i in range(1, 6):
df["AUPR Net %s" % i] = results[i - 1]["aupr"]
for i in range(1, 6):
df["AUROC Net %s" % i] = results[i - 1]["auroc"]
return df
示例6: diagnostics
def diagnostics(self):
"""Return dataframe with information about the analysis
"""
n_drugs = len(self.ic50.drugIds)
n_features = len(self.features.features) - self.features.shift
n_combos = n_drugs * n_features
feasible = 0
pb = Progress(n_drugs, 1)
counter = 0
for drug in self.ic50.drugIds:
for feature in self.features.features[self.features.shift:]:
dd = self._get_one_drug_one_feature_data(drug, feature,
diagnostic_only=True)
if dd.status is True:
feasible += 1
counter += 1
pb.animate(counter)
results = {
'n_drug': n_drugs,
'n_combos': n_combos,
'feasible_tests': feasible,
'percentage_feasible_tests': float(feasible)/n_combos*100}
return results
示例7: create_html_drugs
def create_html_drugs(self):
"""Create an HTML page for each drug"""
# group by drugs
all_drugs = list(self.df['DRUG_ID'].unique())
df = self.get_significant_set()
groups = df.groupby('DRUG_ID')
if self.verbose:
print("Creating individual HTML pages for each drug")
N = len(groups.indices.keys())
N = len(all_drugs)
pb = Progress(N)
for i, drug in enumerate(all_drugs):
# enumerate(groups.indices.keys()):
# get the indices and therefore subgroup
if drug in groups.groups.keys():
subdf = groups.get_group(drug)
else:
subdf = {}
html = HTMLOneDrug(self, self.df, subdf, drug)
html.create_report(onweb=False)
if self.settings.animate:
pb.animate(i+1)
if self.settings.animate: print("\n")
示例8: filling_chembl_pubchem_using_unichem
def filling_chembl_pubchem_using_unichem(self):
"""
"""
N = len(self.drug_ids)
pb = Progress(N)
for i,this in enumerate(self.drug_ids):
entry = self.dd.df.ix[this]
# if no information is provided, we will need to get it
# from chemspider
# From the database, when chembl is provided, it is unique
# same for chemspider and pubchem and CAS
select = entry[['CHEMSPIDER', 'CHEMBL', 'PUBCHEM']]
if select.count() == 0:
name = self.dd.df.ix[this].DRUG_NAME
results = self._cs_find(name)
if len(results) == 0:
# nothing found
pass
elif len(results) == 1:
self.dd_filled.df.ix[this].loc['CHEMSPIDER'] = results[0]
else:
# non unique
#chemspider = ",".join([str(x) for x in results])
self.dd_filled.df.ix[this].loc['CHEMSPIDER'] = results
pb.animate(i+1)
# Search in chemspider systematically
for i, this in enumerate(self.drug_ids):
entry = self.dd.df.ix[this]
if select.count() == 1:
res = self._cs_find(drug)
pb.animate(i+1)
示例9: to_kmer_content
def to_kmer_content(self, k=7):
"""Return a Series with kmer count across all reads
:param int k: (default to 7-mers)
:return: Pandas Series with index as kmer and values as count.
Takes about 30 seconds on a million reads.
"""
# Counter is slow if we apply it on each read.
# .count is slow as well
import collections
from sequana.kmer import get_kmer
counter = collections.Counter()
pb = Progress(len(self))
buffer_ = []
for i, this in enumerate(self):
buffer_.extend(list(get_kmer(this['sequence'], k)))
if len(buffer_) > 100000:
counter += collections.Counter(buffer_)
buffer_ = []
pb.animate(i)
counter += collections.Counter(buffer_)
ts = pd.Series(counter)
ts.sort_values(inplace=True, ascending=False)
return ts
示例10: search_from_smile_inchembl
def search_from_smile_inchembl(self):
N = len(self.drug_ids)
pb = Progress(N)
self.results_chembl = {}
self.results_chemspider = {}
for i in range(0, N):
drug = self.drug_ids[i]
self.results_chembl[drug] = []
if self.results[drug]:
for chemspider_id in self.results[drug]:
chemspider_entry = self._cs_get(chemspider_id)
self.results_chemspider[drug] = chemspider_entry
smile = chemspider_entry['smiles']
# now search in chembl
res_chembl = self.chembl.get_compounds_by_SMILES(smile)
try:
res_chembl['compounds']
self.results_chembl[drug].extend(res_chembl['compounds'])
except:
pass
pb.animate(i+1)
示例11: dendogram_coefficients
def dendogram_coefficients(self, stacked=False, show=True, cmap="terrain"):
"""
shows the coefficient of each optimised model for each drug
"""
drugids = self.drugIds
from easydev import Progress
pb = Progress(len(drugids))
d = {}
for i, drug_name in enumerate(drugids):
X, Y = self._get_one_drug_data(drug_name, randomize_Y=False)
results = self.runCV(drug_name, verbose=False)
df = pd.DataFrame({'name': X.columns, 'weight': results.coefficients})
df = df.set_index("name").sort_values("weight")
d[drug_name] = df.copy()
pb.animate(i+1)
# use drugid to keep same order as in the data
dfall = pd.concat([d[i] for i in drugids], axis=1)
dfall.columns = drugids
if show:
from biokit import heatmap
h = heatmap.Heatmap(dfall, cmap=cmap)
h.plot(num=1,colorbar_position="top left")
if stacked is True:
dfall = dfall.stack().reset_index()
dfall.columns = ["feature", "drug", "weight"]
return dfall
示例12: create_html_associations
def create_html_associations(self):
"""Create an HTML page for each significant association
The name of the output HTML file is **<association id>.html**
where association id is stored in :attr:`df`.
"""
print("\nCreating individual HTML pages for each association")
df = self.get_significant_set()
drugs = df['DRUG_ID'].values
features = df['FEATURE'].values
assocs = df['ASSOC_ID'].values
fdrs = df['ANOVA_FEATURE_FDR'].values
N = len(df)
pb = Progress(N)
html = Association(self, drug='dummy', feature='dummy', fdr='dummy')
for i in range(N):
html.drug = drugs[i]
html.feature = features[i]
html._filename = str(assocs[i]) + '.html'
html.fdr = fdrs[i]
html.assoc_id = assocs[i]
html._init_report() # since we have one shared instance
html.create_report(onweb=False)
pb.animate(i+1)
示例13: select_random_reads
def select_random_reads(self, N=None, output_filename="random.fasta"):
"""Select random reads and save in a file
:param int N: number of random unique reads to select
should provide a number but a list can be used as well.
:param str output_filename:
"""
import numpy as np
thisN = len(self)
if isinstance(N, int):
if N > thisN:
N = thisN
# create random set of reads to pick up
cherries = list(range(thisN))
np.random.shuffle(cherries)
# cast to set for efficient iteration
cherries = set(cherries[0:N])
elif isinstance(N, set):
cherries = N
elif isinstance(N, list):
cherries = set(N)
fasta = FastxFile(self.filename)
pb = Progress(thisN) # since we scan the entire file
with open(output_filename, "w") as fh:
for i, read in enumerate(fasta):
if i in cherries:
fh.write(read.__str__() + "\n")
else:
pass
pb.animate(i+1)
return cherries
示例14: volcano_plot_all_drugs
def volcano_plot_all_drugs(self):
"""Create a volcano plot for each drug and save in PNG files
Each filename is set to **volcano_<drug identifier>.png**
"""
drugs = list(self.df[self._colname_drugid].unique())
pb = Progress(len(drugs), 1)
for i, drug in enumerate(drugs):
self.volcano_plot_one_drug(drug)
self.savefig("volcano_%s.png" % drug, size_inches=(10, 10))
pb.animate(i+1)
示例15: _load_complexes
def _load_complexes(self, show_progress=True):
from easydev import Progress
import time
pb = Progress(len(self.df.complexAC))
complexes = {}
self.logging.info("Loading all details from the IntactComplex database")
for i, identifier in enumerate(self.df.complexAC):
res = self.webserv.details(identifier)
complexes[identifier] = res
if show_progress:
pb.animate(i+1)
self._complexes = complexes