本文整理匯總了Python中gimmemotifs.config.MotifConfig.get_score_dir方法的典型用法代碼示例。如果您正苦於以下問題:Python MotifConfig.get_score_dir方法的具體用法?Python MotifConfig.get_score_dir怎麽用?Python MotifConfig.get_score_dir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gimmemotifs.config.MotifConfig
的用法示例。
在下文中一共展示了MotifConfig.get_score_dir方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: MotifComparer
# 需要導入模塊: from gimmemotifs.config import MotifConfig [as 別名]
# 或者: from gimmemotifs.config.MotifConfig import get_score_dir [as 別名]
class MotifComparer(object):
"""Class for motif comparison.
Compare two or more motifs using a variety of metrics. Probably the best
metric to compare motifs is seqcor. The implementation of this metric
is similar to the one used in Grau (2015), where motifs are scored
according to the Pearson correlation of the scores along sequence. In this
case a de Bruijn of k=7 is used.
Valid metrics are:
seqcor - Pearson correlation of motif scores along sequence.
pcc - Pearson correlation coefficient of motif PFMs.
ed - Euclidean distance-based similarity of motif PFMs.
distance - Distance-based similarity of motif PFMs.
wic - Weighted Information Content, see van Heeringen 2011.
chisq - Chi-squared similarity of motif PFMs.
akl - Similarity based on average Kullback-Leibler similarity, see Mahony, 2011.
ssd - Sum of squared distances of motif PFMs.
Examples
--------
mc = MotifComparer()
# Compare two motifs
score, pos, strand = mc.compare_motifs(m1, m2, metric="seqcor")
# Compare a list of motifs to another list of motifs
mc.get_all_scores(motifs, dbmotifs, match, metric, combine)
# Get the best match for every motif in a list of reference motifs
get_closest_match(motifs, dbmotifs=None)
"""
def __init__(self):
self.config = MotifConfig()
self.metrics = ["pcc", "ed", "distance", "wic"]
self.combine = ["mean", "sum"]
self._load_scores()
# Create a parallel python job server, to use for fast motif comparison
def _load_scores(self):
self.scoredist = {}
for metric in self.metrics:
self.scoredist[metric] = {"total": {}, "subtotal": {}}
for match in ["total", "subtotal"]:
for combine in ["mean"]:
self.scoredist[metric]["%s_%s" % (match, combine)] = {}
score_file = os.path.join(self.config.get_score_dir(), "%s_%s_%s_score_dist.txt" % (match, metric, combine))
if os.path.exists(score_file):
with open(score_file) as f:
for line in f:
l1, l2, m, sd = line.strip().split("\t")[:4]
self.scoredist[metric]["%s_%s" % (match, combine)].setdefault(int(l1), {})[int(l2)] = [float(m), float(sd)]
def compare_motifs(self, m1, m2, match="total", metric="wic", combine="mean", pval=False):
"""Compare two motifs.
The similarity metric can be any of seqcor, pcc, ed, distance, wic,
chisq, akl or ssd. If match is 'total' the similarity score is
calculated for the whole match, including positions that are not
present in both motifs. If match is partial or subtotal, only the
matching psotiions are used to calculate the score. The score of
individual position is combined using either the mean or the sum.
Note that the match and combine parameters have no effect on the seqcor
similarity metric.
Parameters
----------
m1 : Motif instance
Motif instance 1.
m2 : Motif instance
Motif instance 2.
match : str, optional
Match can be "partial", "subtotal" or "total". Not all metrics use
this.
metric : str, optional
Distance metric.
combine : str, optional
Combine positional scores using "mean" or "sum". Not all metrics
use this.
pval : bool, optional
Calculate p-vale of match.
Returns
-------
score, position, strand
"""
if metric == "seqcor":
return seqcor(m1, m2)
elif match == "partial":
if pval:
return self.pvalue(m1, m2, "total", metric, combine, self.max_partial(m1.pwm, m2.pwm, metric, combine))
elif metric in ["pcc", "ed", "distance", "wic", "chisq", "ssd"]:
return self.max_partial(m1.pwm, m2.pwm, metric, combine)
#.........這裏部分代碼省略.........