This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Douglas Myers-Turnbull wrote this while at UCSF. Because of this, the list of copyright owners is unknown and is not licensed (sorry!). | |
import chemspipy | |
from chemspipy import ChemSpider | |
import warnings | |
from typing import Iterable, Mapping, Optional | |
import warnings | |
import time | |
# use your API key for fetching from ChemSpider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import warnings | |
import numpy as np | |
from typing import Iterable, Mapping, Callable, Any, Tuple | |
def converge(sampler: Callable[[None], Iterable[float]], | |
statistic:Callable[[np.ndarray], float]=np.mean, | |
ε:float=0.01, min_iters:int=3, max_iters:int=50, | |
noter:Callable[[int, float, float, Iterable[float]], Any]=lambda i, estimate, delta, samples: print('Iteration {}: {:.3f}, δ=={:.3f}'.format(i, estimate, delta)) | |
) -> Tuple[float, Iterable[float]]: | |
"""Repeatedly sample something until the mean (or other statistic) converges to within ε. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import sys | |
from io import StringIO | |
@contextlib.contextmanager | |
def silenced(no_stdout=True, no_stderr=True): | |
""" | |
Suppresses output to stdout and/or stderr. | |
Always resets stdout and stderr, even on an exception. | |
Usage: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires https://gist.github.com/dmyersturnbull/efe32052bf4cf06df915 | |
import pandas as pd | |
from typing import Iterable, Union, Mapping | |
from goatools import obo_parser # uses https://github.com/tanghaibao/goatools | |
from goatools.obo_parser import GOTerm # NOT the same as FlatGoTerm, which has no knowledge of hierarchy | |
if not os.path.exists('gene_ontology.1_2.obo'): | |
import wget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires https://gist.github.com/dmyersturnbull/c0717406eb46158401a9: | |
from silenced import silenced | |
import re | |
import uniprot # from https://github.com/boscoh/uniprot | |
import pandas as pd | |
import contextlib | |
import sys | |
from io import StringIO | |
from typing import Iterable, Union, Mapping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class UnorderedPair[A](a: A, b: A) { | |
override def equals(o: Any) = o match { | |
case that: UnorderedPair[A] => that.a == a && that.b == b || that.a == b && that.b == a | |
case _ => false | |
} | |
override def hashCode = a.hashCode * b.hashCode // commutative and unique | |
} |
NewerOlder