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 scipy.stats import fisher_exact | |
import pandas as pd | |
from IPython.display import display, Markdown | |
def read_google_sheet(): | |
SHEET_ID = '1JSjSLuto3jqdEnnG7JqzeC_1pUZw76n7XueVAYrUOpk' | |
SHEET_NAME = 'Sheet1' | |
url = f'https://docs.google.com/spreadsheets/d/{SHEET_ID}/gviz/tq?tqx=out:csv&sheet={SHEET_NAME}' | |
df = pd.read_csv(url, header=1, dtype='str') | |
return df.loc[:, [not x.startswith('Unnamed') for x in df.columns]] |
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 matplotlib.pyplot as plt | |
import matplotlib.colors as clr | |
import numpy as np | |
some_matrix = np.random.rand(10, 10) | |
cmap = clr.LinearSegmentedColormap.from_list('custom colormap', | |
['white', 'gold', 'red', 'magenta', 'blue', 'black'], | |
N=256) | |
sns.heatmap(some_matrix, cmap=cmap) |
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
# set dark plots if theme is dark | |
user_settings = '~/.jupyter/lab/user-settings/@jupyterlab/apputils-extension/themes.jupyterlab-settings' | |
if 'JupyterLab Dark' in open(os.path.expanduser(user_settings)).read(): | |
style = {'axes.facecolor': '#111111', | |
'axes.edgecolor': '.99', | |
'axes.labelcolor': '.99', | |
'figure.facecolor': '#111111', | |
'grid.color': '.0', | |
'text.color': '.99', | |
'xtick.color': '.99', |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 read_google_sheet(): | |
SHEET_ID = '1JSjSLuto3jqdEnnG7JqzeC_1pUZw76n7XueVAYrUOpk' | |
SHEET_NAME = 'Sheet1' | |
url = f'https://docs.google.com/spreadsheets/d/{SHEET_ID}/gviz/tq?tqx=out:csv&sheet={SHEET_NAME}' | |
df = pd.read_csv(url, header=1) | |
return df.loc[:, [not x.startswith('Unnamed') for x in df.columns]] | |
def gene_list_names(): | |
df = read_google_sheet() | |
return sorted(df.columns.tolist()) |
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
class left: | |
def __rlshift__(self, df): | |
"Left align columns of data frame: df << left()" | |
left_aligned_df = df.style.set_properties(**{'text-align': 'left'}) | |
left_aligned_df = left_aligned_df.set_table_styles( | |
[dict(selector = 'th', props=[('text-align', 'left')])]) | |
display(left_aligned_df) | |
# df.head << left() |
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 math import sqrt | |
from itertools import zip_longest | |
def list_genes(words, ncols=None): | |
n = len(words) | |
col_width = max(map(len, words)) + 1 | |
if ncols is None: | |
ncols = max(100//col_width, 1+sqrt(n/col_width)) | |
nrows = int(n/ncols) + 1 | |
rows = [] |
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
for file in `find codeml/steps/codeml -name '*.txt'`; do | |
echo mv -- "$file" "$(dirname "$file")/$(basename -- "$file" .txt)_site.txt" | |
done |
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 felsenstein(tree, states): | |
# Initialize a dictionary to store the probabilities at each node | |
probabilities = {} | |
# Traverse the tree in postorder (i.e. children first, parent last) | |
for node in postorder_traverse(tree): | |
# If the node is a leaf, its probability is 1 | |
if is_leaf(node): | |
probabilities[node] = 1 | |
else: |
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 burrows_wheeler_transform(text): | |
# Create a list of all rotations of the input text | |
rotations = [text[i:] + text[:i] for i in range(len(text))] | |
# Sort the list of rotations in lexicographic order | |
rotations.sort() | |
# Return the last characters of each rotated string, which is the | |
# Burrows-Wheeler transform of the input text | |
return “”.join([rot[-1] for rot in rotations]) |
NewerOlder