Skip to content

Instantly share code, notes, and snippets.

View hanfeisun's full-sized avatar
🏕️

Hanfei Sun hanfeisun

🏕️
View GitHub Profile
@hanfeisun
hanfeisun / liulab.emacs
Created May 25, 2012 05:27
My emacs config in LiuLab
(setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin:/Applications/Racket5/bin/:/usr/texbin/"))
(setenv "CLASSPATH" ":/Users/hanfei/Documents/Sandbox/TIJ/TIJS/TIJ-3rd-edition-code")
(if x-resource-name
(progn
(set-face-attribute 'default nil :font "inconsolata-18")
))
(if (not (equal emacs-version "23.4.1"))
(progn
@hanfeisun
hanfeisun / bob.py
Created July 7, 2012 00:23
BamOnBed
import pysam
import os
t = "./865_rep1_treat.bam"
tb = "865_rep1_peaks.bed"
sorted_prefix = lambda path: path + ".sorted"
sorted_path = lambda path: sorted_prefix(path) + ".bam"
import sys
import os
from ConfigParser import SafeConfigParser
from jinja2 import Environment, PackageLoader
from chilin.qc import MappingQC, PeakcallingQC
jinja_env = env = Environment(loader=PackageLoader('chilin', 'templates'))
def check_conf(conf):
if True:
from chilin.dc import jinja_env, PathFinder
class QC_Controller(object):
def __init__(self, conf):
self.pathfinder = PathFinder(conf)
self.template = jinja_env.get_template(pathfinder.qc_template)
self.has_run = False
def run(self):
pass
def check(self):
@hanfeisun
hanfeisun / spp.py
Created July 20, 2012 01:29
spp.py
#!/usr/bin/python2.7
import os
import sys
import argparse
from math import sqrt
from collections import Counter
from itertools import tee, ifilterfalse, ifilter
import pysam
@hanfeisun
hanfeisun / bMACS.c
Created August 15, 2012 23:55
bits_extend
#include <stdio.h>
#include <stdlib.h>
#define SHIFT 4
#define MSK 0x0F
#define UNT 1
#define N 300000000
#define print(X) for (i=1;i<1+N;i++) {printf("%d\t%d\n",i,(X)[i]);}
unsigned char aln[1+N];
def create_workflow(args, conf):
"""
:type conf:ChiLinConfig
"""
root_workflow = Workflow("Main")
ShellCommand("prepare","mkdir -p {output}",output = conf.target_dir).attach_to(root_workflow)
groom_workflow = attach(root_workflow, Workflow("Groom"))
rawQC_workflow = attach(root_workflow, Workflow("RawQC"))
map_workflow = attach(root_workflow, Workflow("ReadsMapping"))
@hanfeisun
hanfeisun / gist:5377516
Created April 13, 2013 07:51
Two duplicate function
def _peaks_parse(input):
total = 0
fc20n = 0
fc10n = 0
peaks_info = {}
with open(input) as peaks_xls:
for line in peaks_xls:
if line.startswith('# tags after filtering in treatment'):
# tags after filtering in treatment: 13438948
peaks_info["uniloc"] = int(line.strip().split(":")[1])
@hanfeisun
hanfeisun / factor_parse.py
Created October 30, 2013 08:23
Factor Parser for GEO
def parseFactorByAntibody(geoPost):
targetFlds = ["CHIP_ANTIBODY", "ANTIBODY", "CHIP", "ANTIBODY_SOURCE", "ANTIBODY_ANTIBODYDESCRIPTION",
"ANTIBODY_TARGETDESCRIPTION"]
#1. try to get the values
for t in targetFlds:
tmp = getFromPost(geoPost, t).strip()
if not tmp:
continue
tmp = tmp.upper().replace("ANTI-", " ").replace("ANTI", " ").strip()
if len(tmp) < 10 and tmp != "":
@hanfeisun
hanfeisun / crack_xx.sh
Last active December 27, 2015 15:49 — forked from anonymous/gist:7350812
#!/bin/bash
sudo date 03050001
# Replace the following line with any application you need to run
open /Applications/Merriam-Webster\ 4.0/Merriam-Webster\ Dictionary.app
# sleep 60
# Set back to the current time using apple service (network needed)
sudo ntpdate -u time.apple.com