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 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 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 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 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
# 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 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
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
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
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 gzip, io | |
from typing import Iterator | |
def lines(file_name: str, known_encoding='utf-8') -> Iterator[str]: | |
"""Lazily read a text file or gzipped text file, decode, and strip any newline character (\n or \r). | |
If the file name ends with '.gz' or '.gzip', assumes the file is Gzipped. | |
Arguments: | |
known_encoding: Applied only when decoding gzip | |
""" | |
if file_name.endswith('.gz') or file_name.endswith('.gzip'): |