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
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
# 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
using MAT | |
using Lumberjack | |
@doc """ | |
Using MAT.jl, converts any MATLAB version >=5 .mat file to an HDF5-compatible MATLAB version 7 .mat file. | |
Warns if the file already exists. | |
""" -> | |
function convert_to_matlab7(input_file:: AbstractString, output_file:: AbstractString) | |
if ispath(output_file) | |
warn("File $output_file already exists") |
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 org.scalacheck.Gen | |
import org.scalatest.{PropSpec, Matchers} | |
import org.scalatest.prop.PropertyChecks | |
class MinimalScalaCheckExample extends PropSpec with PropertyChecks with Matchers { | |
property("A string's length should be constant") { | |
forAll { (s: String) => | |
s.length should equal(s.length) | |
} | |
} |
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
from http_get import http_get # uses https://gist.github.com/dmyersturnbull/fade1a5901beeb1003680f8267454640 | |
from typing import Mapping, Union, Iterable | |
import json | |
searchable_fields = {'alias_name', 'alias_symbol', 'ccds_id', 'ena', 'ensemble_gene_id', | |
'entrez_id', 'hgnc_id', 'locus_group', 'locus_type', 'mgd_id', | |
'name', 'prev_name', 'prev_symbol', 'refseq_accession', 'rgd_id', | |
'status', 'symbol', 'ucsc_id', 'uniprot_ids', 'vega_id'} | |
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
from typing import Callable | |
import pandas as pd | |
from dl_and_rezip import dl_and_rezip # see https://gist.github.com/dmyersturnbull/a6591676fc98da355c5250d48e26844e | |
def _load(filter_fn: Callable[[pd.DataFrame], pd.DataFrame]=pd.DataFrame.dropna) -> pd.DataFrame: | |
"""Get a DataFrame of Human Protein Atlas tissue expression data, indexed by Gene name and with the 'Gene' and 'Reliability' columns dropped. | |
The expression level ('Level') is replaced using this map: {'Not detected': 0, 'Low': 1, 'Medium': 2, 'High': 3}. | |
Downloads the file from http://www.proteinatlas.org/download/normal_tissue.csv.zip and reloads from normal_tissue.csv.gz thereafter. |
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 | |
} |
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
private implicit class Paddable(string: String) { | |
/** Left-pad this string. */ | |
def ^(end: Int): String = " " * (end - string.length) + string | |
/** Right-pad this string. */ | |
def $(end: Int): String = string + " " * (end - string.length) | |
} |
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
# This prints thisismypassword: | |
password = "thisismypassword" | |
function display_post(post_text) | |
println("<p>$post_text</p>") | |
end | |
display_post("$pass" * "word") | |
# This doesn't when given $password (escaped) as an argument: | |
display_post(ARGS[1]) |
OlderNewer