Skip to content

Instantly share code, notes, and snippets.

@rhngla
rhngla / 00-gene-ensembl.py
Last active January 22, 2024 22:40
gget to search for Ensembl ids of gene names
# Some gene names have aliases; those can be found using gget.
import gget
import pandas as pd
gene_list = ['1190002N15Rik', '1700019L22Rik', '1700086L19Rik', '2610100L16Rik', '2900055J20Rik', '2900092D14Rik', '3110035E14Rik', '5031426D15Rik', '5930412G12Rik', '6330403A02Rik', '6430573F11Rik', 'A230070E04Rik', 'A330050F15Rik', 'AF529169', 'Ak3l2-ps', 'Apitd1', 'BC030499', 'BC048546', 'Bai2', 'Cecr6', 'Ctgf', 'Cxx1a', 'E130012A19Rik', 'E530001K10Rik', 'Epb4.1', 'Epb4.1l4a', 'Fam150b', 'Fam196a', 'Fam19a1', 'Fam19a2', 'Fam19a5', 'Fam212b', 'Fam46a', 'Fam84a', 'Fam84b', 'Gad1-ps', 'Gpr123', 'Gpr125', 'Gpr126', 'Gpr133', 'Gucy1a3', 'Hrasls', 'Hyi', 'I830012O16Rik', 'LOC100503338', 'LOC101056001', 'LOC102632463', 'LOC102633357', 'LOC102633724', 'LOC102634132', 'LOC102634502', 'LOC102635502', 'LOC102636041', 'LOC102636700', 'LOC102638670', 'LOC102638890', 'LOC102640573', 'LOC102643175', 'LOC105242578', 'LOC105242710', 'LOC105242740', 'LOC105243130', 'LOC105243282', 'LOC105243425', 'LOC105243542', 'LOC105244000',
@rhngla
rhngla / GO_terms.csv
Last active August 8, 2023 17:50
Pathways and Genes
GO_id description
GO:0006623 protein targeting to vacuole
GO:0006626 protein targeting to mitochondrion
GO:0006627 protein processing involved in protein targeting to mitochondrion
GO:0006672 ceramide metabolic process
GO:0031647 regulation of protein stability
GO:0006744 ubiquinone biosynthetic process
GO:0006734 NADH metabolic process
GO:0006783 heme biosynthetic process
GO:0006506 GPI anchor biosynthetic process
@rhngla
rhngla / TreeLengths.m
Created July 8, 2020 19:31
Calculate tree lengths for trees in the graph specified by (AM,r)
function tree_lengths=TreeLengths(AM,r)
%Returns total length measured for each of the L trees defined by the labeled adjacency matrix.
%Inputs:
% AM : (NxN) matrix labeled adjacency matrix (assumed symmetric)
% r : (Nx3) position vector for the N nodes
%Outputs:
% tree_lengths : (1xL)
AMlbl_direct=triu(AM,1);
tree_labels=unique(AMlbl_direct(AMlbl_direct>0));
@rhngla
rhngla / pathlib_examples.py
Created July 3, 2020 19:49
pathlib examples
#Some simple file IO related operations
from pathlib import Path
#Below takes care of os based differences
dir_name = '/Users/Fruity/Local/datasets'
file_name = 'CTX_Hip_10x_counts.h5'
dir_path = Path(dir_name)
#Use forward slashes to combine path
sudo apt-get install imagemagick
convert -delay 200 -loop 0 *.png output.gif
#Order of files as specified in file_list.txt
convert -delay 20 @file_list.txt -loop 0 animation.gif
@rhngla
rhngla / CCA_extended.py
Last active March 25, 2020 07:06
Extend the CCA class of scikit-learn to return reconstructions of the Y as well.
from sklearn.cross_decomposition import CCA
from sklearn.utils import check_array
from sklearn.utils.validation import check_is_fitted, FLOAT_DTYPES
class CCA_extended(CCA):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
return
@rhngla
rhngla / tricks.py
Last active June 27, 2019 23:42
Python tricks
#Ref: http://akuederle.com/create-numpy-array-with-for-loop
import numpy as np
n_results_per_iter = 4
result_array = np.empty((0, n_results_per_iter))
for iter in [1,2,3]:
result_this_iter = np.array([0,1,2,3])
result_array = np.append(result_array, [result_this_iter], axis=0)
#Slicing rows and columns from a matrix simultaneously. The key is to use broadcasting.
@rhngla
rhngla / startupscript.py
Last active July 27, 2022 23:04
IPython startup script
#File will be executed for every new instance of ipython
#Place file in: ~/.ipython/profile_default/startup/startupscript.py
print('loading packages and magics from ~/.ipython/profile_default/startup/startupscript.py')
from IPython import get_ipython
get_ipython().run_line_magic("load_ext","autoreload")
print('%load_ext autoreload')
get_ipython().run_line_magic("autoreload", "2")
print('%autoreload 2')