本文整理汇总了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)
#.........这里部分代码省略.........