Skip to content

Instantly share code, notes, and snippets.

View hanfeisun's full-sized avatar
🏕️

Hanfei Sun hanfeisun

🏕️
View GitHub Profile
def _macs2(workflow, conf):
# merge all treatments into one
merge_bams_treat = ShellCommand(
"{tool} merge {output[merged]} {param[bams]}",
tool="samtools",
input=[target + ".bam" for target in conf.treatment_targets],
output={"merged": conf.prefix + "_treatment.bam"})
merge_bams_treat.param = {"bams": " ".join(merge_bams_treat.input)}
if len(conf.treatment_targets) > 1:
def _macs2(workflow, conf):
# merge all treatments into one
merge_bams_treat = ShellCommand(
"{tool} merge {output[merged]} {param[bams]}",
tool="samtools",
input=[target + ".bam" for target in conf.treatment_targets],
output={"merged": conf.prefix + "_treatment.bam"})
merge_bams_treat.param = {"bams": " ".join(merge_bams_treat.input)}
if len(conf.treatment_targets) > 1:
def _bowtie(workflow, conf):
for target in conf.sample_targets:
bowtie = attach_back(workflow,
ShellCommand(
"{tool} -p {param[threads]} -S -m {param[max_align]} \
{param[genome_index]} {input[fastq]} {output[sam]} 2> {output[bowtie_summary]}",
input={"genome_dir": os.path.dirname(conf.get_path("lib", "genome_index")),
"fastq": target + ".fastq"},
output={"sam": target + ".sam",
"bowtie_summary": target + "_bowtie_summary.txt", },
CLASS1 = ["BMAL1-ZT10_rep1", "BMAL1-ZT10_rep2"]
CLASS1_PATHS = ["/mnt/Storage/data/exam_data/BMAL1/BMAL1-ZT10_rep1.bam", "/mnt/Storage/data/exam_data/BMAL1/BMAL1-ZT10_rep2.bam"]
CLASS2 = ["BMAL1-ZT22_rep1"]
CLASS2_PATHS = ["/mnt/Storage/data/exam_data/BMAL1/BMAL1-ZT22_rep1.bam"]
GTF = "/mnt/Storage/data/RefGene/mm9.gtf"
SAMPLES = CLASS1 + CLASS2
def update_one_sample(gsmid, parse_fields=['other_ids', 'paper', 'name', 'species', 'description', 'antibody', 'factor',
'cell type', 'cell line', 'tissue', 'strain']):
"""Given a gsmid, tries to create a new sample--auto-filling in the
meta fields
If overwrite is True and there is the sample that has the same gsmid, this function will overwrite that sample
NOTE: will try to save the sample!!
@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
@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 / 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])
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 / 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];