comparison gfapts/inc/R/samvcf_data_parser.R @ 0:f753b30013e6 draft

Uploaded
author rdaveau
date Fri, 29 Jun 2012 10:20:55 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f753b30013e6
1 rm(list=ls())
2 options(warn=-1)
3 args=commandArgs()[-c(1:4)]
4 infile=args[1]
5 outfile=sub("Temp.2R$", "var", infile)
6
7 x=read.table(infile, sep="\t", header=FALSE, row.names=NULL, colClasses=c('factor', rep('integer', 2), rep('factor', 3), rep('integer', 5), 'factor'),
8 col.names=c('chr', 'start', 'end', 'ref', 'alt', 'zyg', 'QC', 'NRF', 'NRR', 'NAF', 'NAR', 'VCF.FILTER'))
9
10 x=cbind(x, matrix(
11 as.numeric(format(sapply(1:nrow(x), function(i)
12 with(x[i, ], c(with(binom.test(c(sum(NRF, NAF), sum(NRR, NAR))), p.value),
13 with(binom.test(c(NRF, NRR)), p.value),
14 with(binom.test(c(NAF, NAR)), p.value)))), digits=3, scientific=TRUE)),
15 ncol=3, byrow=TRUE, dimnames=list(NULL, c('p.strand', 'p.ref', 'p.alt')))
16 )
17
18 x=cbind(subset((x=cbind(x, do.call('rbind', lapply(1:nrow(x), function(i) with(x[i, ], {
19 AD=sum(NAF, NAR)
20 DP=sum(NRF, NRR, AD)
21 AF=signif(AD/DP, digits=3)
22 VAR.FILTER=c(zyg!='unk' & QC>=20 & DP>=10 & AD>=5 & (p.strand>.05 | min(sum(NRF, NAF), sum(NRR, NAR))>=10) & (p.ref>.05 | min(NRF, NRR)>=10) & (p.alt>.05 | min(NAF, NAR)>=10))
23 cbind(DP,AD,AF, VAR.FILTER)
24 }))))), select=-VAR.FILTER), VAR.FILTER=with(x, factor(VAR.FILTER, levels=c(0, 1), labels=c('SKIP', 'PASS'))))
25
26 write.table(as.matrix(x), outfile, quote=FALSE, sep="\t", row.names=FALSE, col.names=FALSE)
27 q(runLast=FALSE)