Skip to content

Instantly share code, notes, and snippets.

@sonali-bioc
sonali-bioc / cnv-CNAnorm.R
Last active January 27, 2016 13:31
Detect CNV using Bioconductor package CNAnorm
library(CNAnorm)
library(RUnit)
#outside R session - convert perl file
##perl bam2windows.pl "tumorA.chr4.bam" "normalA.chr4.bam" > perloutput.txt
test_counts <- function(chr4data)
{
test_indices <- c(8000001, 8010001,10000001 , 10010001, 1000001)
test_res <- c(67,62,67,74,47) #from samtools
@sonali-bioc
sonali-bioc / cnv-testCounts.R
Last active August 29, 2015 13:56
Check the counts calculated by each of the methods
## Our motivation for this gist comes from the fact that we would like
## to check the counts calculated by each of the methods.
## Here we provide a simple unitTest which takes as input a GRanges
## object which contains the reads from the "tumorA.chr4.bam" file.
## we choose 5 regions and get their counts from samtools using a simple
## command :
## samtools view tumorA.chr4.bam chr4:8000001-8010000 | wc -l 67
library(cn.mops)
library(RUnit)
tumor_gr <- getReadCountsFromBAM("tumorA.chr4.bam",
refSeqName="chr4",WL=10000,mode="unpaired")
normal_gr <- getReadCountsFromBAM("normalA.chr4.bam",
refSeqName="chr4",WL=10000,mode="unpaired")
ref_analysis_norm0 <- referencecn.mops(tumor_gr, normal_gr,norm=0)
library(GenomicAlignments)
library(RUnit)
cnv_countOverlaps <-
function(bamfilename, chrom, binSize=10000)
{
bf <- BamFile(bamfilename)
aln<- readGAlignments(bf)
sub <- resize(granges(aln), width=1)
tiles <- tileGenome(seqlengths(bf), tilewidth=binSize,
@sonali-bioc
sonali-bioc / plotbinnedCounts.R
Created February 4, 2014 00:31
use pshannon-bioc / binnedCounts.R and plot the counts for Tumor and Normal Sample Data
plotbinnedCounts <- function(filename, tumor, normal, ylim )
{
y1 <- tumor
y2 <- normal
png(file= filename, bg="white")
plot( y1,
col="red",
xlab= "bins",
ylab =" reads",
ylim =ylim )