Skip to content

Instantly share code, notes, and snippets.

View afrendeiro's full-sized avatar

André F. Rendeiro afrendeiro

View GitHub Profile
@afrendeiro
afrendeiro / series_matrix2csv.py
Created May 26, 2017 17:40
GEO Series matrix to project and sample annotations
def series_matrix2csv(matrix_url, prefix=None):
"""
matrix_url: gziped URL with GEO series matrix.
"""
import gzip
import pandas as pd
os.system("wget {}".format(matrix_url))
filename = matrix_url.split("/")[-1]
@afrendeiro
afrendeiro / make_tracks.py
Last active March 2, 2017 13:54
Make a UCSC trackHub from a looper.Project
from looper.models import Project
import argparse
import os
import pandas as pd
import re
import string
import textwrap
def get_colors(level, pallete="gist_rainbow", nan_color=[0.5, 0.5, 0.5]):
@afrendeiro
afrendeiro / merry_xmas.py
Created December 23, 2016 15:00
Merry Xmas by Jörg Mensche
# By Jörg Mensche
import matplotlib.pyplot as plt # basic plot functionalities
import seaborn as sns
# more advanced plotting
import scipy.stats as sc
# random number generator
# generate the x-mas tree:
all_branches = []
balls_x = []
@afrendeiro
afrendeiro / quantile_tracks.py
Created November 14, 2016 15:46
Scripts to produce Quantile bigWig files as seen in http://www.nature.com/articles/ncomms11938/figures/2
from pipelines.models import Project
import os
import pandas as pd
import pysam
# Start project
prj = Project("metadata/project_config.yaml")
prj.add_sample_sheet()
@afrendeiro
afrendeiro / enrichr.py
Created August 9, 2016 17:20
Use Enrichr's API to get enrichments of a gene set
#! /usr/bin/env python
import argparse
import pandas as pd
import json
import requests
default_gene_set_libraries = [
'GO_Biological_Process_2015',
#!/usr/bin/env python
import csv
import sys
# usage:
# samtools view -h file.bam | shift_reads.py genome | samtools view -S -b - | samtools sort - file.shifted
def getChrSizes(chrmFile):
"""
Reads tab-delimiter file with two rows describing the chromossomes and its lengths.
@afrendeiro
afrendeiro / enrichr.py
Last active May 3, 2016 09:08
Function to use Enrichr's API
def enrichr(dataframe, gene_set_libraries=None, kind="genes"):
"""
Use Enrichr on a list of genes (currently only genes supported through the API).
"""
import json
import requests
import pandas
ENRICHR_ADD = 'http://amp.pharm.mssm.edu/Enrichr/addList'
@afrendeiro
afrendeiro / mass_rename.sh
Created February 4, 2016 09:43
Mass rename files cheatsheet
# I just need to have these somewhere to remember them later
for F in `find . | grep -e 'CM[0-9]\{2,\}s'`
do
echo $F $(echo $F | sed 's/CM\([0-9]\{2,\}\)s/CM\1-/g')
mv $F $(echo $F | sed 's/CM\([0-9]\{2,\}\)s/CM\1-/g')
done
for F in `find . | grep -e '_[1-2]_' | grep -v PBMC`
do
import numpy as np
import pandas as pd
class DifferentialRegions(object):
"""
Compute two-tailed empirical p-value for difference between values of two variables.
"""
def __init__(self, df, a, b, permutations=100, alpha=0.05, correct=True):
super(DifferentialRegions, self).__init__()