Created
January 28, 2016 16:03
-
-
Save cmdcolin/953412ce5902f7df8023 to your computer and use it in GitHub Desktop.
template length graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript | |
# usage: | |
# samtools view your_file.bam | cut -f3,4,9 > pre_bedgraph.txt | |
# tlengraph pre_bedgraph.txt output.bg | |
# bedGraphToBigWig output.bg chrom.sizes output.bw | |
library("ggplot2") | |
library("data.table") | |
#disable scientific notition in write.table | |
options(scipen=999) | |
args<-commandArgs(TRUE) | |
# use data.table to read file (format: chr, start pos, template length) | |
DT<-fread(args[1]) | |
# take abs() of template length | |
DT$V3=abs(DT$V3) | |
# make bigwig spikes of length 1 | |
DT2=data.table(DT$V1,DT$V2,DT$V2+1,DT$V3) | |
# sort by chr and start pos | |
setkeyv(DT2,c("V1","V2")) | |
# only take unique values | |
DT3=unique(DT2, by=c("V1", "V2")) | |
# write bedgraph | |
write.table(DT3,args[2],sep="\t",row.names=F,col.names=F,quote=F) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment