This file contains hidden or 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 datetime | |
def format_time(time: datetime.datetime) -> str: | |
"""Standard timestamp format. Ex: 2016-05-02_22_35_56.""" | |
return time.strftime("%Y-%m-%d_%H-%M-%S") | |
def timestamp() -> str: | |
"""Standard timestamp of time now. Ex: 2016-05-02_22_35_56.""" | |
return format_time(datetime.datetime.now()) |
This file contains hidden or 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 IPython.display import display, Markdown | |
import pandas as pd | |
def head(df: pd.DataFrame, n_rows:int=1) -> None: | |
"""Pretty-print the head of a Pandas table in a Jupyter notebook and show its dimensions.""" | |
display(Markdown("**whole table (below):** {} rows × {} columns".format(len(df), len(df.columns)))) | |
display(df.head(n_rows)) |
This file contains hidden or 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 for the Kokel Lab, which has released it under the Apache Software License, Version 2.0 | |
# See the license file here: https://gist.github.com/dmyersturnbull/bfa1c3371e7449db553aaa1e7cd3cac1 | |
# The list of copyright owners is unknown | |
from typing import Callable, Optional, Tuple, Iterable | |
from matplotlib.axes import SubplotBase | |
import seaborn as sns | |
def prettify_plot(plot_fn: Callable[[], SubplotBase], | |
style :str='whitegrid', |
This file contains hidden or 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 numpy as np | |
def sliding_window(x: np.ndarray, n: int) -> np.ndarray: | |
"""Returns a sliding window of n elements from x. | |
Raises a ValueError of n > len(x). | |
""" | |
if n > len(x): raise ValueError("N must be less than the array length") | |
# Courtesy of https://stackoverflow.com/questions/13728392/moving-average-or-running-mean | |
return np.convolve(x, np.ones((n,)) / n, mode='valid') |
This file contains hidden or 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]) |
This file contains hidden or 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 hidden or 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!). | |
from dl_and_rezip import dl_and_rezip # see https://gist.github.com/dmyersturnbull/a6591676fc98da355c5250d48e26844e | |
from lines import lines | |
from typing import Mapping, Iterable, Optional, Iterator, Callable | |
import os | |
import warnings | |
import pandas as pd | |
import re |
This file contains hidden or 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 hidden or 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 hidden or 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) | |
} |