Skip to content

Instantly share code, notes, and snippets.

@harryscholes
harryscholes / ssh-keys.sh
Last active May 18, 2017 09:49
Passwordless SSH login
# Copy SSH keys to remote server for passwordless login
ssh-copy-id <username>@<remote.server>
ssh -XY <username>@<remote.server>
# Additionally add this to ~/.ssh/config file
Host <name>
User <username_on_remote_server>
HostName <remote.server>
proxyCommand ssh -W <remote.server>:22 <username>@<login.server>
@harryscholes
harryscholes / load_BLAST_outfmt_m6.py
Created May 30, 2017 12:47
Load NCBI BLAST -outfmt 6 .tsv file into Python with Pandas
import pandas as pd
BLAST_output_file = "" # set to the path of the BLAST output file
df = pd.read_csv(BLAST_output_file,
sep="\t",
header=None,
names=["query_id", "subject_id", "pct_identity", "aln_length", "n_of_mismatches",
"gap_openings", "q_start", "q_end", "s_start", "s_end", "e_value", "bit_score"])
@harryscholes
harryscholes / GO_evidence_codes.py
Created May 31, 2017 13:18
High quality experimental and curated GO evidence codes
codes = ["EXP", "IDA", "IPI", "IMP", "IGI", "IEP", # experimental
"ISS", "ISO", "ISA", "ISM", "IGC", "IBA", "IBD", "IKR", "IRD", "RCA", "IC", "TAS", # curated
"IEA"] # automatically-assigned
@harryscholes
harryscholes / sparse_boolean_indexing.py
Created June 2, 2017 11:13
Efficient boolean indexing of SciPy spare matrices
from scipy import sparse
# generate a random sparse matrix
M = sparse.random(100,100)
M
# <100x100 sparse matrix of type '<class 'numpy.float64'>'
# with 100 stored elements in COOrdinate format>
# create boolean array of the data stord in the sparse matrix
@harryscholes
harryscholes / anaconda_auto.env
Last active June 5, 2017 15:48
Anaconda autoenv that won't reactivate the environment when changing into child directories
# dependencies: conda, autoenv
# cd into dir containing environment.yml file and run: conda env create
# save this gist to file named .env in the dir
# run: source /usr/local/opt/autoenv/activate.sh
# set to the name of the Anaconda environment contained in environment.yml
venv=
# get the current environment
@harryscholes
harryscholes / kegg_api.sh
Created June 12, 2017 13:19
Download all KEGG pathways and modules for an organism
organism=spo
# Download S. pombe KEGG pathways
wget -O kegg_pathways.tsv http://rest.kegg.jp/list/pathway/${organism}
ids=$(cut -f1 kegg_pathways.tsv)
for id in $ids; do
wget -O ${id}.json http://togows.dbcls.jp/entry/pathway/${id}/genes.json
done
@harryscholes
harryscholes / github_dev.sh
Last active August 1, 2017 16:25
Setup development environment for Python modules stored on GitHub
## e.g. for NetworkX (https://github.com/networkx/networkx/blob/master/CONTRIBUTE.rst)
## set up repo
# fork repo on GitHub
cd ~/git
git clone git@github.com:harryscholes/networkx.git
cd networkx
git remote add upstream git@github.com:networkx/networkx.git
git checkout master
@harryscholes
harryscholes / iota_seed.py
Last active August 22, 2017 14:49
IOTA cryptocurrency altcoin seed generator for IOTA Wallet
import string, secrets
pool = list(string.ascii_uppercase[:] + str(9))
seed = "".join(secrets.choice(pool) for _ in range(81))
@harryscholes
harryscholes / dropbox_paper_to_latex.sh
Created August 17, 2017 14:10
Convert Dropbox Paper document to LaTeX
# set these to the name of the markdown file exported from Dropbox Paper and the desired name of the LaTeX file
MARKDOWN_FILE=
LATEX_FILE=
# Dropbox uses '$$' for markdown math, so this must be replaced with '$'
sed -i '' -e 's/\$\$/\$/g' $MARKDOWN_FILE
# convert markdown to LaTeX
pandoc $MARKDOWN_FILE -f markdown -t latex -o $LATEX_FILE --mathjax --top-level-division=chapter --wrap=none
@harryscholes
harryscholes / boilerplate_class_definition.py
Created November 3, 2017 15:19
Boilerplate class definition in Python
class Meta(type):
"""
Flexible metaclass for defining useful decorator functions.
"""
def __new__(cls, clsname, bases, clsdict):
clsobj = super().__new__(cls, clsname, bases, clsdict)
return clsobj
class Base(object, metaclass=Meta):