Skip to content

Instantly share code, notes, and snippets.

View nimezhu's full-sized avatar

Zhu Xiaopeng nimezhu

View GitHub Profile
@nimezhu
nimezhu / RNA2D.js
Created May 6, 2014 21:58
RNA Visualization Demo
/**
* Created with JetBrains WebStorm.
* User: zhuxp
* Date: 13-4-21
* To change this template use File | Settings | File Templates.
*/
function parseStems(ss)
{
@nimezhu
nimezhu / NCI-H209.copynumber.tab
Created May 6, 2014 22:57
Haplotype Allele Block Viewer ( python matplotlib )
chr1 61735 7035990 CopyNumberRegion_0 2 0
chr1 7036801 7974076 CopyNumberRegion_1 3 0
chr1 7975788 29271013 CopyNumberRegion_2 2 0
chr1 29275883 30265652 CopyNumberRegion_3 4 2
chr1 30271899 31334415 CopyNumberRegion_4 6 2
chr1 31336903 41403766 CopyNumberRegion_5 7 2
chr1 41405663 42601214 CopyNumberRegion_6 4 2
chr1 42602991 44503629 CopyNumberRegion_7 6 2
chr1 44507772 48809180 CopyNumberRegion_8 2 0
chr1 48810111 48824773 CopyNumberRegion_9 7 1
#for i in chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrX chrY chrM
for i in chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chrX chrY chrM
do
echo "samtools mpileup -uf ../hg19.fna ../Mapping/$i.v2.sorted.bam | bcftools view -bvcg - > test_$i.var.raw.bcf"
echo "bcftools view test_$i.var.raw.bcf | vcfutils.pl varFilter -D100000 > test_$i.vcf"
echo "vcf2var.pl test_$i.vcf > test_$i.variants"
echo "samtools view ../Mapping/$i.v2.sorted.bam | extract_hairs --sam stdin --variants test_$i.variants > test_$i.fragments"
done
@nimezhu
nimezhu / myVennDiagram.R
Created May 6, 2014 22:57
Venn Diagram and Scatter Plot (R)
venn.overlap <-
function(r, a, b, target = 0)
{
#
# calculate the overlap area for circles of radius a and b
# with centers separated by r
# target is included for the root finding code
#
pi = acos(-1)
if(r >= a + b) {
@nimezhu
nimezhu / checkFastq.sh
Created May 6, 2014 22:58
check Fastq ( Phred+33 or Phred+64 ) ( shell script )
#!/bin/sh
inputfile=$1
# you can add friendly code to check the extension and use zcat if it's *.fastq.gz or *.fq.gz...
[[ "$inputfile" =~ ".*\.(fq\.gz$|fastq\.gz$)" ]] && zcat $inputfile | head -n400 | awk '{if(NR%4==0) printf("%s",$0);}' | od -A n -t u1 | awk 'BEGIN{min=100;max=0;}{for(i=1;i<=NF;i++) {if($i>max) max=$i; if($i<min) min=$i;}}END{if(max<=74 && min<59) print "Phred+33"; else if(max>73 && min>=64) print "Phred+64"; else if(min>=59 && min<64 && max>73) print "Solexa+64"; else print "Unknown score encoding!";}'
[[ "$inputfile" =~ ".*\.(fq$|fastq$)" ]] && head -n400 $inputfile | awk '{if(NR%4==0) printf("%s",$0);}' | od -A n -t u1 | awk 'BEGIN{min=100;max=0;}{for(i=1;i<=NF;i++) {if($i>max) max=$i; if($i<min) min=$i;}}END{if(max<=74 && min<59) print "Phred+33"; else if(max>73 && min>=64) print "Phred+64"; else if(min>=59 && min<64 && max>73) print "Solexa+64"; else print "Unknown score encoding!";}'
@nimezhu
nimezhu / contamination_test.sh
Created May 6, 2014 22:58
fastq file test ( contributed by Yang Zhang )
#!/bin/bash
if [ $# -lt 1 ]
then
echo "USAGE: test_contamination.sh <fastq_file>"
exit 0
fi
# modify the following parameters as needed
Sample_Size=5000000
@nimezhu
nimezhu / gtfIO.py
Created May 6, 2014 22:59
gtf IO, contributed by Guifeng Wei ( using xplib )
#!/usr/bin/python
# Wei Guifeng, <guifengwei@gmail.com>
# Revised By zhuxp <nimezhu@gmail.com>
# -- coding: utf-8 --
'''
Gencode annotation or Cufflinks transcript.gtf
usage:
for gene in TableIO.parse("cufflinks.transcript.gtf", 'gtf'):
print "{0}\t{1}\t{2}".format(gene.chr, gene.strand, (gene.stop - gene.start))
@nimezhu
nimezhu / Causality.js
Last active August 29, 2015 14:01
Causal Network Visualization
$(function() {
Backbone.sync = function(method, model, success, error){
success();
}
CausalityView = Backbone.View.extend({
el: $('body'), // el attaches to existing element
attributes: {"width":900,"height":700},
events: {
'change #csv': 'render',
@nimezhu
nimezhu / barchart_demo.py
Created May 7, 2014 00:26
python demo [ matplotlib sqlite and pipe]
#!/usr/bin/env python
# a bar plot with errorbars
import numpy as np
import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)
ind = np.arange(N) # the x locations for the groups
@nimezhu
nimezhu / README.md
Last active August 29, 2015 14:01
query ends to report

##TSS(TTS) POSITION CLASSIFIED

HITS : distance < 10
SHIFT : 10<= distance < 50
ALT_E : 50 < distance and peak in Exon
ALT_E : 50 < distance and peak in Intron

COL14 for gene: number of tss, repr string, number of tts