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
def reverse_complement(sequence): | |
tab = str.maketrans("ACGT", "TGCA") | |
return sequence.translate(tab)[::-1] | |
def apply_rc(row): | |
if row['strand'] == '-': | |
row['seq'] = reverse_complement(row['seq']) | |
return row | |
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
# run this in you bash command line | |
# list all r3 packages installed with conda: | |
conda list | grep r3 | awk '{print $1}') | |
# remove all pakages r3 | |
for i in $(conda list | grep r3 | awk '{print $1}'); do conda remove -y $i; done | |
# finally, remove R | |
conda remove r-essentials |
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
\documentclass{article} | |
\usepackage{tikz} | |
\usepackage{array} | |
\usepackage{siunitx} | |
\usetikzlibrary{shapes.geometric, shapes.misc, arrows, fit, calc} | |
\newcommand\addvmargin[1]{ | |
\node[fit=(current bounding box),inner ysep=#1,inner xsep=0]{}; | |
} |
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
df['new'] = df['new'].str.split('/') # example how to listfy a column of strings | |
temp = pd.DataFrame(df['new'].dropna().tolist()) | |
temp = temp.stack() | |
temp.index = temp.index.droplevel(1) # index need to be coherent with the original dataframe | |
temp.name = 'new_colum' # name of the new column in the original dataframe | |
df = df.join(temp) |
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
def better_table(table, caption, name): | |
start = r""" | |
\begin{{table}}[!htb] | |
\sisetup{{round-mode=places, round-precision=2}} | |
\caption{{{}}}\label{{table:{}}} | |
\centering | |
""".format(caption, name) | |
end = r"\end{table}" |
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 operator | |
sequence = "ACGACTGATCGATCGATCGATGCATCGATCGACGAT" | |
random_positions = random.sample(xrange(len(sequence)), 30) | |
get_positions = operator.itemgetter(*random_positions) | |
get_positions(sequence) | |
('T', 'C', 'G', 'C', 'A', 'C', 'C', 'T', 'A', 'T', 'G', 'T', 'A', 'T', 'C', 'C', 'T', 'T', 'A', 'G', 'T', 'A', 'A', 'A', 'C', 'G', 'G', 'C', 'G', 'A') | |
from itertools import groupby |
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 urlparse import parse_qs | |
import pandas as pd | |
def _fetch_uniprot_gff(identifier): | |
""" | |
Retrieve UniProt data from the GFF file | |
:param identifier: UniProt accession identifier | |
:type identifier: str |
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
print '>\n' + '\n> \n'.join(list(df.query(...).sequence_column)) |
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 requests | |
data = {"title": "Found a bug", # str | |
"body": "I'm having a problem with this.", # str | |
"assignee": None, # username str or None | |
"milestone": 1, # int | |
"labels": ['label1']} # list of str | |
def submit_github_issue(data, token, username, repo): | |
headers = {'Content-Type':'application/json', |
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 pandas as pd | |
colspecs = [(0, 6), (6, 11), (12, 16), (16, 17), (17, 20), (21, 22), (22, 26), | |
(26, 27), (30, 38), (38, 46), (46, 54), (54, 60), (60, 66), (76, 78), | |
(78, 80)] | |
names = ['ATOM', 'serial', 'name', 'altloc', 'resname', 'chainid', 'resseq', | |
'icode', 'x', 'y', 'z', 'occupancy', 'tempfactor', 'element', 'charge'] | |
pdb = pd.read_fwf(pdb_path, names=names, colspecs=colspecs) |