repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Interpolator.Reverse | def Reverse(self, y):
"""Looks up y and returns the corresponding value of x."""
return self._Bisect(y, self.ys, self.xs) | python | def Reverse(self, y):
"""Looks up y and returns the corresponding value of x."""
return self._Bisect(y, self.ys, self.xs) | [
"def",
"Reverse",
"(",
"self",
",",
"y",
")",
":",
"return",
"self",
".",
"_Bisect",
"(",
"y",
",",
"self",
".",
"ys",
",",
"self",
".",
"xs",
")"
] | Looks up y and returns the corresponding value of x. | [
"Looks",
"up",
"y",
"and",
"returns",
"the",
"corresponding",
"value",
"of",
"x",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L104-L106 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Interpolator._Bisect | def _Bisect(self, x, xs, ys):
"""Helper function."""
if x <= xs[0]:
return ys[0]
if x >= xs[-1]:
return ys[-1]
i = bisect.bisect(xs, x)
frac = 1.0 * (x - xs[i - 1]) / (xs[i] - xs[i - 1])
y = ys[i - 1] + frac * 1.0 * (ys[i] - ys[i - 1])
retu... | python | def _Bisect(self, x, xs, ys):
"""Helper function."""
if x <= xs[0]:
return ys[0]
if x >= xs[-1]:
return ys[-1]
i = bisect.bisect(xs, x)
frac = 1.0 * (x - xs[i - 1]) / (xs[i] - xs[i - 1])
y = ys[i - 1] + frac * 1.0 * (ys[i] - ys[i - 1])
retu... | [
"def",
"_Bisect",
"(",
"self",
",",
"x",
",",
"xs",
",",
"ys",
")",
":",
"if",
"x",
"<=",
"xs",
"[",
"0",
"]",
":",
"return",
"ys",
"[",
"0",
"]",
"if",
"x",
">=",
"xs",
"[",
"-",
"1",
"]",
":",
"return",
"ys",
"[",
"-",
"1",
"]",
"i",
... | Helper function. | [
"Helper",
"function",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L108-L117 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | _DictWrapper.InitMapping | def InitMapping(self, values):
"""Initializes with a map from value to probability.
values: map from value to probability
"""
for value, prob in values.iteritems():
self.Set(value, prob) | python | def InitMapping(self, values):
"""Initializes with a map from value to probability.
values: map from value to probability
"""
for value, prob in values.iteritems():
self.Set(value, prob) | [
"def",
"InitMapping",
"(",
"self",
",",
"values",
")",
":",
"for",
"value",
",",
"prob",
"in",
"values",
".",
"iteritems",
"(",
")",
":",
"self",
".",
"Set",
"(",
"value",
",",
"prob",
")"
] | Initializes with a map from value to probability.
values: map from value to probability | [
"Initializes",
"with",
"a",
"map",
"from",
"value",
"to",
"probability",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L162-L168 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | _DictWrapper.InitPmf | def InitPmf(self, values):
"""Initializes with a Pmf.
values: Pmf object
"""
for value, prob in values.Items():
self.Set(value, prob) | python | def InitPmf(self, values):
"""Initializes with a Pmf.
values: Pmf object
"""
for value, prob in values.Items():
self.Set(value, prob) | [
"def",
"InitPmf",
"(",
"self",
",",
"values",
")",
":",
"for",
"value",
",",
"prob",
"in",
"values",
".",
"Items",
"(",
")",
":",
"self",
".",
"Set",
"(",
"value",
",",
"prob",
")"
] | Initializes with a Pmf.
values: Pmf object | [
"Initializes",
"with",
"a",
"Pmf",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L170-L176 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | _DictWrapper.Copy | def Copy(self, name=None):
"""Returns a copy.
Make a shallow copy of d. If you want a deep copy of d,
use copy.deepcopy on the whole object.
Args:
name: string name for the new Hist
"""
new = copy.copy(self)
new.d = copy.copy(self.d)
new.nam... | python | def Copy(self, name=None):
"""Returns a copy.
Make a shallow copy of d. If you want a deep copy of d,
use copy.deepcopy on the whole object.
Args:
name: string name for the new Hist
"""
new = copy.copy(self)
new.d = copy.copy(self.d)
new.nam... | [
"def",
"Copy",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"new",
"=",
"copy",
".",
"copy",
"(",
"self",
")",
"new",
".",
"d",
"=",
"copy",
".",
"copy",
"(",
"self",
".",
"d",
")",
"new",
".",
"name",
"=",
"name",
"if",
"name",
"is",
"... | Returns a copy.
Make a shallow copy of d. If you want a deep copy of d,
use copy.deepcopy on the whole object.
Args:
name: string name for the new Hist | [
"Returns",
"a",
"copy",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L194-L206 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | _DictWrapper.Scale | def Scale(self, factor):
"""Multiplies the values by a factor.
factor: what to multiply by
Returns: new object
"""
new = self.Copy()
new.d.clear()
for val, prob in self.Items():
new.Set(val * factor, prob)
return new | python | def Scale(self, factor):
"""Multiplies the values by a factor.
factor: what to multiply by
Returns: new object
"""
new = self.Copy()
new.d.clear()
for val, prob in self.Items():
new.Set(val * factor, prob)
return new | [
"def",
"Scale",
"(",
"self",
",",
"factor",
")",
":",
"new",
"=",
"self",
".",
"Copy",
"(",
")",
"new",
".",
"d",
".",
"clear",
"(",
")",
"for",
"val",
",",
"prob",
"in",
"self",
".",
"Items",
"(",
")",
":",
"new",
".",
"Set",
"(",
"val",
"... | Multiplies the values by a factor.
factor: what to multiply by
Returns: new object | [
"Multiplies",
"the",
"values",
"by",
"a",
"factor",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L208-L220 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | _DictWrapper.Log | def Log(self, m=None):
"""Log transforms the probabilities.
Removes values with probability 0.
Normalizes so that the largest logprob is 0.
"""
if self.log:
raise ValueError("Pmf/Hist already under a log transform")
self.log = True
if m is N... | python | def Log(self, m=None):
"""Log transforms the probabilities.
Removes values with probability 0.
Normalizes so that the largest logprob is 0.
"""
if self.log:
raise ValueError("Pmf/Hist already under a log transform")
self.log = True
if m is N... | [
"def",
"Log",
"(",
"self",
",",
"m",
"=",
"None",
")",
":",
"if",
"self",
".",
"log",
":",
"raise",
"ValueError",
"(",
"\"Pmf/Hist already under a log transform\"",
")",
"self",
".",
"log",
"=",
"True",
"if",
"m",
"is",
"None",
":",
"m",
"=",
"self",
... | Log transforms the probabilities.
Removes values with probability 0.
Normalizes so that the largest logprob is 0. | [
"Log",
"transforms",
"the",
"probabilities",
".",
"Removes",
"values",
"with",
"probability",
"0",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L222-L240 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | _DictWrapper.Exp | def Exp(self, m=None):
"""Exponentiates the probabilities.
m: how much to shift the ps before exponentiating
If m is None, normalizes so that the largest prob is 1.
"""
if not self.log:
raise ValueError("Pmf/Hist not under a log transform")
self.log = False
... | python | def Exp(self, m=None):
"""Exponentiates the probabilities.
m: how much to shift the ps before exponentiating
If m is None, normalizes so that the largest prob is 1.
"""
if not self.log:
raise ValueError("Pmf/Hist not under a log transform")
self.log = False
... | [
"def",
"Exp",
"(",
"self",
",",
"m",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"log",
":",
"raise",
"ValueError",
"(",
"\"Pmf/Hist not under a log transform\"",
")",
"self",
".",
"log",
"=",
"False",
"if",
"m",
"is",
"None",
":",
"m",
"=",
"se... | Exponentiates the probabilities.
m: how much to shift the ps before exponentiating
If m is None, normalizes so that the largest prob is 1. | [
"Exponentiates",
"the",
"probabilities",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L242-L257 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | _DictWrapper.Print | def Print(self):
"""Prints the values and freqs/probs in ascending order."""
for val, prob in sorted(self.d.iteritems()):
print(val, prob) | python | def Print(self):
"""Prints the values and freqs/probs in ascending order."""
for val, prob in sorted(self.d.iteritems()):
print(val, prob) | [
"def",
"Print",
"(",
"self",
")",
":",
"for",
"val",
",",
"prob",
"in",
"sorted",
"(",
"self",
".",
"d",
".",
"iteritems",
"(",
")",
")",
":",
"print",
"(",
"val",
",",
"prob",
")"
] | Prints the values and freqs/probs in ascending order. | [
"Prints",
"the",
"values",
"and",
"freqs",
"/",
"probs",
"in",
"ascending",
"order",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L288-L291 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | _DictWrapper.Incr | def Incr(self, x, term=1):
"""Increments the freq/prob associated with the value x.
Args:
x: number value
term: how much to increment by
"""
self.d[x] = self.d.get(x, 0) + term | python | def Incr(self, x, term=1):
"""Increments the freq/prob associated with the value x.
Args:
x: number value
term: how much to increment by
"""
self.d[x] = self.d.get(x, 0) + term | [
"def",
"Incr",
"(",
"self",
",",
"x",
",",
"term",
"=",
"1",
")",
":",
"self",
".",
"d",
"[",
"x",
"]",
"=",
"self",
".",
"d",
".",
"get",
"(",
"x",
",",
"0",
")",
"+",
"term"
] | Increments the freq/prob associated with the value x.
Args:
x: number value
term: how much to increment by | [
"Increments",
"the",
"freq",
"/",
"prob",
"associated",
"with",
"the",
"value",
"x",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L302-L309 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | _DictWrapper.Mult | def Mult(self, x, factor):
"""Scales the freq/prob associated with the value x.
Args:
x: number value
factor: how much to multiply by
"""
self.d[x] = self.d.get(x, 0) * factor | python | def Mult(self, x, factor):
"""Scales the freq/prob associated with the value x.
Args:
x: number value
factor: how much to multiply by
"""
self.d[x] = self.d.get(x, 0) * factor | [
"def",
"Mult",
"(",
"self",
",",
"x",
",",
"factor",
")",
":",
"self",
".",
"d",
"[",
"x",
"]",
"=",
"self",
".",
"d",
".",
"get",
"(",
"x",
",",
"0",
")",
"*",
"factor"
] | Scales the freq/prob associated with the value x.
Args:
x: number value
factor: how much to multiply by | [
"Scales",
"the",
"freq",
"/",
"prob",
"associated",
"with",
"the",
"value",
"x",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L311-L318 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Hist.IsSubset | def IsSubset(self, other):
"""Checks whether the values in this histogram are a subset of
the values in the given histogram."""
for val, freq in self.Items():
if freq > other.Freq(val):
return False
return True | python | def IsSubset(self, other):
"""Checks whether the values in this histogram are a subset of
the values in the given histogram."""
for val, freq in self.Items():
if freq > other.Freq(val):
return False
return True | [
"def",
"IsSubset",
"(",
"self",
",",
"other",
")",
":",
"for",
"val",
",",
"freq",
"in",
"self",
".",
"Items",
"(",
")",
":",
"if",
"freq",
">",
"other",
".",
"Freq",
"(",
"val",
")",
":",
"return",
"False",
"return",
"True"
] | Checks whether the values in this histogram are a subset of
the values in the given histogram. | [
"Checks",
"whether",
"the",
"values",
"in",
"this",
"histogram",
"are",
"a",
"subset",
"of",
"the",
"values",
"in",
"the",
"given",
"histogram",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L361-L367 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Hist.Subtract | def Subtract(self, other):
"""Subtracts the values in the given histogram from this histogram."""
for val, freq in other.Items():
self.Incr(val, -freq) | python | def Subtract(self, other):
"""Subtracts the values in the given histogram from this histogram."""
for val, freq in other.Items():
self.Incr(val, -freq) | [
"def",
"Subtract",
"(",
"self",
",",
"other",
")",
":",
"for",
"val",
",",
"freq",
"in",
"other",
".",
"Items",
"(",
")",
":",
"self",
".",
"Incr",
"(",
"val",
",",
"-",
"freq",
")"
] | Subtracts the values in the given histogram from this histogram. | [
"Subtracts",
"the",
"values",
"in",
"the",
"given",
"histogram",
"from",
"this",
"histogram",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L369-L372 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Pmf.ProbGreater | def ProbGreater(self, x):
"""Probability that a sample from this Pmf exceeds x.
x: number
returns: float probability
"""
t = [prob for (val, prob) in self.d.iteritems() if val > x]
return sum(t) | python | def ProbGreater(self, x):
"""Probability that a sample from this Pmf exceeds x.
x: number
returns: float probability
"""
t = [prob for (val, prob) in self.d.iteritems() if val > x]
return sum(t) | [
"def",
"ProbGreater",
"(",
"self",
",",
"x",
")",
":",
"t",
"=",
"[",
"prob",
"for",
"(",
"val",
",",
"prob",
")",
"in",
"self",
".",
"d",
".",
"iteritems",
"(",
")",
"if",
"val",
">",
"x",
"]",
"return",
"sum",
"(",
"t",
")"
] | Probability that a sample from this Pmf exceeds x.
x: number
returns: float probability | [
"Probability",
"that",
"a",
"sample",
"from",
"this",
"Pmf",
"exceeds",
"x",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L402-L410 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Pmf.Normalize | def Normalize(self, fraction=1.0):
"""Normalizes this PMF so the sum of all probs is fraction.
Args:
fraction: what the total should be after normalization
Returns: the total probability before normalizing
"""
if self.log:
raise ValueError("Pmf is under ... | python | def Normalize(self, fraction=1.0):
"""Normalizes this PMF so the sum of all probs is fraction.
Args:
fraction: what the total should be after normalization
Returns: the total probability before normalizing
"""
if self.log:
raise ValueError("Pmf is under ... | [
"def",
"Normalize",
"(",
"self",
",",
"fraction",
"=",
"1.0",
")",
":",
"if",
"self",
".",
"log",
":",
"raise",
"ValueError",
"(",
"\"Pmf is under a log transform\"",
")",
"total",
"=",
"self",
".",
"Total",
"(",
")",
"if",
"total",
"==",
"0.0",
":",
"... | Normalizes this PMF so the sum of all probs is fraction.
Args:
fraction: what the total should be after normalization
Returns: the total probability before normalizing | [
"Normalizes",
"this",
"PMF",
"so",
"the",
"sum",
"of",
"all",
"probs",
"is",
"fraction",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L485-L506 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Pmf.Random | def Random(self):
"""Chooses a random element from this PMF.
Returns:
float value from the Pmf
"""
if len(self.d) == 0:
raise ValueError('Pmf contains no values.')
target = random.random()
total = 0.0
for x, p in self.d.iteritems():
... | python | def Random(self):
"""Chooses a random element from this PMF.
Returns:
float value from the Pmf
"""
if len(self.d) == 0:
raise ValueError('Pmf contains no values.')
target = random.random()
total = 0.0
for x, p in self.d.iteritems():
... | [
"def",
"Random",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"d",
")",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"'Pmf contains no values.'",
")",
"target",
"=",
"random",
".",
"random",
"(",
")",
"total",
"=",
"0.0",
"for",
"x",
",",
"... | Chooses a random element from this PMF.
Returns:
float value from the Pmf | [
"Chooses",
"a",
"random",
"element",
"from",
"this",
"PMF",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L508-L525 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Pmf.Mean | def Mean(self):
"""Computes the mean of a PMF.
Returns:
float mean
"""
mu = 0.0
for x, p in self.d.iteritems():
mu += p * x
return mu | python | def Mean(self):
"""Computes the mean of a PMF.
Returns:
float mean
"""
mu = 0.0
for x, p in self.d.iteritems():
mu += p * x
return mu | [
"def",
"Mean",
"(",
"self",
")",
":",
"mu",
"=",
"0.0",
"for",
"x",
",",
"p",
"in",
"self",
".",
"d",
".",
"iteritems",
"(",
")",
":",
"mu",
"+=",
"p",
"*",
"x",
"return",
"mu"
] | Computes the mean of a PMF.
Returns:
float mean | [
"Computes",
"the",
"mean",
"of",
"a",
"PMF",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L527-L536 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Pmf.Var | def Var(self, mu=None):
"""Computes the variance of a PMF.
Args:
mu: the point around which the variance is computed;
if omitted, computes the mean
Returns:
float variance
"""
if mu is None:
mu = self.Mean()
var = 0.0... | python | def Var(self, mu=None):
"""Computes the variance of a PMF.
Args:
mu: the point around which the variance is computed;
if omitted, computes the mean
Returns:
float variance
"""
if mu is None:
mu = self.Mean()
var = 0.0... | [
"def",
"Var",
"(",
"self",
",",
"mu",
"=",
"None",
")",
":",
"if",
"mu",
"is",
"None",
":",
"mu",
"=",
"self",
".",
"Mean",
"(",
")",
"var",
"=",
"0.0",
"for",
"x",
",",
"p",
"in",
"self",
".",
"d",
".",
"iteritems",
"(",
")",
":",
"var",
... | Computes the variance of a PMF.
Args:
mu: the point around which the variance is computed;
if omitted, computes the mean
Returns:
float variance | [
"Computes",
"the",
"variance",
"of",
"a",
"PMF",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L538-L554 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Pmf.MaximumLikelihood | def MaximumLikelihood(self):
"""Returns the value with the highest probability.
Returns: float probability
"""
prob, val = max((prob, val) for val, prob in self.Items())
return val | python | def MaximumLikelihood(self):
"""Returns the value with the highest probability.
Returns: float probability
"""
prob, val = max((prob, val) for val, prob in self.Items())
return val | [
"def",
"MaximumLikelihood",
"(",
"self",
")",
":",
"prob",
",",
"val",
"=",
"max",
"(",
"(",
"prob",
",",
"val",
")",
"for",
"val",
",",
"prob",
"in",
"self",
".",
"Items",
"(",
")",
")",
"return",
"val"
] | Returns the value with the highest probability.
Returns: float probability | [
"Returns",
"the",
"value",
"with",
"the",
"highest",
"probability",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L556-L562 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Pmf.AddPmf | def AddPmf(self, other):
"""Computes the Pmf of the sum of values drawn from self and other.
other: another Pmf
returns: new Pmf
"""
pmf = Pmf()
for v1, p1 in self.Items():
for v2, p2 in other.Items():
pmf.Incr(v1 + v2, p1 * p2)
retur... | python | def AddPmf(self, other):
"""Computes the Pmf of the sum of values drawn from self and other.
other: another Pmf
returns: new Pmf
"""
pmf = Pmf()
for v1, p1 in self.Items():
for v2, p2 in other.Items():
pmf.Incr(v1 + v2, p1 * p2)
retur... | [
"def",
"AddPmf",
"(",
"self",
",",
"other",
")",
":",
"pmf",
"=",
"Pmf",
"(",
")",
"for",
"v1",
",",
"p1",
"in",
"self",
".",
"Items",
"(",
")",
":",
"for",
"v2",
",",
"p2",
"in",
"other",
".",
"Items",
"(",
")",
":",
"pmf",
".",
"Incr",
"(... | Computes the Pmf of the sum of values drawn from self and other.
other: another Pmf
returns: new Pmf | [
"Computes",
"the",
"Pmf",
"of",
"the",
"sum",
"of",
"values",
"drawn",
"from",
"self",
"and",
"other",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L590-L601 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Pmf.AddConstant | def AddConstant(self, other):
"""Computes the Pmf of the sum a constant and values from self.
other: a number
returns: new Pmf
"""
pmf = Pmf()
for v1, p1 in self.Items():
pmf.Set(v1 + other, p1)
return pmf | python | def AddConstant(self, other):
"""Computes the Pmf of the sum a constant and values from self.
other: a number
returns: new Pmf
"""
pmf = Pmf()
for v1, p1 in self.Items():
pmf.Set(v1 + other, p1)
return pmf | [
"def",
"AddConstant",
"(",
"self",
",",
"other",
")",
":",
"pmf",
"=",
"Pmf",
"(",
")",
"for",
"v1",
",",
"p1",
"in",
"self",
".",
"Items",
"(",
")",
":",
"pmf",
".",
"Set",
"(",
"v1",
"+",
"other",
",",
"p1",
")",
"return",
"pmf"
] | Computes the Pmf of the sum a constant and values from self.
other: a number
returns: new Pmf | [
"Computes",
"the",
"Pmf",
"of",
"the",
"sum",
"a",
"constant",
"and",
"values",
"from",
"self",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L603-L613 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Pmf.Max | def Max(self, k):
"""Computes the CDF of the maximum of k selections from this dist.
k: int
returns: new Cdf
"""
cdf = self.MakeCdf()
cdf.ps = [p ** k for p in cdf.ps]
return cdf | python | def Max(self, k):
"""Computes the CDF of the maximum of k selections from this dist.
k: int
returns: new Cdf
"""
cdf = self.MakeCdf()
cdf.ps = [p ** k for p in cdf.ps]
return cdf | [
"def",
"Max",
"(",
"self",
",",
"k",
")",
":",
"cdf",
"=",
"self",
".",
"MakeCdf",
"(",
")",
"cdf",
".",
"ps",
"=",
"[",
"p",
"**",
"k",
"for",
"p",
"in",
"cdf",
".",
"ps",
"]",
"return",
"cdf"
] | Computes the CDF of the maximum of k selections from this dist.
k: int
returns: new Cdf | [
"Computes",
"the",
"CDF",
"of",
"the",
"maximum",
"of",
"k",
"selections",
"from",
"this",
"dist",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L628-L637 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Joint.Marginal | def Marginal(self, i, name=''):
"""Gets the marginal distribution of the indicated variable.
i: index of the variable we want
Returns: Pmf
"""
pmf = Pmf(name=name)
for vs, prob in self.Items():
pmf.Incr(vs[i], prob)
return pmf | python | def Marginal(self, i, name=''):
"""Gets the marginal distribution of the indicated variable.
i: index of the variable we want
Returns: Pmf
"""
pmf = Pmf(name=name)
for vs, prob in self.Items():
pmf.Incr(vs[i], prob)
return pmf | [
"def",
"Marginal",
"(",
"self",
",",
"i",
",",
"name",
"=",
"''",
")",
":",
"pmf",
"=",
"Pmf",
"(",
"name",
"=",
"name",
")",
"for",
"vs",
",",
"prob",
"in",
"self",
".",
"Items",
"(",
")",
":",
"pmf",
".",
"Incr",
"(",
"vs",
"[",
"i",
"]",... | Gets the marginal distribution of the indicated variable.
i: index of the variable we want
Returns: Pmf | [
"Gets",
"the",
"marginal",
"distribution",
"of",
"the",
"indicated",
"variable",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L646-L656 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Joint.Conditional | def Conditional(self, i, j, val, name=''):
"""Gets the conditional distribution of the indicated variable.
Distribution of vs[i], conditioned on vs[j] = val.
i: index of the variable we want
j: which variable is conditioned on
val: the value the jth variable has to have
... | python | def Conditional(self, i, j, val, name=''):
"""Gets the conditional distribution of the indicated variable.
Distribution of vs[i], conditioned on vs[j] = val.
i: index of the variable we want
j: which variable is conditioned on
val: the value the jth variable has to have
... | [
"def",
"Conditional",
"(",
"self",
",",
"i",
",",
"j",
",",
"val",
",",
"name",
"=",
"''",
")",
":",
"pmf",
"=",
"Pmf",
"(",
"name",
"=",
"name",
")",
"for",
"vs",
",",
"prob",
"in",
"self",
".",
"Items",
"(",
")",
":",
"if",
"vs",
"[",
"j"... | Gets the conditional distribution of the indicated variable.
Distribution of vs[i], conditioned on vs[j] = val.
i: index of the variable we want
j: which variable is conditioned on
val: the value the jth variable has to have
Returns: Pmf | [
"Gets",
"the",
"conditional",
"distribution",
"of",
"the",
"indicated",
"variable",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L658-L675 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Joint.MaxLikeInterval | def MaxLikeInterval(self, percentage=90):
"""Returns the maximum-likelihood credible interval.
If percentage=90, computes a 90% CI containing the values
with the highest likelihoods.
percentage: float between 0 and 100
Returns: list of values from the suite
"""
... | python | def MaxLikeInterval(self, percentage=90):
"""Returns the maximum-likelihood credible interval.
If percentage=90, computes a 90% CI containing the values
with the highest likelihoods.
percentage: float between 0 and 100
Returns: list of values from the suite
"""
... | [
"def",
"MaxLikeInterval",
"(",
"self",
",",
"percentage",
"=",
"90",
")",
":",
"interval",
"=",
"[",
"]",
"total",
"=",
"0",
"t",
"=",
"[",
"(",
"prob",
",",
"val",
")",
"for",
"val",
",",
"prob",
"in",
"self",
".",
"Items",
"(",
")",
"]",
"t",... | Returns the maximum-likelihood credible interval.
If percentage=90, computes a 90% CI containing the values
with the highest likelihoods.
percentage: float between 0 and 100
Returns: list of values from the suite | [
"Returns",
"the",
"maximum",
"-",
"likelihood",
"credible",
"interval",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L677-L699 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Cdf.Copy | def Copy(self, name=None):
"""Returns a copy of this Cdf.
Args:
name: string name for the new Cdf
"""
if name is None:
name = self.name
return Cdf(list(self.xs), list(self.ps), name) | python | def Copy(self, name=None):
"""Returns a copy of this Cdf.
Args:
name: string name for the new Cdf
"""
if name is None:
name = self.name
return Cdf(list(self.xs), list(self.ps), name) | [
"def",
"Copy",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"name",
"return",
"Cdf",
"(",
"list",
"(",
"self",
".",
"xs",
")",
",",
"list",
"(",
"self",
".",
"ps",
")",
",",
"name... | Returns a copy of this Cdf.
Args:
name: string name for the new Cdf | [
"Returns",
"a",
"copy",
"of",
"this",
"Cdf",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L881-L889 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Cdf.Append | def Append(self, x, p):
"""Add an (x, p) pair to the end of this CDF.
Note: this us normally used to build a CDF from scratch, not
to modify existing CDFs. It is up to the caller to make sure
that the result is a legal CDF.
"""
self.xs.append(x)
self.ps.append(p... | python | def Append(self, x, p):
"""Add an (x, p) pair to the end of this CDF.
Note: this us normally used to build a CDF from scratch, not
to modify existing CDFs. It is up to the caller to make sure
that the result is a legal CDF.
"""
self.xs.append(x)
self.ps.append(p... | [
"def",
"Append",
"(",
"self",
",",
"x",
",",
"p",
")",
":",
"self",
".",
"xs",
".",
"append",
"(",
"x",
")",
"self",
".",
"ps",
".",
"append",
"(",
"p",
")"
] | Add an (x, p) pair to the end of this CDF.
Note: this us normally used to build a CDF from scratch, not
to modify existing CDFs. It is up to the caller to make sure
that the result is a legal CDF. | [
"Add",
"an",
"(",
"x",
"p",
")",
"pair",
"to",
"the",
"end",
"of",
"this",
"CDF",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L907-L915 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Cdf.Shift | def Shift(self, term):
"""Adds a term to the xs.
term: how much to add
"""
new = self.Copy()
new.xs = [x + term for x in self.xs]
return new | python | def Shift(self, term):
"""Adds a term to the xs.
term: how much to add
"""
new = self.Copy()
new.xs = [x + term for x in self.xs]
return new | [
"def",
"Shift",
"(",
"self",
",",
"term",
")",
":",
"new",
"=",
"self",
".",
"Copy",
"(",
")",
"new",
".",
"xs",
"=",
"[",
"x",
"+",
"term",
"for",
"x",
"in",
"self",
".",
"xs",
"]",
"return",
"new"
] | Adds a term to the xs.
term: how much to add | [
"Adds",
"a",
"term",
"to",
"the",
"xs",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L917-L924 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Cdf.Scale | def Scale(self, factor):
"""Multiplies the xs by a factor.
factor: what to multiply by
"""
new = self.Copy()
new.xs = [x * factor for x in self.xs]
return new | python | def Scale(self, factor):
"""Multiplies the xs by a factor.
factor: what to multiply by
"""
new = self.Copy()
new.xs = [x * factor for x in self.xs]
return new | [
"def",
"Scale",
"(",
"self",
",",
"factor",
")",
":",
"new",
"=",
"self",
".",
"Copy",
"(",
")",
"new",
".",
"xs",
"=",
"[",
"x",
"*",
"factor",
"for",
"x",
"in",
"self",
".",
"xs",
"]",
"return",
"new"
] | Multiplies the xs by a factor.
factor: what to multiply by | [
"Multiplies",
"the",
"xs",
"by",
"a",
"factor",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L926-L933 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Cdf.Prob | def Prob(self, x):
"""Returns CDF(x), the probability that corresponds to value x.
Args:
x: number
Returns:
float probability
"""
if x < self.xs[0]: return 0.0
index = bisect.bisect(self.xs, x)
p = self.ps[index - 1]
return p | python | def Prob(self, x):
"""Returns CDF(x), the probability that corresponds to value x.
Args:
x: number
Returns:
float probability
"""
if x < self.xs[0]: return 0.0
index = bisect.bisect(self.xs, x)
p = self.ps[index - 1]
return p | [
"def",
"Prob",
"(",
"self",
",",
"x",
")",
":",
"if",
"x",
"<",
"self",
".",
"xs",
"[",
"0",
"]",
":",
"return",
"0.0",
"index",
"=",
"bisect",
".",
"bisect",
"(",
"self",
".",
"xs",
",",
"x",
")",
"p",
"=",
"self",
".",
"ps",
"[",
"index",... | Returns CDF(x), the probability that corresponds to value x.
Args:
x: number
Returns:
float probability | [
"Returns",
"CDF",
"(",
"x",
")",
"the",
"probability",
"that",
"corresponds",
"to",
"value",
"x",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L935-L947 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Cdf.Value | def Value(self, p):
"""Returns InverseCDF(p), the value that corresponds to probability p.
Args:
p: number in the range [0, 1]
Returns:
number value
"""
if p < 0 or p > 1:
raise ValueError('Probability p must be in range [0, 1]')
if ... | python | def Value(self, p):
"""Returns InverseCDF(p), the value that corresponds to probability p.
Args:
p: number in the range [0, 1]
Returns:
number value
"""
if p < 0 or p > 1:
raise ValueError('Probability p must be in range [0, 1]')
if ... | [
"def",
"Value",
"(",
"self",
",",
"p",
")",
":",
"if",
"p",
"<",
"0",
"or",
"p",
">",
"1",
":",
"raise",
"ValueError",
"(",
"'Probability p must be in range [0, 1]'",
")",
"if",
"p",
"==",
"0",
":",
"return",
"self",
".",
"xs",
"[",
"0",
"]",
"if",... | Returns InverseCDF(p), the value that corresponds to probability p.
Args:
p: number in the range [0, 1]
Returns:
number value | [
"Returns",
"InverseCDF",
"(",
"p",
")",
"the",
"value",
"that",
"corresponds",
"to",
"probability",
"p",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L949-L967 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Cdf.Mean | def Mean(self):
"""Computes the mean of a CDF.
Returns:
float mean
"""
old_p = 0
total = 0.0
for x, new_p in zip(self.xs, self.ps):
p = new_p - old_p
total += p * x
old_p = new_p
return total | python | def Mean(self):
"""Computes the mean of a CDF.
Returns:
float mean
"""
old_p = 0
total = 0.0
for x, new_p in zip(self.xs, self.ps):
p = new_p - old_p
total += p * x
old_p = new_p
return total | [
"def",
"Mean",
"(",
"self",
")",
":",
"old_p",
"=",
"0",
"total",
"=",
"0.0",
"for",
"x",
",",
"new_p",
"in",
"zip",
"(",
"self",
".",
"xs",
",",
"self",
".",
"ps",
")",
":",
"p",
"=",
"new_p",
"-",
"old_p",
"total",
"+=",
"p",
"*",
"x",
"o... | Computes the mean of a CDF.
Returns:
float mean | [
"Computes",
"the",
"mean",
"of",
"a",
"CDF",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L992-L1004 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Cdf.CredibleInterval | def CredibleInterval(self, percentage=90):
"""Computes the central credible interval.
If percentage=90, computes the 90% CI.
Args:
percentage: float between 0 and 100
Returns:
sequence of two floats, low and high
"""
prob = (1 - percentage / 100... | python | def CredibleInterval(self, percentage=90):
"""Computes the central credible interval.
If percentage=90, computes the 90% CI.
Args:
percentage: float between 0 and 100
Returns:
sequence of two floats, low and high
"""
prob = (1 - percentage / 100... | [
"def",
"CredibleInterval",
"(",
"self",
",",
"percentage",
"=",
"90",
")",
":",
"prob",
"=",
"(",
"1",
"-",
"percentage",
"/",
"100.0",
")",
"/",
"2",
"interval",
"=",
"self",
".",
"Value",
"(",
"prob",
")",
",",
"self",
".",
"Value",
"(",
"1",
"... | Computes the central credible interval.
If percentage=90, computes the 90% CI.
Args:
percentage: float between 0 and 100
Returns:
sequence of two floats, low and high | [
"Computes",
"the",
"central",
"credible",
"interval",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1006-L1019 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Cdf.Render | def Render(self):
"""Generates a sequence of points suitable for plotting.
An empirical CDF is a step function; linear interpolation
can be misleading.
Returns:
tuple of (xs, ps)
"""
xs = [self.xs[0]]
ps = [0.0]
for i, p in enumerate(self.ps)... | python | def Render(self):
"""Generates a sequence of points suitable for plotting.
An empirical CDF is a step function; linear interpolation
can be misleading.
Returns:
tuple of (xs, ps)
"""
xs = [self.xs[0]]
ps = [0.0]
for i, p in enumerate(self.ps)... | [
"def",
"Render",
"(",
"self",
")",
":",
"xs",
"=",
"[",
"self",
".",
"xs",
"[",
"0",
"]",
"]",
"ps",
"=",
"[",
"0.0",
"]",
"for",
"i",
",",
"p",
"in",
"enumerate",
"(",
"self",
".",
"ps",
")",
":",
"xs",
".",
"append",
"(",
"self",
".",
"... | Generates a sequence of points suitable for plotting.
An empirical CDF is a step function; linear interpolation
can be misleading.
Returns:
tuple of (xs, ps) | [
"Generates",
"a",
"sequence",
"of",
"points",
"suitable",
"for",
"plotting",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1031-L1051 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Cdf.Max | def Max(self, k):
"""Computes the CDF of the maximum of k selections from this dist.
k: int
returns: new Cdf
"""
cdf = self.Copy()
cdf.ps = [p ** k for p in cdf.ps]
return cdf | python | def Max(self, k):
"""Computes the CDF of the maximum of k selections from this dist.
k: int
returns: new Cdf
"""
cdf = self.Copy()
cdf.ps = [p ** k for p in cdf.ps]
return cdf | [
"def",
"Max",
"(",
"self",
",",
"k",
")",
":",
"cdf",
"=",
"self",
".",
"Copy",
"(",
")",
"cdf",
".",
"ps",
"=",
"[",
"p",
"**",
"k",
"for",
"p",
"in",
"cdf",
".",
"ps",
"]",
"return",
"cdf"
] | Computes the CDF of the maximum of k selections from this dist.
k: int
returns: new Cdf | [
"Computes",
"the",
"CDF",
"of",
"the",
"maximum",
"of",
"k",
"selections",
"from",
"this",
"dist",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1053-L1062 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Suite.LogUpdate | def LogUpdate(self, data):
"""Updates a suite of hypotheses based on new data.
Modifies the suite directly; if you want to keep the original, make
a copy.
Note: unlike Update, LogUpdate does not normalize.
Args:
data: any representation of the data
"""
... | python | def LogUpdate(self, data):
"""Updates a suite of hypotheses based on new data.
Modifies the suite directly; if you want to keep the original, make
a copy.
Note: unlike Update, LogUpdate does not normalize.
Args:
data: any representation of the data
"""
... | [
"def",
"LogUpdate",
"(",
"self",
",",
"data",
")",
":",
"for",
"hypo",
"in",
"self",
".",
"Values",
"(",
")",
":",
"like",
"=",
"self",
".",
"LogLikelihood",
"(",
"data",
",",
"hypo",
")",
"self",
".",
"Incr",
"(",
"hypo",
",",
"like",
")"
] | Updates a suite of hypotheses based on new data.
Modifies the suite directly; if you want to keep the original, make
a copy.
Note: unlike Update, LogUpdate does not normalize.
Args:
data: any representation of the data | [
"Updates",
"a",
"suite",
"of",
"hypotheses",
"based",
"on",
"new",
"data",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1165-L1178 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Suite.UpdateSet | def UpdateSet(self, dataset):
"""Updates each hypothesis based on the dataset.
This is more efficient than calling Update repeatedly because
it waits until the end to Normalize.
Modifies the suite directly; if you want to keep the original, make
a copy.
dataset: a sequ... | python | def UpdateSet(self, dataset):
"""Updates each hypothesis based on the dataset.
This is more efficient than calling Update repeatedly because
it waits until the end to Normalize.
Modifies the suite directly; if you want to keep the original, make
a copy.
dataset: a sequ... | [
"def",
"UpdateSet",
"(",
"self",
",",
"dataset",
")",
":",
"for",
"data",
"in",
"dataset",
":",
"for",
"hypo",
"in",
"self",
".",
"Values",
"(",
")",
":",
"like",
"=",
"self",
".",
"Likelihood",
"(",
"data",
",",
"hypo",
")",
"self",
".",
"Mult",
... | Updates each hypothesis based on the dataset.
This is more efficient than calling Update repeatedly because
it waits until the end to Normalize.
Modifies the suite directly; if you want to keep the original, make
a copy.
dataset: a sequence of data
returns: the normal... | [
"Updates",
"each",
"hypothesis",
"based",
"on",
"the",
"dataset",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1180-L1197 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Suite.Print | def Print(self):
"""Prints the hypotheses and their probabilities."""
for hypo, prob in sorted(self.Items()):
print(hypo, prob) | python | def Print(self):
"""Prints the hypotheses and their probabilities."""
for hypo, prob in sorted(self.Items()):
print(hypo, prob) | [
"def",
"Print",
"(",
"self",
")",
":",
"for",
"hypo",
",",
"prob",
"in",
"sorted",
"(",
"self",
".",
"Items",
"(",
")",
")",
":",
"print",
"(",
"hypo",
",",
"prob",
")"
] | Prints the hypotheses and their probabilities. | [
"Prints",
"the",
"hypotheses",
"and",
"their",
"probabilities",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1228-L1231 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Suite.MakeOdds | def MakeOdds(self):
"""Transforms from probabilities to odds.
Values with prob=0 are removed.
"""
for hypo, prob in self.Items():
if prob:
self.Set(hypo, Odds(prob))
else:
self.Remove(hypo) | python | def MakeOdds(self):
"""Transforms from probabilities to odds.
Values with prob=0 are removed.
"""
for hypo, prob in self.Items():
if prob:
self.Set(hypo, Odds(prob))
else:
self.Remove(hypo) | [
"def",
"MakeOdds",
"(",
"self",
")",
":",
"for",
"hypo",
",",
"prob",
"in",
"self",
".",
"Items",
"(",
")",
":",
"if",
"prob",
":",
"self",
".",
"Set",
"(",
"hypo",
",",
"Odds",
"(",
"prob",
")",
")",
"else",
":",
"self",
".",
"Remove",
"(",
... | Transforms from probabilities to odds.
Values with prob=0 are removed. | [
"Transforms",
"from",
"probabilities",
"to",
"odds",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1233-L1242 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Suite.MakeProbs | def MakeProbs(self):
"""Transforms from odds to probabilities."""
for hypo, odds in self.Items():
self.Set(hypo, Probability(odds)) | python | def MakeProbs(self):
"""Transforms from odds to probabilities."""
for hypo, odds in self.Items():
self.Set(hypo, Probability(odds)) | [
"def",
"MakeProbs",
"(",
"self",
")",
":",
"for",
"hypo",
",",
"odds",
"in",
"self",
".",
"Items",
"(",
")",
":",
"self",
".",
"Set",
"(",
"hypo",
",",
"Probability",
"(",
"odds",
")",
")"
] | Transforms from odds to probabilities. | [
"Transforms",
"from",
"odds",
"to",
"probabilities",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1244-L1247 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Pdf.MakePmf | def MakePmf(self, xs, name=''):
"""Makes a discrete version of this Pdf, evaluated at xs.
xs: equally-spaced sequence of values
Returns: new Pmf
"""
pmf = Pmf(name=name)
for x in xs:
pmf.Set(x, self.Density(x))
pmf.Normalize()
return pmf | python | def MakePmf(self, xs, name=''):
"""Makes a discrete version of this Pdf, evaluated at xs.
xs: equally-spaced sequence of values
Returns: new Pmf
"""
pmf = Pmf(name=name)
for x in xs:
pmf.Set(x, self.Density(x))
pmf.Normalize()
return pmf | [
"def",
"MakePmf",
"(",
"self",
",",
"xs",
",",
"name",
"=",
"''",
")",
":",
"pmf",
"=",
"Pmf",
"(",
"name",
"=",
"name",
")",
"for",
"x",
"in",
"xs",
":",
"pmf",
".",
"Set",
"(",
"x",
",",
"self",
".",
"Density",
"(",
"x",
")",
")",
"pmf",
... | Makes a discrete version of this Pdf, evaluated at xs.
xs: equally-spaced sequence of values
Returns: new Pmf | [
"Makes",
"a",
"discrete",
"version",
"of",
"this",
"Pdf",
"evaluated",
"at",
"xs",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1332-L1343 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Beta.Update | def Update(self, data):
"""Updates a Beta distribution.
data: pair of int (heads, tails)
"""
heads, tails = data
self.alpha += heads
self.beta += tails | python | def Update(self, data):
"""Updates a Beta distribution.
data: pair of int (heads, tails)
"""
heads, tails = data
self.alpha += heads
self.beta += tails | [
"def",
"Update",
"(",
"self",
",",
"data",
")",
":",
"heads",
",",
"tails",
"=",
"data",
"self",
".",
"alpha",
"+=",
"heads",
"self",
".",
"beta",
"+=",
"tails"
] | Updates a Beta distribution.
data: pair of int (heads, tails) | [
"Updates",
"a",
"Beta",
"distribution",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1663-L1670 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Beta.Sample | def Sample(self, n):
"""Generates a random sample from this distribution.
n: int sample size
"""
size = n,
return numpy.random.beta(self.alpha, self.beta, size) | python | def Sample(self, n):
"""Generates a random sample from this distribution.
n: int sample size
"""
size = n,
return numpy.random.beta(self.alpha, self.beta, size) | [
"def",
"Sample",
"(",
"self",
",",
"n",
")",
":",
"size",
"=",
"n",
",",
"return",
"numpy",
".",
"random",
".",
"beta",
"(",
"self",
".",
"alpha",
",",
"self",
".",
"beta",
",",
"size",
")"
] | Generates a random sample from this distribution.
n: int sample size | [
"Generates",
"a",
"random",
"sample",
"from",
"this",
"distribution",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1680-L1686 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Beta.MakePmf | def MakePmf(self, steps=101, name=''):
"""Returns a Pmf of this distribution.
Note: Normally, we just evaluate the PDF at a sequence
of points and treat the probability density as a probability
mass.
But if alpha or beta is less than one, we have to be
more careful beca... | python | def MakePmf(self, steps=101, name=''):
"""Returns a Pmf of this distribution.
Note: Normally, we just evaluate the PDF at a sequence
of points and treat the probability density as a probability
mass.
But if alpha or beta is less than one, we have to be
more careful beca... | [
"def",
"MakePmf",
"(",
"self",
",",
"steps",
"=",
"101",
",",
"name",
"=",
"''",
")",
":",
"if",
"self",
".",
"alpha",
"<",
"1",
"or",
"self",
".",
"beta",
"<",
"1",
":",
"cdf",
"=",
"self",
".",
"MakeCdf",
"(",
")",
"pmf",
"=",
"cdf",
".",
... | Returns a Pmf of this distribution.
Note: Normally, we just evaluate the PDF at a sequence
of points and treat the probability density as a probability
mass.
But if alpha or beta is less than one, we have to be
more careful because the PDF goes to infinity at x=0
and x=... | [
"Returns",
"a",
"Pmf",
"of",
"this",
"distribution",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1692-L1712 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Beta.MakeCdf | def MakeCdf(self, steps=101):
"""Returns the CDF of this distribution."""
xs = [i / (steps - 1.0) for i in xrange(steps)]
ps = [scipy.special.betainc(self.alpha, self.beta, x) for x in xs]
cdf = Cdf(xs, ps)
return cdf | python | def MakeCdf(self, steps=101):
"""Returns the CDF of this distribution."""
xs = [i / (steps - 1.0) for i in xrange(steps)]
ps = [scipy.special.betainc(self.alpha, self.beta, x) for x in xs]
cdf = Cdf(xs, ps)
return cdf | [
"def",
"MakeCdf",
"(",
"self",
",",
"steps",
"=",
"101",
")",
":",
"xs",
"=",
"[",
"i",
"/",
"(",
"steps",
"-",
"1.0",
")",
"for",
"i",
"in",
"xrange",
"(",
"steps",
")",
"]",
"ps",
"=",
"[",
"scipy",
".",
"special",
".",
"betainc",
"(",
"sel... | Returns the CDF of this distribution. | [
"Returns",
"the",
"CDF",
"of",
"this",
"distribution",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1714-L1719 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Dirichlet.Update | def Update(self, data):
"""Updates a Dirichlet distribution.
data: sequence of observations, in order corresponding to params
"""
m = len(data)
self.params[:m] += data | python | def Update(self, data):
"""Updates a Dirichlet distribution.
data: sequence of observations, in order corresponding to params
"""
m = len(data)
self.params[:m] += data | [
"def",
"Update",
"(",
"self",
",",
"data",
")",
":",
"m",
"=",
"len",
"(",
"data",
")",
"self",
".",
"params",
"[",
":",
"m",
"]",
"+=",
"data"
] | Updates a Dirichlet distribution.
data: sequence of observations, in order corresponding to params | [
"Updates",
"a",
"Dirichlet",
"distribution",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1743-L1749 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Dirichlet.Random | def Random(self):
"""Generates a random variate from this distribution.
Returns: normalized vector of fractions
"""
p = numpy.random.gamma(self.params)
return p / p.sum() | python | def Random(self):
"""Generates a random variate from this distribution.
Returns: normalized vector of fractions
"""
p = numpy.random.gamma(self.params)
return p / p.sum() | [
"def",
"Random",
"(",
"self",
")",
":",
"p",
"=",
"numpy",
".",
"random",
".",
"gamma",
"(",
"self",
".",
"params",
")",
"return",
"p",
"/",
"p",
".",
"sum",
"(",
")"
] | Generates a random variate from this distribution.
Returns: normalized vector of fractions | [
"Generates",
"a",
"random",
"variate",
"from",
"this",
"distribution",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1751-L1757 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Dirichlet.Likelihood | def Likelihood(self, data):
"""Computes the likelihood of the data.
Selects a random vector of probabilities from this distribution.
Returns: float probability
"""
m = len(data)
if self.n < m:
return 0
x = data
p = self.Random()
q = ... | python | def Likelihood(self, data):
"""Computes the likelihood of the data.
Selects a random vector of probabilities from this distribution.
Returns: float probability
"""
m = len(data)
if self.n < m:
return 0
x = data
p = self.Random()
q = ... | [
"def",
"Likelihood",
"(",
"self",
",",
"data",
")",
":",
"m",
"=",
"len",
"(",
"data",
")",
"if",
"self",
".",
"n",
"<",
"m",
":",
"return",
"0",
"x",
"=",
"data",
"p",
"=",
"self",
".",
"Random",
"(",
")",
"q",
"=",
"p",
"[",
":",
"m",
"... | Computes the likelihood of the data.
Selects a random vector of probabilities from this distribution.
Returns: float probability | [
"Computes",
"the",
"likelihood",
"of",
"the",
"data",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1759-L1773 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Dirichlet.LogLikelihood | def LogLikelihood(self, data):
"""Computes the log likelihood of the data.
Selects a random vector of probabilities from this distribution.
Returns: float log probability
"""
m = len(data)
if self.n < m:
return float('-inf')
x = self.Random()
... | python | def LogLikelihood(self, data):
"""Computes the log likelihood of the data.
Selects a random vector of probabilities from this distribution.
Returns: float log probability
"""
m = len(data)
if self.n < m:
return float('-inf')
x = self.Random()
... | [
"def",
"LogLikelihood",
"(",
"self",
",",
"data",
")",
":",
"m",
"=",
"len",
"(",
"data",
")",
"if",
"self",
".",
"n",
"<",
"m",
":",
"return",
"float",
"(",
"'-inf'",
")",
"x",
"=",
"self",
".",
"Random",
"(",
")",
"y",
"=",
"numpy",
".",
"l... | Computes the log likelihood of the data.
Selects a random vector of probabilities from this distribution.
Returns: float log probability | [
"Computes",
"the",
"log",
"likelihood",
"of",
"the",
"data",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1775-L1788 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Dirichlet.MarginalBeta | def MarginalBeta(self, i):
"""Computes the marginal distribution of the ith element.
See http://en.wikipedia.org/wiki/Dirichlet_distribution
#Marginal_distributions
i: int
Returns: Beta object
"""
alpha0 = self.params.sum()
alpha = self.params[i]
... | python | def MarginalBeta(self, i):
"""Computes the marginal distribution of the ith element.
See http://en.wikipedia.org/wiki/Dirichlet_distribution
#Marginal_distributions
i: int
Returns: Beta object
"""
alpha0 = self.params.sum()
alpha = self.params[i]
... | [
"def",
"MarginalBeta",
"(",
"self",
",",
"i",
")",
":",
"alpha0",
"=",
"self",
".",
"params",
".",
"sum",
"(",
")",
"alpha",
"=",
"self",
".",
"params",
"[",
"i",
"]",
"return",
"Beta",
"(",
"alpha",
",",
"alpha0",
"-",
"alpha",
")"
] | Computes the marginal distribution of the ith element.
See http://en.wikipedia.org/wiki/Dirichlet_distribution
#Marginal_distributions
i: int
Returns: Beta object | [
"Computes",
"the",
"marginal",
"distribution",
"of",
"the",
"ith",
"element",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1790-L1802 |
lpantano/seqcluster | seqcluster/libs/thinkbayes.py | Dirichlet.PredictivePmf | def PredictivePmf(self, xs, name=''):
"""Makes a predictive distribution.
xs: values to go into the Pmf
Returns: Pmf that maps from x to the mean prevalence of x
"""
alpha0 = self.params.sum()
ps = self.params / alpha0
return MakePmfFromItems(zip(xs, ps), name=n... | python | def PredictivePmf(self, xs, name=''):
"""Makes a predictive distribution.
xs: values to go into the Pmf
Returns: Pmf that maps from x to the mean prevalence of x
"""
alpha0 = self.params.sum()
ps = self.params / alpha0
return MakePmfFromItems(zip(xs, ps), name=n... | [
"def",
"PredictivePmf",
"(",
"self",
",",
"xs",
",",
"name",
"=",
"''",
")",
":",
"alpha0",
"=",
"self",
".",
"params",
".",
"sum",
"(",
")",
"ps",
"=",
"self",
".",
"params",
"/",
"alpha0",
"return",
"MakePmfFromItems",
"(",
"zip",
"(",
"xs",
",",... | Makes a predictive distribution.
xs: values to go into the Pmf
Returns: Pmf that maps from x to the mean prevalence of x | [
"Makes",
"a",
"predictive",
"distribution",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1804-L1813 |
lpantano/seqcluster | seqcluster/libs/report.py | _get_ann | def _get_ann(dbs, features):
"""
Gives format to annotation for html table output
"""
value = ""
for db, feature in zip(dbs, features):
value += db + ":" + feature
return value | python | def _get_ann(dbs, features):
"""
Gives format to annotation for html table output
"""
value = ""
for db, feature in zip(dbs, features):
value += db + ":" + feature
return value | [
"def",
"_get_ann",
"(",
"dbs",
",",
"features",
")",
":",
"value",
"=",
"\"\"",
"for",
"db",
",",
"feature",
"in",
"zip",
"(",
"dbs",
",",
"features",
")",
":",
"value",
"+=",
"db",
"+",
"\":\"",
"+",
"feature",
"return",
"value"
] | Gives format to annotation for html table output | [
"Gives",
"format",
"to",
"annotation",
"for",
"html",
"table",
"output"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/report.py#L21-L28 |
lpantano/seqcluster | seqcluster/libs/report.py | make_profile | def make_profile(data, out_dir, args):
"""
Make data report for each cluster
"""
safe_dirs(out_dir)
main_table = []
header = ['id', 'ann']
n = len(data[0])
bar = ProgressBar(maxval=n)
bar.start()
bar.update(0)
for itern, c in enumerate(data[0]):
bar.update(itern)
... | python | def make_profile(data, out_dir, args):
"""
Make data report for each cluster
"""
safe_dirs(out_dir)
main_table = []
header = ['id', 'ann']
n = len(data[0])
bar = ProgressBar(maxval=n)
bar.start()
bar.update(0)
for itern, c in enumerate(data[0]):
bar.update(itern)
... | [
"def",
"make_profile",
"(",
"data",
",",
"out_dir",
",",
"args",
")",
":",
"safe_dirs",
"(",
"out_dir",
")",
"main_table",
"=",
"[",
"]",
"header",
"=",
"[",
"'id'",
",",
"'ann'",
"]",
"n",
"=",
"len",
"(",
"data",
"[",
"0",
"]",
")",
"bar",
"=",... | Make data report for each cluster | [
"Make",
"data",
"report",
"for",
"each",
"cluster"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/report.py#L39-L61 |
lpantano/seqcluster | seqcluster/libs/report.py | _expand | def _expand(dat, counts, start, end):
"""
expand the same counts from start to end
"""
for pos in range(start, end):
for s in counts:
dat[s][pos] += counts[s]
return dat | python | def _expand(dat, counts, start, end):
"""
expand the same counts from start to end
"""
for pos in range(start, end):
for s in counts:
dat[s][pos] += counts[s]
return dat | [
"def",
"_expand",
"(",
"dat",
",",
"counts",
",",
"start",
",",
"end",
")",
":",
"for",
"pos",
"in",
"range",
"(",
"start",
",",
"end",
")",
":",
"for",
"s",
"in",
"counts",
":",
"dat",
"[",
"s",
"]",
"[",
"pos",
"]",
"+=",
"counts",
"[",
"s"... | expand the same counts from start to end | [
"expand",
"the",
"same",
"counts",
"from",
"start",
"to",
"end"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/report.py#L64-L71 |
lpantano/seqcluster | seqcluster/libs/report.py | _convert_to_df | def _convert_to_df(in_file, freq, raw_file):
"""
convert data frame into table with pandas
"""
dat = defaultdict(Counter)
if isinstance(in_file, (str, unicode)):
with open(in_file) as in_handle:
for line in in_handle:
cols = line.strip().split("\t")
... | python | def _convert_to_df(in_file, freq, raw_file):
"""
convert data frame into table with pandas
"""
dat = defaultdict(Counter)
if isinstance(in_file, (str, unicode)):
with open(in_file) as in_handle:
for line in in_handle:
cols = line.strip().split("\t")
... | [
"def",
"_convert_to_df",
"(",
"in_file",
",",
"freq",
",",
"raw_file",
")",
":",
"dat",
"=",
"defaultdict",
"(",
"Counter",
")",
"if",
"isinstance",
"(",
"in_file",
",",
"(",
"str",
",",
"unicode",
")",
")",
":",
"with",
"open",
"(",
"in_file",
")",
... | convert data frame into table with pandas | [
"convert",
"data",
"frame",
"into",
"table",
"with",
"pandas"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/report.py#L74-L97 |
lpantano/seqcluster | seqcluster/libs/report.py | _make | def _make(c):
"""
create html from template, adding figure,
annotation and sequences counts
"""
ann = defaultdict(list)
for pos in c['ann']:
for db in pos:
ann[db] += list(pos[db])
logger.debug(ann)
valid = [l for l in c['valid']]
ann_list = [", ".join(list(set(... | python | def _make(c):
"""
create html from template, adding figure,
annotation and sequences counts
"""
ann = defaultdict(list)
for pos in c['ann']:
for db in pos:
ann[db] += list(pos[db])
logger.debug(ann)
valid = [l for l in c['valid']]
ann_list = [", ".join(list(set(... | [
"def",
"_make",
"(",
"c",
")",
":",
"ann",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"pos",
"in",
"c",
"[",
"'ann'",
"]",
":",
"for",
"db",
"in",
"pos",
":",
"ann",
"[",
"db",
"]",
"+=",
"list",
"(",
"pos",
"[",
"db",
"]",
")",
"logger",
... | create html from template, adding figure,
annotation and sequences counts | [
"create",
"html",
"from",
"template",
"adding",
"figure",
"annotation",
"and",
"sequences",
"counts"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/report.py#L100-L115 |
lpantano/seqcluster | seqcluster/libs/report.py | _single_cluster | def _single_cluster(c, data, out_file, args):
"""
Map sequences on precursors and create
expression profile
"""
valid, ann = 0, 0
raw_file = None
freq = defaultdict()
[freq.update({s.keys()[0]: s.values()[0]}) for s in data[0][c]['freq']]
names = [s.keys()[0] for s in data[0][c]['seq... | python | def _single_cluster(c, data, out_file, args):
"""
Map sequences on precursors and create
expression profile
"""
valid, ann = 0, 0
raw_file = None
freq = defaultdict()
[freq.update({s.keys()[0]: s.values()[0]}) for s in data[0][c]['freq']]
names = [s.keys()[0] for s in data[0][c]['seq... | [
"def",
"_single_cluster",
"(",
"c",
",",
"data",
",",
"out_file",
",",
"args",
")",
":",
"valid",
",",
"ann",
"=",
"0",
",",
"0",
"raw_file",
"=",
"None",
"freq",
"=",
"defaultdict",
"(",
")",
"[",
"freq",
".",
"update",
"(",
"{",
"s",
".",
"keys... | Map sequences on precursors and create
expression profile | [
"Map",
"sequences",
"on",
"precursors",
"and",
"create",
"expression",
"profile"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/report.py#L118-L149 |
lpantano/seqcluster | seqcluster/methods/__init__.py | read_cluster | def read_cluster(data, id=1):
"""Read json cluster and populate as cluster class"""
cl = cluster(1)
# seqs = [s.values()[0] for s in data['seqs']]
names = [s.keys()[0] for s in data['seqs']]
cl.add_id_member(names, 1)
freq = defaultdict()
[freq.update({s.keys()[0]: s.values()[0]}) for s in ... | python | def read_cluster(data, id=1):
"""Read json cluster and populate as cluster class"""
cl = cluster(1)
# seqs = [s.values()[0] for s in data['seqs']]
names = [s.keys()[0] for s in data['seqs']]
cl.add_id_member(names, 1)
freq = defaultdict()
[freq.update({s.keys()[0]: s.values()[0]}) for s in ... | [
"def",
"read_cluster",
"(",
"data",
",",
"id",
"=",
"1",
")",
":",
"cl",
"=",
"cluster",
"(",
"1",
")",
"# seqs = [s.values()[0] for s in data['seqs']]",
"names",
"=",
"[",
"s",
".",
"keys",
"(",
")",
"[",
"0",
"]",
"for",
"s",
"in",
"data",
"[",
"'s... | Read json cluster and populate as cluster class | [
"Read",
"json",
"cluster",
"and",
"populate",
"as",
"cluster",
"class"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/methods/__init__.py#L6-L14 |
lpantano/seqcluster | seqcluster/libs/read.py | write_data | def write_data(data, out_file):
"""write json file from seqcluster cluster"""
with open(out_file, 'w') as handle_out:
handle_out.write(json.dumps([data], skipkeys=True, indent=2)) | python | def write_data(data, out_file):
"""write json file from seqcluster cluster"""
with open(out_file, 'w') as handle_out:
handle_out.write(json.dumps([data], skipkeys=True, indent=2)) | [
"def",
"write_data",
"(",
"data",
",",
"out_file",
")",
":",
"with",
"open",
"(",
"out_file",
",",
"'w'",
")",
"as",
"handle_out",
":",
"handle_out",
".",
"write",
"(",
"json",
".",
"dumps",
"(",
"[",
"data",
"]",
",",
"skipkeys",
"=",
"True",
",",
... | write json file from seqcluster cluster | [
"write",
"json",
"file",
"from",
"seqcluster",
"cluster"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/read.py#L33-L36 |
lpantano/seqcluster | seqcluster/libs/read.py | get_sequences_from_cluster | def get_sequences_from_cluster(c1, c2, data):
"""get all sequences from on cluster"""
seqs1 = data[c1]['seqs']
seqs2 = data[c2]['seqs']
seqs = list(set(seqs1 + seqs2))
names = []
for s in seqs:
if s in seqs1 and s in seqs2:
names.append("both")
elif s in seqs1:
... | python | def get_sequences_from_cluster(c1, c2, data):
"""get all sequences from on cluster"""
seqs1 = data[c1]['seqs']
seqs2 = data[c2]['seqs']
seqs = list(set(seqs1 + seqs2))
names = []
for s in seqs:
if s in seqs1 and s in seqs2:
names.append("both")
elif s in seqs1:
... | [
"def",
"get_sequences_from_cluster",
"(",
"c1",
",",
"c2",
",",
"data",
")",
":",
"seqs1",
"=",
"data",
"[",
"c1",
"]",
"[",
"'seqs'",
"]",
"seqs2",
"=",
"data",
"[",
"c2",
"]",
"[",
"'seqs'",
"]",
"seqs",
"=",
"list",
"(",
"set",
"(",
"seqs1",
"... | get all sequences from on cluster | [
"get",
"all",
"sequences",
"from",
"on",
"cluster"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/read.py#L38-L51 |
lpantano/seqcluster | seqcluster/libs/read.py | map_to_precursors | def map_to_precursors(seqs, names, loci, out_file, args):
"""map sequences to precursors with razers3"""
with make_temp_directory() as temp:
pre_fasta = os.path.join(temp, "pre.fa")
seqs_fasta = os.path.join(temp, "seqs.fa")
out_sam = os.path.join(temp, "out.sam")
pre_fasta = get... | python | def map_to_precursors(seqs, names, loci, out_file, args):
"""map sequences to precursors with razers3"""
with make_temp_directory() as temp:
pre_fasta = os.path.join(temp, "pre.fa")
seqs_fasta = os.path.join(temp, "seqs.fa")
out_sam = os.path.join(temp, "out.sam")
pre_fasta = get... | [
"def",
"map_to_precursors",
"(",
"seqs",
",",
"names",
",",
"loci",
",",
"out_file",
",",
"args",
")",
":",
"with",
"make_temp_directory",
"(",
")",
"as",
"temp",
":",
"pre_fasta",
"=",
"os",
".",
"path",
".",
"join",
"(",
"temp",
",",
"\"pre.fa\"",
")... | map sequences to precursors with razers3 | [
"map",
"sequences",
"to",
"precursors",
"with",
"razers3"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/read.py#L58-L74 |
lpantano/seqcluster | seqcluster/libs/read.py | precursor_sequence | def precursor_sequence(loci, reference):
"""Get sequence from genome"""
region = "%s\t%s\t%s\t.\t.\t%s" % (loci[1], loci[2], loci[3], loci[4])
precursor = pybedtools.BedTool(str(region), from_string=True).sequence(fi=reference, s=True)
return open(precursor.seqfn).read().split("\n")[1] | python | def precursor_sequence(loci, reference):
"""Get sequence from genome"""
region = "%s\t%s\t%s\t.\t.\t%s" % (loci[1], loci[2], loci[3], loci[4])
precursor = pybedtools.BedTool(str(region), from_string=True).sequence(fi=reference, s=True)
return open(precursor.seqfn).read().split("\n")[1] | [
"def",
"precursor_sequence",
"(",
"loci",
",",
"reference",
")",
":",
"region",
"=",
"\"%s\\t%s\\t%s\\t.\\t.\\t%s\"",
"%",
"(",
"loci",
"[",
"1",
"]",
",",
"loci",
"[",
"2",
"]",
",",
"loci",
"[",
"3",
"]",
",",
"loci",
"[",
"4",
"]",
")",
"precursor... | Get sequence from genome | [
"Get",
"sequence",
"from",
"genome"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/read.py#L76-L80 |
lpantano/seqcluster | seqcluster/libs/read.py | map_to_precursors_on_fly | def map_to_precursors_on_fly(seqs, names, loci, args):
"""map sequences to precursors with franpr algorithm to avoid writting on disk"""
precursor = precursor_sequence(loci, args.ref).upper()
dat = dict()
for s, n in itertools.izip(seqs, names):
res = pyMatch.Match(precursor, str(s), 1, 3)
... | python | def map_to_precursors_on_fly(seqs, names, loci, args):
"""map sequences to precursors with franpr algorithm to avoid writting on disk"""
precursor = precursor_sequence(loci, args.ref).upper()
dat = dict()
for s, n in itertools.izip(seqs, names):
res = pyMatch.Match(precursor, str(s), 1, 3)
... | [
"def",
"map_to_precursors_on_fly",
"(",
"seqs",
",",
"names",
",",
"loci",
",",
"args",
")",
":",
"precursor",
"=",
"precursor_sequence",
"(",
"loci",
",",
"args",
".",
"ref",
")",
".",
"upper",
"(",
")",
"dat",
"=",
"dict",
"(",
")",
"for",
"s",
","... | map sequences to precursors with franpr algorithm to avoid writting on disk | [
"map",
"sequences",
"to",
"precursors",
"with",
"franpr",
"algorithm",
"to",
"avoid",
"writting",
"on",
"disk"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/read.py#L82-L91 |
lpantano/seqcluster | seqcluster/libs/read.py | _align | def _align(x, y, local = False):
"""
https://medium.com/towards-data-science/pairwise-sequence-alignment-using-biopython-d1a9d0ba861f
"""
if local:
aligned_x = pairwise2.align.localxx(x, y)
else:
aligned_x = pairwise2.align.globalms(x, y, 1, -1, -1, -0.5)
if aligned_x:
... | python | def _align(x, y, local = False):
"""
https://medium.com/towards-data-science/pairwise-sequence-alignment-using-biopython-d1a9d0ba861f
"""
if local:
aligned_x = pairwise2.align.localxx(x, y)
else:
aligned_x = pairwise2.align.globalms(x, y, 1, -1, -1, -0.5)
if aligned_x:
... | [
"def",
"_align",
"(",
"x",
",",
"y",
",",
"local",
"=",
"False",
")",
":",
"if",
"local",
":",
"aligned_x",
"=",
"pairwise2",
".",
"align",
".",
"localxx",
"(",
"x",
",",
"y",
")",
"else",
":",
"aligned_x",
"=",
"pairwise2",
".",
"align",
".",
"g... | https://medium.com/towards-data-science/pairwise-sequence-alignment-using-biopython-d1a9d0ba861f | [
"https",
":",
"//",
"medium",
".",
"com",
"/",
"towards",
"-",
"data",
"-",
"science",
"/",
"pairwise",
"-",
"sequence",
"-",
"alignment",
"-",
"using",
"-",
"biopython",
"-",
"d1a9d0ba861f"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/read.py#L93-L106 |
lpantano/seqcluster | seqcluster/libs/read.py | map_to_precursor_biopython | def map_to_precursor_biopython(seqs, names, loci, args):
"""map the sequences using biopython package"""
precursor = precursor_sequence(loci, args.ref).upper()
dat = dict()
for s, n in itertools.izip(seqs, names):
res = _align(str(s), precursor)
if res:
dat[n] = res
logge... | python | def map_to_precursor_biopython(seqs, names, loci, args):
"""map the sequences using biopython package"""
precursor = precursor_sequence(loci, args.ref).upper()
dat = dict()
for s, n in itertools.izip(seqs, names):
res = _align(str(s), precursor)
if res:
dat[n] = res
logge... | [
"def",
"map_to_precursor_biopython",
"(",
"seqs",
",",
"names",
",",
"loci",
",",
"args",
")",
":",
"precursor",
"=",
"precursor_sequence",
"(",
"loci",
",",
"args",
".",
"ref",
")",
".",
"upper",
"(",
")",
"dat",
"=",
"dict",
"(",
")",
"for",
"s",
"... | map the sequences using biopython package | [
"map",
"the",
"sequences",
"using",
"biopython",
"package"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/read.py#L108-L117 |
lpantano/seqcluster | seqcluster/libs/read.py | get_seqs_fasta | def get_seqs_fasta(seqs, names, out_fa):
"""get fasta from sequences"""
with open(out_fa, 'w') as fa_handle:
for s, n in itertools.izip(seqs, names):
print(">cx{1}-{0}\n{0}".format(s, n), file=fa_handle)
return out_fa | python | def get_seqs_fasta(seqs, names, out_fa):
"""get fasta from sequences"""
with open(out_fa, 'w') as fa_handle:
for s, n in itertools.izip(seqs, names):
print(">cx{1}-{0}\n{0}".format(s, n), file=fa_handle)
return out_fa | [
"def",
"get_seqs_fasta",
"(",
"seqs",
",",
"names",
",",
"out_fa",
")",
":",
"with",
"open",
"(",
"out_fa",
",",
"'w'",
")",
"as",
"fa_handle",
":",
"for",
"s",
",",
"n",
"in",
"itertools",
".",
"izip",
"(",
"seqs",
",",
"names",
")",
":",
"print",... | get fasta from sequences | [
"get",
"fasta",
"from",
"sequences"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/read.py#L138-L143 |
lpantano/seqcluster | seqcluster/libs/read.py | get_loci_fasta | def get_loci_fasta(loci, out_fa, ref):
"""get fasta from precursor"""
if not find_cmd("bedtools"):
raise ValueError("Not bedtools installed")
with make_temp_directory() as temp:
bed_file = os.path.join(temp, "file.bed")
for nc, loci in loci.iteritems():
for l in loci:
... | python | def get_loci_fasta(loci, out_fa, ref):
"""get fasta from precursor"""
if not find_cmd("bedtools"):
raise ValueError("Not bedtools installed")
with make_temp_directory() as temp:
bed_file = os.path.join(temp, "file.bed")
for nc, loci in loci.iteritems():
for l in loci:
... | [
"def",
"get_loci_fasta",
"(",
"loci",
",",
"out_fa",
",",
"ref",
")",
":",
"if",
"not",
"find_cmd",
"(",
"\"bedtools\"",
")",
":",
"raise",
"ValueError",
"(",
"\"Not bedtools installed\"",
")",
"with",
"make_temp_directory",
"(",
")",
"as",
"temp",
":",
"bed... | get fasta from precursor | [
"get",
"fasta",
"from",
"precursor"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/read.py#L150-L163 |
lpantano/seqcluster | seqcluster/libs/read.py | read_alignment | def read_alignment(out_sam, loci, seqs, out_file):
"""read which seqs map to which loci and
return a tab separated file"""
hits = defaultdict(list)
with open(out_file, "w") as out_handle:
samfile = pysam.Samfile(out_sam, "r")
for a in samfile.fetch():
if not a.is_unmapped:
... | python | def read_alignment(out_sam, loci, seqs, out_file):
"""read which seqs map to which loci and
return a tab separated file"""
hits = defaultdict(list)
with open(out_file, "w") as out_handle:
samfile = pysam.Samfile(out_sam, "r")
for a in samfile.fetch():
if not a.is_unmapped:
... | [
"def",
"read_alignment",
"(",
"out_sam",
",",
"loci",
",",
"seqs",
",",
"out_file",
")",
":",
"hits",
"=",
"defaultdict",
"(",
"list",
")",
"with",
"open",
"(",
"out_file",
",",
"\"w\"",
")",
"as",
"out_handle",
":",
"samfile",
"=",
"pysam",
".",
"Samf... | read which seqs map to which loci and
return a tab separated file | [
"read",
"which",
"seqs",
"map",
"to",
"which",
"loci",
"and",
"return",
"a",
"tab",
"separated",
"file"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/read.py#L165-L184 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _download_mirbase | def _download_mirbase(args, version="CURRENT"):
"""
Download files from mirbase
"""
if not args.hairpin or not args.mirna:
logger.info("Working with version %s" % version)
hairpin_fn = op.join(op.abspath(args.out), "hairpin.fa.gz")
mirna_fn = op.join(op.abspath(args.out), "miRNA.... | python | def _download_mirbase(args, version="CURRENT"):
"""
Download files from mirbase
"""
if not args.hairpin or not args.mirna:
logger.info("Working with version %s" % version)
hairpin_fn = op.join(op.abspath(args.out), "hairpin.fa.gz")
mirna_fn = op.join(op.abspath(args.out), "miRNA.... | [
"def",
"_download_mirbase",
"(",
"args",
",",
"version",
"=",
"\"CURRENT\"",
")",
":",
"if",
"not",
"args",
".",
"hairpin",
"or",
"not",
"args",
".",
"mirna",
":",
"logger",
".",
"info",
"(",
"\"Working with version %s\"",
"%",
"version",
")",
"hairpin_fn",
... | Download files from mirbase | [
"Download",
"files",
"from",
"mirbase"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L23-L38 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _make_unique | def _make_unique(name, idx):
"""Make name unique in case only counts there"""
p = re.compile(".[aA-zZ]+_x[0-9]+")
if p.match(name):
tags = name[1:].split("_x")
return ">%s_%s_x%s" % (tags[0], idx, tags[1])
return name.replace("@", ">") | python | def _make_unique(name, idx):
"""Make name unique in case only counts there"""
p = re.compile(".[aA-zZ]+_x[0-9]+")
if p.match(name):
tags = name[1:].split("_x")
return ">%s_%s_x%s" % (tags[0], idx, tags[1])
return name.replace("@", ">") | [
"def",
"_make_unique",
"(",
"name",
",",
"idx",
")",
":",
"p",
"=",
"re",
".",
"compile",
"(",
"\".[aA-zZ]+_x[0-9]+\"",
")",
"if",
"p",
".",
"match",
"(",
"name",
")",
":",
"tags",
"=",
"name",
"[",
"1",
":",
"]",
".",
"split",
"(",
"\"_x\"",
")"... | Make name unique in case only counts there | [
"Make",
"name",
"unique",
"in",
"case",
"only",
"counts",
"there"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L41-L47 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _filter_seqs | def _filter_seqs(fn):
"""Convert names of sequences to unique ids"""
out_file = op.splitext(fn)[0] + "_unique.fa"
idx = 0
if not file_exists(out_file):
with open(out_file, 'w') as out_handle:
with open(fn) as in_handle:
for line in in_handle:
if li... | python | def _filter_seqs(fn):
"""Convert names of sequences to unique ids"""
out_file = op.splitext(fn)[0] + "_unique.fa"
idx = 0
if not file_exists(out_file):
with open(out_file, 'w') as out_handle:
with open(fn) as in_handle:
for line in in_handle:
if li... | [
"def",
"_filter_seqs",
"(",
"fn",
")",
":",
"out_file",
"=",
"op",
".",
"splitext",
"(",
"fn",
")",
"[",
"0",
"]",
"+",
"\"_unique.fa\"",
"idx",
"=",
"0",
"if",
"not",
"file_exists",
"(",
"out_file",
")",
":",
"with",
"open",
"(",
"out_file",
",",
... | Convert names of sequences to unique ids | [
"Convert",
"names",
"of",
"sequences",
"to",
"unique",
"ids"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L50-L69 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _read_precursor | def _read_precursor(precursor, sps):
"""
Load precursor file for that species
"""
hairpin = defaultdict(str)
name = None
with open(precursor) as in_handle:
for line in in_handle:
if line.startswith(">"):
if hairpin[name]:
hairpin[name] = ha... | python | def _read_precursor(precursor, sps):
"""
Load precursor file for that species
"""
hairpin = defaultdict(str)
name = None
with open(precursor) as in_handle:
for line in in_handle:
if line.startswith(">"):
if hairpin[name]:
hairpin[name] = ha... | [
"def",
"_read_precursor",
"(",
"precursor",
",",
"sps",
")",
":",
"hairpin",
"=",
"defaultdict",
"(",
"str",
")",
"name",
"=",
"None",
"with",
"open",
"(",
"precursor",
")",
"as",
"in_handle",
":",
"for",
"line",
"in",
"in_handle",
":",
"if",
"line",
"... | Load precursor file for that species | [
"Load",
"precursor",
"file",
"for",
"that",
"species"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L112-L127 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _read_gtf | def _read_gtf(gtf):
"""
Load GTF file with precursor positions on genome
"""
if not gtf:
return gtf
db = defaultdict(list)
with open(gtf) as in_handle:
for line in in_handle:
if line.startswith("#"):
continue
cols = line.strip().split("\t")... | python | def _read_gtf(gtf):
"""
Load GTF file with precursor positions on genome
"""
if not gtf:
return gtf
db = defaultdict(list)
with open(gtf) as in_handle:
for line in in_handle:
if line.startswith("#"):
continue
cols = line.strip().split("\t")... | [
"def",
"_read_gtf",
"(",
"gtf",
")",
":",
"if",
"not",
"gtf",
":",
"return",
"gtf",
"db",
"=",
"defaultdict",
"(",
"list",
")",
"with",
"open",
"(",
"gtf",
")",
"as",
"in_handle",
":",
"for",
"line",
"in",
"in_handle",
":",
"if",
"line",
".",
"star... | Load GTF file with precursor positions on genome | [
"Load",
"GTF",
"file",
"with",
"precursor",
"positions",
"on",
"genome"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L130-L146 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _coord | def _coord(sequence, start, mirna, precursor, iso):
"""
Define t5 and t3 isomirs
"""
dif = abs(mirna[0] - start)
if start < mirna[0]:
iso.t5 = sequence[:dif].upper()
elif start > mirna[0]:
iso.t5 = precursor[mirna[0] - 1:mirna[0] - 1 + dif].lower()
elif start == mirna[0]:
... | python | def _coord(sequence, start, mirna, precursor, iso):
"""
Define t5 and t3 isomirs
"""
dif = abs(mirna[0] - start)
if start < mirna[0]:
iso.t5 = sequence[:dif].upper()
elif start > mirna[0]:
iso.t5 = precursor[mirna[0] - 1:mirna[0] - 1 + dif].lower()
elif start == mirna[0]:
... | [
"def",
"_coord",
"(",
"sequence",
",",
"start",
",",
"mirna",
",",
"precursor",
",",
"iso",
")",
":",
"dif",
"=",
"abs",
"(",
"mirna",
"[",
"0",
"]",
"-",
"start",
")",
"if",
"start",
"<",
"mirna",
"[",
"0",
"]",
":",
"iso",
".",
"t5",
"=",
"... | Define t5 and t3 isomirs | [
"Define",
"t5",
"and",
"t3",
"isomirs"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L149-L180 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _annotate | def _annotate(reads, mirbase_ref, precursors):
"""
Using SAM/BAM coordinates, mismatches and realign to annotate isomiRs
"""
for r in reads:
for p in reads[r].precursors:
start = reads[r].precursors[p].start + 1 # convert to 1base
end = start + len(reads[r].sequence)
... | python | def _annotate(reads, mirbase_ref, precursors):
"""
Using SAM/BAM coordinates, mismatches and realign to annotate isomiRs
"""
for r in reads:
for p in reads[r].precursors:
start = reads[r].precursors[p].start + 1 # convert to 1base
end = start + len(reads[r].sequence)
... | [
"def",
"_annotate",
"(",
"reads",
",",
"mirbase_ref",
",",
"precursors",
")",
":",
"for",
"r",
"in",
"reads",
":",
"for",
"p",
"in",
"reads",
"[",
"r",
"]",
".",
"precursors",
":",
"start",
"=",
"reads",
"[",
"r",
"]",
".",
"precursors",
"[",
"p",
... | Using SAM/BAM coordinates, mismatches and realign to annotate isomiRs | [
"Using",
"SAM",
"/",
"BAM",
"coordinates",
"mismatches",
"and",
"realign",
"to",
"annotate",
"isomiRs"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L183-L198 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _realign | def _realign(seq, precursor, start):
"""
The actual fn that will realign the sequence
"""
error = set()
pattern_addition = [[1, 1, 0], [1, 0, 1], [0, 1, 0], [0, 1, 1], [0, 0, 1], [1, 1, 1]]
for pos in range(0, len(seq)):
if seq[pos] != precursor[(start + pos)]:
error.add(pos)... | python | def _realign(seq, precursor, start):
"""
The actual fn that will realign the sequence
"""
error = set()
pattern_addition = [[1, 1, 0], [1, 0, 1], [0, 1, 0], [0, 1, 1], [0, 0, 1], [1, 1, 1]]
for pos in range(0, len(seq)):
if seq[pos] != precursor[(start + pos)]:
error.add(pos)... | [
"def",
"_realign",
"(",
"seq",
",",
"precursor",
",",
"start",
")",
":",
"error",
"=",
"set",
"(",
")",
"pattern_addition",
"=",
"[",
"[",
"1",
",",
"1",
",",
"0",
"]",
",",
"[",
"1",
",",
"0",
",",
"1",
"]",
",",
"[",
"0",
",",
"1",
",",
... | The actual fn that will realign the sequence | [
"The",
"actual",
"fn",
"that",
"will",
"realign",
"the",
"sequence"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L201-L231 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _clean_hits | def _clean_hits(reads):
"""
Select only best matches
"""
new_reads = defaultdict(realign)
for r in reads:
world = {}
sc = 0
for p in reads[r].precursors:
world[p] = reads[r].precursors[p].get_score(len(reads[r].sequence))
if sc < world[p]:
... | python | def _clean_hits(reads):
"""
Select only best matches
"""
new_reads = defaultdict(realign)
for r in reads:
world = {}
sc = 0
for p in reads[r].precursors:
world[p] = reads[r].precursors[p].get_score(len(reads[r].sequence))
if sc < world[p]:
... | [
"def",
"_clean_hits",
"(",
"reads",
")",
":",
"new_reads",
"=",
"defaultdict",
"(",
"realign",
")",
"for",
"r",
"in",
"reads",
":",
"world",
"=",
"{",
"}",
"sc",
"=",
"0",
"for",
"p",
"in",
"reads",
"[",
"r",
"]",
".",
"precursors",
":",
"world",
... | Select only best matches | [
"Select",
"only",
"best",
"matches"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L234-L253 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _read_bam | def _read_bam(bam_fn, precursors):
"""
read bam file and perform realignment of hits
"""
mode = "r" if bam_fn.endswith("sam") else "rb"
handle = pysam.Samfile(bam_fn, mode)
reads = defaultdict(realign)
for line in handle:
chrom = handle.getrname(line.reference_id)
# print("%s... | python | def _read_bam(bam_fn, precursors):
"""
read bam file and perform realignment of hits
"""
mode = "r" if bam_fn.endswith("sam") else "rb"
handle = pysam.Samfile(bam_fn, mode)
reads = defaultdict(realign)
for line in handle:
chrom = handle.getrname(line.reference_id)
# print("%s... | [
"def",
"_read_bam",
"(",
"bam_fn",
",",
"precursors",
")",
":",
"mode",
"=",
"\"r\"",
"if",
"bam_fn",
".",
"endswith",
"(",
"\"sam\"",
")",
"else",
"\"rb\"",
"handle",
"=",
"pysam",
".",
"Samfile",
"(",
"bam_fn",
",",
"mode",
")",
"reads",
"=",
"defaul... | read bam file and perform realignment of hits | [
"read",
"bam",
"file",
"and",
"perform",
"realignment",
"of",
"hits"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L271-L291 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _collapse_fastq | def _collapse_fastq(in_fn):
"""
collapse reads into unique sequences
"""
args = argparse.Namespace()
args.fastq = in_fn
args.minimum = 1
args.out = op.dirname(in_fn)
return collapse_fastq(args) | python | def _collapse_fastq(in_fn):
"""
collapse reads into unique sequences
"""
args = argparse.Namespace()
args.fastq = in_fn
args.minimum = 1
args.out = op.dirname(in_fn)
return collapse_fastq(args) | [
"def",
"_collapse_fastq",
"(",
"in_fn",
")",
":",
"args",
"=",
"argparse",
".",
"Namespace",
"(",
")",
"args",
".",
"fastq",
"=",
"in_fn",
"args",
".",
"minimum",
"=",
"1",
"args",
".",
"out",
"=",
"op",
".",
"dirname",
"(",
"in_fn",
")",
"return",
... | collapse reads into unique sequences | [
"collapse",
"reads",
"into",
"unique",
"sequences"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L294-L302 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _read_pyMatch | def _read_pyMatch(fn, precursors):
"""
read pyMatch file and perform realignment of hits
"""
with open(fn) as handle:
reads = defaultdict(realign)
for line in handle:
query_name, seq, chrom, reference_start, end, mism, add = line.split()
reference_start = int(refe... | python | def _read_pyMatch(fn, precursors):
"""
read pyMatch file and perform realignment of hits
"""
with open(fn) as handle:
reads = defaultdict(realign)
for line in handle:
query_name, seq, chrom, reference_start, end, mism, add = line.split()
reference_start = int(refe... | [
"def",
"_read_pyMatch",
"(",
"fn",
",",
"precursors",
")",
":",
"with",
"open",
"(",
"fn",
")",
"as",
"handle",
":",
"reads",
"=",
"defaultdict",
"(",
"realign",
")",
"for",
"line",
"in",
"handle",
":",
"query_name",
",",
"seq",
",",
"chrom",
",",
"r... | read pyMatch file and perform realignment of hits | [
"read",
"pyMatch",
"file",
"and",
"perform",
"realignment",
"of",
"hits"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L305-L328 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _parse_mut | def _parse_mut(subs):
"""
Parse mutation tag from miraligner output
"""
if subs!="0":
subs = [[subs.replace(subs[-2:], ""),subs[-2], subs[-1]]]
return subs | python | def _parse_mut(subs):
"""
Parse mutation tag from miraligner output
"""
if subs!="0":
subs = [[subs.replace(subs[-2:], ""),subs[-2], subs[-1]]]
return subs | [
"def",
"_parse_mut",
"(",
"subs",
")",
":",
"if",
"subs",
"!=",
"\"0\"",
":",
"subs",
"=",
"[",
"[",
"subs",
".",
"replace",
"(",
"subs",
"[",
"-",
"2",
":",
"]",
",",
"\"\"",
")",
",",
"subs",
"[",
"-",
"2",
"]",
",",
"subs",
"[",
"-",
"1"... | Parse mutation tag from miraligner output | [
"Parse",
"mutation",
"tag",
"from",
"miraligner",
"output"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L331-L337 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _read_miraligner | def _read_miraligner(fn):
"""Read ouput of miraligner and create compatible output."""
reads = defaultdict(realign)
with open(fn) as in_handle:
in_handle.next()
for line in in_handle:
cols = line.strip().split("\t")
iso = isomir()
query_name, seq = cols[1]... | python | def _read_miraligner(fn):
"""Read ouput of miraligner and create compatible output."""
reads = defaultdict(realign)
with open(fn) as in_handle:
in_handle.next()
for line in in_handle:
cols = line.strip().split("\t")
iso = isomir()
query_name, seq = cols[1]... | [
"def",
"_read_miraligner",
"(",
"fn",
")",
":",
"reads",
"=",
"defaultdict",
"(",
"realign",
")",
"with",
"open",
"(",
"fn",
")",
"as",
"in_handle",
":",
"in_handle",
".",
"next",
"(",
")",
"for",
"line",
"in",
"in_handle",
":",
"cols",
"=",
"line",
... | Read ouput of miraligner and create compatible output. | [
"Read",
"ouput",
"of",
"miraligner",
"and",
"create",
"compatible",
"output",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L340-L359 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _cmd_miraligner | def _cmd_miraligner(fn, out_file, species, hairpin, out):
"""
Run miraligner for miRNA annotation
"""
tool = _get_miraligner()
path_db = op.dirname(op.abspath(hairpin))
cmd = "{tool} -freq -i {fn} -o {out_file} -s {species} -db {path_db} -sub 1 -trim 3 -add 3"
if not file_exists(out_file):
... | python | def _cmd_miraligner(fn, out_file, species, hairpin, out):
"""
Run miraligner for miRNA annotation
"""
tool = _get_miraligner()
path_db = op.dirname(op.abspath(hairpin))
cmd = "{tool} -freq -i {fn} -o {out_file} -s {species} -db {path_db} -sub 1 -trim 3 -add 3"
if not file_exists(out_file):
... | [
"def",
"_cmd_miraligner",
"(",
"fn",
",",
"out_file",
",",
"species",
",",
"hairpin",
",",
"out",
")",
":",
"tool",
"=",
"_get_miraligner",
"(",
")",
"path_db",
"=",
"op",
".",
"dirname",
"(",
"op",
".",
"abspath",
"(",
"hairpin",
")",
")",
"cmd",
"=... | Run miraligner for miRNA annotation | [
"Run",
"miraligner",
"for",
"miRNA",
"annotation"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L362-L373 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _mirtop | def _mirtop(out_files, hairpin, gff3, species, out):
"""
Convert miraligner to mirtop format
"""
args = argparse.Namespace()
args.hairpin = hairpin
args.sps = species
args.gtf = gff3
args.add_extra = True
args.files = out_files
args.format = "seqbuster"
args.out_format = "gff... | python | def _mirtop(out_files, hairpin, gff3, species, out):
"""
Convert miraligner to mirtop format
"""
args = argparse.Namespace()
args.hairpin = hairpin
args.sps = species
args.gtf = gff3
args.add_extra = True
args.files = out_files
args.format = "seqbuster"
args.out_format = "gff... | [
"def",
"_mirtop",
"(",
"out_files",
",",
"hairpin",
",",
"gff3",
",",
"species",
",",
"out",
")",
":",
"args",
"=",
"argparse",
".",
"Namespace",
"(",
")",
"args",
".",
"hairpin",
"=",
"hairpin",
"args",
".",
"sps",
"=",
"species",
"args",
".",
"gtf"... | Convert miraligner to mirtop format | [
"Convert",
"miraligner",
"to",
"mirtop",
"format"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L376-L389 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _merge | def _merge(dts):
"""
merge multiple samples in one matrix
"""
df = pd.concat(dts)
ma = df.pivot(index='isomir', columns='sample', values='counts')
ma_mirna = ma
ma = ma.fillna(0)
ma_mirna['mirna'] = [m.split(":")[0] for m in ma.index.values]
ma_mirna = ma_mirna.groupby(['mirna']).su... | python | def _merge(dts):
"""
merge multiple samples in one matrix
"""
df = pd.concat(dts)
ma = df.pivot(index='isomir', columns='sample', values='counts')
ma_mirna = ma
ma = ma.fillna(0)
ma_mirna['mirna'] = [m.split(":")[0] for m in ma.index.values]
ma_mirna = ma_mirna.groupby(['mirna']).su... | [
"def",
"_merge",
"(",
"dts",
")",
":",
"df",
"=",
"pd",
".",
"concat",
"(",
"dts",
")",
"ma",
"=",
"df",
".",
"pivot",
"(",
"index",
"=",
"'isomir'",
",",
"columns",
"=",
"'sample'",
",",
"values",
"=",
"'counts'",
")",
"ma_mirna",
"=",
"ma",
"ma... | merge multiple samples in one matrix | [
"merge",
"multiple",
"samples",
"in",
"one",
"matrix"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L454-L466 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | _create_counts | def _create_counts(out_dts, out_dir):
"""Summarize results into single files."""
ma, ma_mirna = _merge(out_dts)
out_ma = op.join(out_dir, "counts.tsv")
out_ma_mirna = op.join(out_dir, "counts_mirna.tsv")
ma.to_csv(out_ma, sep="\t")
ma_mirna.to_csv(out_ma_mirna, sep="\t")
return out_ma_mirna,... | python | def _create_counts(out_dts, out_dir):
"""Summarize results into single files."""
ma, ma_mirna = _merge(out_dts)
out_ma = op.join(out_dir, "counts.tsv")
out_ma_mirna = op.join(out_dir, "counts_mirna.tsv")
ma.to_csv(out_ma, sep="\t")
ma_mirna.to_csv(out_ma_mirna, sep="\t")
return out_ma_mirna,... | [
"def",
"_create_counts",
"(",
"out_dts",
",",
"out_dir",
")",
":",
"ma",
",",
"ma_mirna",
"=",
"_merge",
"(",
"out_dts",
")",
"out_ma",
"=",
"op",
".",
"join",
"(",
"out_dir",
",",
"\"counts.tsv\"",
")",
"out_ma_mirna",
"=",
"op",
".",
"join",
"(",
"ou... | Summarize results into single files. | [
"Summarize",
"results",
"into",
"single",
"files",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L469-L476 |
lpantano/seqcluster | seqcluster/seqbuster/__init__.py | miraligner | def miraligner(args):
"""
Realign BAM hits to miRBAse to get better accuracy and annotation
"""
hairpin, mirna = _download_mirbase(args)
precursors = _read_precursor(args.hairpin, args.sps)
matures = _read_mature(args.mirna, args.sps)
gtf = _read_gtf(args.gtf)
out_dts = []
out_files ... | python | def miraligner(args):
"""
Realign BAM hits to miRBAse to get better accuracy and annotation
"""
hairpin, mirna = _download_mirbase(args)
precursors = _read_precursor(args.hairpin, args.sps)
matures = _read_mature(args.mirna, args.sps)
gtf = _read_gtf(args.gtf)
out_dts = []
out_files ... | [
"def",
"miraligner",
"(",
"args",
")",
":",
"hairpin",
",",
"mirna",
"=",
"_download_mirbase",
"(",
"args",
")",
"precursors",
"=",
"_read_precursor",
"(",
"args",
".",
"hairpin",
",",
"args",
".",
"sps",
")",
"matures",
"=",
"_read_mature",
"(",
"args",
... | Realign BAM hits to miRBAse to get better accuracy and annotation | [
"Realign",
"BAM",
"hits",
"to",
"miRBAse",
"to",
"get",
"better",
"accuracy",
"and",
"annotation"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/seqbuster/__init__.py#L479-L539 |
lpantano/seqcluster | seqcluster/install.py | chdir | def chdir(new_dir):
"""
stolen from bcbio.
Context manager to temporarily change to a new directory.
http://lucentbeing.com/blog/context-managers-and-the-with-statement-in-python/
"""
cur_dir = os.getcwd()
_mkdir(new_dir)
os.chdir(new_dir)
try:
yield
finally:
os.... | python | def chdir(new_dir):
"""
stolen from bcbio.
Context manager to temporarily change to a new directory.
http://lucentbeing.com/blog/context-managers-and-the-with-statement-in-python/
"""
cur_dir = os.getcwd()
_mkdir(new_dir)
os.chdir(new_dir)
try:
yield
finally:
os.... | [
"def",
"chdir",
"(",
"new_dir",
")",
":",
"cur_dir",
"=",
"os",
".",
"getcwd",
"(",
")",
"_mkdir",
"(",
"new_dir",
")",
"os",
".",
"chdir",
"(",
"new_dir",
")",
"try",
":",
"yield",
"finally",
":",
"os",
".",
"chdir",
"(",
"cur_dir",
")"
] | stolen from bcbio.
Context manager to temporarily change to a new directory.
http://lucentbeing.com/blog/context-managers-and-the-with-statement-in-python/ | [
"stolen",
"from",
"bcbio",
".",
"Context",
"manager",
"to",
"temporarily",
"change",
"to",
"a",
"new",
"directory",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/install.py#L35-L48 |
lpantano/seqcluster | seqcluster/install.py | _get_flavor | def _get_flavor():
"""
Download flavor from github
"""
target = op.join("seqcluster", "flavor")
url = "https://github.com/lpantano/seqcluster.git"
if not os.path.exists(target):
# shutil.rmtree("seqcluster")
subprocess.check_call(["git", "clone","-b", "flavor", "--single-branch", u... | python | def _get_flavor():
"""
Download flavor from github
"""
target = op.join("seqcluster", "flavor")
url = "https://github.com/lpantano/seqcluster.git"
if not os.path.exists(target):
# shutil.rmtree("seqcluster")
subprocess.check_call(["git", "clone","-b", "flavor", "--single-branch", u... | [
"def",
"_get_flavor",
"(",
")",
":",
"target",
"=",
"op",
".",
"join",
"(",
"\"seqcluster\"",
",",
"\"flavor\"",
")",
"url",
"=",
"\"https://github.com/lpantano/seqcluster.git\"",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"target",
")",
":",
"# s... | Download flavor from github | [
"Download",
"flavor",
"from",
"github"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/install.py#L70-L79 |
lpantano/seqcluster | seqcluster/install.py | _install | def _install(path, args):
"""
small helper for installation in case outside bcbio
"""
try:
from bcbio import install as bcb
except:
raise ImportError("It needs bcbio to do the quick installation.")
path_flavor = _get_flavor()
s = {"fabricrc_overrides": {"system_install": path... | python | def _install(path, args):
"""
small helper for installation in case outside bcbio
"""
try:
from bcbio import install as bcb
except:
raise ImportError("It needs bcbio to do the quick installation.")
path_flavor = _get_flavor()
s = {"fabricrc_overrides": {"system_install": path... | [
"def",
"_install",
"(",
"path",
",",
"args",
")",
":",
"try",
":",
"from",
"bcbio",
"import",
"install",
"as",
"bcb",
"except",
":",
"raise",
"ImportError",
"(",
"\"It needs bcbio to do the quick installation.\"",
")",
"path_flavor",
"=",
"_get_flavor",
"(",
")"... | small helper for installation in case outside bcbio | [
"small",
"helper",
"for",
"installation",
"in",
"case",
"outside",
"bcbio"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/install.py#L81-L113 |
lpantano/seqcluster | seqcluster/install.py | _install_data | def _install_data(data_dir, path_flavor, args):
"""Upgrade required genome data files in place.
"""
try:
from bcbio import install as bcb
except:
raise ImportError("It needs bcbio to do the quick installation.")
bio_data = op.join(path_flavor, "../biodata.yaml")
s = {"flavor": pa... | python | def _install_data(data_dir, path_flavor, args):
"""Upgrade required genome data files in place.
"""
try:
from bcbio import install as bcb
except:
raise ImportError("It needs bcbio to do the quick installation.")
bio_data = op.join(path_flavor, "../biodata.yaml")
s = {"flavor": pa... | [
"def",
"_install_data",
"(",
"data_dir",
",",
"path_flavor",
",",
"args",
")",
":",
"try",
":",
"from",
"bcbio",
"import",
"install",
"as",
"bcb",
"except",
":",
"raise",
"ImportError",
"(",
"\"It needs bcbio to do the quick installation.\"",
")",
"bio_data",
"=",... | Upgrade required genome data files in place. | [
"Upgrade",
"required",
"genome",
"data",
"files",
"in",
"place",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/install.py#L115-L141 |
lpantano/seqcluster | seqcluster/make_predictions.py | predictions | def predictions(args):
"""
Create predictions of clusters
"""
logger.info(args)
logger.info("reading sequeces")
out_file = os.path.abspath(os.path.splitext(args.json)[0] + "_prediction.json")
data = load_data(args.json)
out_dir = os.path.abspath(safe_dirs(os.path.join(args.out, "predict... | python | def predictions(args):
"""
Create predictions of clusters
"""
logger.info(args)
logger.info("reading sequeces")
out_file = os.path.abspath(os.path.splitext(args.json)[0] + "_prediction.json")
data = load_data(args.json)
out_dir = os.path.abspath(safe_dirs(os.path.join(args.out, "predict... | [
"def",
"predictions",
"(",
"args",
")",
":",
"logger",
".",
"info",
"(",
"args",
")",
"logger",
".",
"info",
"(",
"\"reading sequeces\"",
")",
"out_file",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"path",
".",
"splitext",
"(",
"args",
"... | Create predictions of clusters | [
"Create",
"predictions",
"of",
"clusters"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/make_predictions.py#L11-L29 |
lpantano/seqcluster | seqcluster/detect/description.py | sort_precursor | def sort_precursor(c, loci):
"""
Sort loci according to number of sequences mapped there.
"""
# Original Py 2.7 code
#data_loci = map(lambda (x): [x, loci[x].chr, int(loci[x].start), int(loci[x].end), loci[x].strand, len(c.loci2seq[x])], c.loci2seq.keys())
# 2to3 suggested Py 3 rewrite
data_... | python | def sort_precursor(c, loci):
"""
Sort loci according to number of sequences mapped there.
"""
# Original Py 2.7 code
#data_loci = map(lambda (x): [x, loci[x].chr, int(loci[x].start), int(loci[x].end), loci[x].strand, len(c.loci2seq[x])], c.loci2seq.keys())
# 2to3 suggested Py 3 rewrite
data_... | [
"def",
"sort_precursor",
"(",
"c",
",",
"loci",
")",
":",
"# Original Py 2.7 code",
"#data_loci = map(lambda (x): [x, loci[x].chr, int(loci[x].start), int(loci[x].end), loci[x].strand, len(c.loci2seq[x])], c.loci2seq.keys())",
"# 2to3 suggested Py 3 rewrite",
"data_loci",
"=",
"[",
"[",
... | Sort loci according to number of sequences mapped there. | [
"Sort",
"loci",
"according",
"to",
"number",
"of",
"sequences",
"mapped",
"there",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/detect/description.py#L14-L23 |
lpantano/seqcluster | seqcluster/detect/description.py | best_precursor | def best_precursor(clus, loci):
"""
Select best precursor asuming size around 100 nt
"""
data_loci = sort_precursor(clus, loci)
current_size = data_loci[0][5]
best = 0
for item, locus in enumerate(data_loci):
if locus[3] - locus[2] > 70:
if locus[5] > current_size * 0.8:
... | python | def best_precursor(clus, loci):
"""
Select best precursor asuming size around 100 nt
"""
data_loci = sort_precursor(clus, loci)
current_size = data_loci[0][5]
best = 0
for item, locus in enumerate(data_loci):
if locus[3] - locus[2] > 70:
if locus[5] > current_size * 0.8:
... | [
"def",
"best_precursor",
"(",
"clus",
",",
"loci",
")",
":",
"data_loci",
"=",
"sort_precursor",
"(",
"clus",
",",
"loci",
")",
"current_size",
"=",
"data_loci",
"[",
"0",
"]",
"[",
"5",
"]",
"best",
"=",
"0",
"for",
"item",
",",
"locus",
"in",
"enum... | Select best precursor asuming size around 100 nt | [
"Select",
"best",
"precursor",
"asuming",
"size",
"around",
"100",
"nt"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/detect/description.py#L25-L40 |
lpantano/seqcluster | scripts/map_SNP_positions.py | _open_file | def _open_file(in_file):
"""From bcbio code"""
_, ext = os.path.splitext(in_file)
if ext == ".gz":
return gzip.open(in_file, 'rb')
if ext in [".fastq", ".fq"]:
return open(in_file, 'r')
# default to just opening it
return open(in_file, "r") | python | def _open_file(in_file):
"""From bcbio code"""
_, ext = os.path.splitext(in_file)
if ext == ".gz":
return gzip.open(in_file, 'rb')
if ext in [".fastq", ".fq"]:
return open(in_file, 'r')
# default to just opening it
return open(in_file, "r") | [
"def",
"_open_file",
"(",
"in_file",
")",
":",
"_",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"in_file",
")",
"if",
"ext",
"==",
"\".gz\"",
":",
"return",
"gzip",
".",
"open",
"(",
"in_file",
",",
"'rb'",
")",
"if",
"ext",
"in",
"... | From bcbio code | [
"From",
"bcbio",
"code"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/scripts/map_SNP_positions.py#L8-L16 |
lpantano/seqcluster | scripts/map_SNP_positions.py | select_snps | def select_snps(mirna, snp, out):
"""
Use bedtools to intersect coordinates
"""
with open(out, 'w') as out_handle:
print(_create_header(mirna, snp, out), file=out_handle, end="")
snp_in_mirna = pybedtools.BedTool(snp).intersect(pybedtools.BedTool(mirna), wo=True)
for single in sn... | python | def select_snps(mirna, snp, out):
"""
Use bedtools to intersect coordinates
"""
with open(out, 'w') as out_handle:
print(_create_header(mirna, snp, out), file=out_handle, end="")
snp_in_mirna = pybedtools.BedTool(snp).intersect(pybedtools.BedTool(mirna), wo=True)
for single in sn... | [
"def",
"select_snps",
"(",
"mirna",
",",
"snp",
",",
"out",
")",
":",
"with",
"open",
"(",
"out",
",",
"'w'",
")",
"as",
"out_handle",
":",
"print",
"(",
"_create_header",
"(",
"mirna",
",",
"snp",
",",
"out",
")",
",",
"file",
"=",
"out_handle",
"... | Use bedtools to intersect coordinates | [
"Use",
"bedtools",
"to",
"intersect",
"coordinates"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/scripts/map_SNP_positions.py#L58-L78 |
lpantano/seqcluster | seqcluster/libs/mystats.py | up_threshold | def up_threshold(x, s, p):
"""function to decide if similarity is
below cutoff"""
if 1.0 * x/s >= p:
return True
elif stat.binom_test(x, s, p) > 0.01:
return True
return False | python | def up_threshold(x, s, p):
"""function to decide if similarity is
below cutoff"""
if 1.0 * x/s >= p:
return True
elif stat.binom_test(x, s, p) > 0.01:
return True
return False | [
"def",
"up_threshold",
"(",
"x",
",",
"s",
",",
"p",
")",
":",
"if",
"1.0",
"*",
"x",
"/",
"s",
">=",
"p",
":",
"return",
"True",
"elif",
"stat",
".",
"binom_test",
"(",
"x",
",",
"s",
",",
"p",
")",
">",
"0.01",
":",
"return",
"True",
"retur... | function to decide if similarity is
below cutoff | [
"function",
"to",
"decide",
"if",
"similarity",
"is",
"below",
"cutoff"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/mystats.py#L6-L13 |
lpantano/seqcluster | seqcluster/libs/peaks.py | _scan | def _scan(positions):
"""get the region inside the vector with more expression"""
scores = []
for start in range(0, len(positions) - 17, 5):
end = start = 17
scores.add(_enrichment(positions[start:end], positions[:start], positions[end:])) | python | def _scan(positions):
"""get the region inside the vector with more expression"""
scores = []
for start in range(0, len(positions) - 17, 5):
end = start = 17
scores.add(_enrichment(positions[start:end], positions[:start], positions[end:])) | [
"def",
"_scan",
"(",
"positions",
")",
":",
"scores",
"=",
"[",
"]",
"for",
"start",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"positions",
")",
"-",
"17",
",",
"5",
")",
":",
"end",
"=",
"start",
"=",
"17",
"scores",
".",
"add",
"(",
"_enrichm... | get the region inside the vector with more expression | [
"get",
"the",
"region",
"inside",
"the",
"vector",
"with",
"more",
"expression"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/peaks.py#L4-L9 |
lpantano/seqcluster | seqcluster/make_clusters.py | cluster | def cluster(args):
"""
Creating clusters
"""
args = _check_args(args)
read_stats_file = op.join(args.dir_out, "read_stats.tsv")
if file_exists(read_stats_file):
os.remove(read_stats_file)
bam_file, seq_obj = _clean_alignment(args)
logger.info("Parsing matrix file")
seqL, y... | python | def cluster(args):
"""
Creating clusters
"""
args = _check_args(args)
read_stats_file = op.join(args.dir_out, "read_stats.tsv")
if file_exists(read_stats_file):
os.remove(read_stats_file)
bam_file, seq_obj = _clean_alignment(args)
logger.info("Parsing matrix file")
seqL, y... | [
"def",
"cluster",
"(",
"args",
")",
":",
"args",
"=",
"_check_args",
"(",
"args",
")",
"read_stats_file",
"=",
"op",
".",
"join",
"(",
"args",
".",
"dir_out",
",",
"\"read_stats.tsv\"",
")",
"if",
"file_exists",
"(",
"read_stats_file",
")",
":",
"os",
".... | Creating clusters | [
"Creating",
"clusters"
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/make_clusters.py#L34-L104 |
lpantano/seqcluster | seqcluster/make_clusters.py | _check_args | def _check_args(args):
"""
check arguments before starting analysis.
"""
logger.info("Checking parameters and files")
args.dir_out = args.out
args.samplename = "pro"
global decision_cluster
global similar
if not os.path.isdir(args.out):
logger.warning("the output folder doens... | python | def _check_args(args):
"""
check arguments before starting analysis.
"""
logger.info("Checking parameters and files")
args.dir_out = args.out
args.samplename = "pro"
global decision_cluster
global similar
if not os.path.isdir(args.out):
logger.warning("the output folder doens... | [
"def",
"_check_args",
"(",
"args",
")",
":",
"logger",
".",
"info",
"(",
"\"Checking parameters and files\"",
")",
"args",
".",
"dir_out",
"=",
"args",
".",
"out",
"args",
".",
"samplename",
"=",
"\"pro\"",
"global",
"decision_cluster",
"global",
"similar",
"i... | check arguments before starting analysis. | [
"check",
"arguments",
"before",
"starting",
"analysis",
"."
] | train | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/make_clusters.py#L107-L145 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.