Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug for cnv input file that only has 3 columns: gene, sampleID, c… #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/subsetMaf.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ subsetMaf = function(maf, tsb = NULL, genes = NULL, fields = NULL, query = NULL,
}
}


if(restrictTo != "all"){
## (bug fix) if using "all", then merge maf.dat and maf.dat.rest
if(restrictTo == "all"){
maf.dat = rbind(maf.dat, maf.dat.rest, fill = TRUE, use.names = TRUE)
maf.silent = rbind(maf.silent, maf.silent.rest, fill = TRUE, use.names = TRUE)
}
Expand Down
42 changes: 29 additions & 13 deletions R/summarizeMaf.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,17 @@ summarizeMaf = function(maf, anno = NULL, chatty = TRUE){
vc.cast.cnv = vc.cast[,c('Tumor_Sample_Barcode', colnames(vc.cast)[colnames(vc.cast) %in% c('Amp', 'Del')]), with =FALSE]
vc.cast.cnv$CNV_total = rowSums(vc.cast.cnv[,2:ncol(vc.cast.cnv)], na.rm = TRUE)

vc.cast = vc.cast[,!colnames(vc.cast)[colnames(vc.cast) %in% c('Amp', 'Del')], with =FALSE]
vc.cast[,total:=rowSums(vc.cast[,2:ncol(vc.cast), with = FALSE])]

vc.cast = merge(vc.cast, vc.cast.cnv, by = 'Tumor_Sample_Barcode', all = TRUE)[order(total, CNV_total, decreasing = TRUE)]
## if the vc.cast only has 3 columns: Tumor_Sample_Barcode, Amp, Del
if(sum(!(colnames(vc.cast) %in% c('Amp', 'Del')))==1){
vc.cast = vc.cast.cnv
NCBI_Build = NA ## this is to NA value if input does not have NCBI info, this will prevent later summarize error
Center = NA ## same reason as NCBI_Build
} else {
vc.cast = vc.cast[,!colnames(vc.cast)[colnames(vc.cast) %in% c('Amp', 'Del')], with =FALSE]
vc.cast[,total:=rowSums(vc.cast[,2:ncol(vc.cast), with = FALSE])]

vc.cast = merge(vc.cast, vc.cast.cnv, by = 'Tumor_Sample_Barcode', all = TRUE)[order(total, CNV_total, decreasing = TRUE)]
}

vc.mean = as.numeric(as.character(c(NA, NA, NA, NA, apply(vc.cast[,2:ncol(vc.cast), with = FALSE], 2, mean))))
vc.median = as.numeric(as.character(c(NA, NA, NA, NA, apply(vc.cast[,2:ncol(vc.cast), with = FALSE], 2, median))))
Expand All @@ -72,10 +79,14 @@ summarizeMaf = function(maf, anno = NULL, chatty = TRUE){
if(any(colnames(vt.cast) %in% c('CNV'))){
vt.cast.cnv = vt.cast[,c('Tumor_Sample_Barcode', colnames(vt.cast)[colnames(vt.cast) %in% c('CNV')]), with =FALSE]

vt.cast = vt.cast[,!colnames(vt.cast)[colnames(vt.cast) %in% c('CNV')], with =FALSE]
vt.cast = vt.cast[,total:=rowSums(vt.cast[,2:ncol(vt.cast), with = FALSE])]

vt.cast = merge(vt.cast, vt.cast.cnv, by = 'Tumor_Sample_Barcode', all = TRUE)[order(total, CNV, decreasing = TRUE)]
## if vt.cast only has two columns: Tumor_Sample_Barcode, CNV
if(sum(!(colnames(vt.cast) %in% c('CNV')))==1){
vt.cast = vt.cast.cnv
} else {
vt.cast = vt.cast[,!colnames(vt.cast)[colnames(vt.cast) %in% c('CNV')], with =FALSE]
vt.cast = vt.cast[,total:=rowSums(vt.cast[,2:ncol(vt.cast), with = FALSE])]
vt.cast = merge(vt.cast, vt.cast.cnv, by = 'Tumor_Sample_Barcode', all = TRUE)[order(total, CNV, decreasing = TRUE)]
}
}else{
vt.cast = vt.cast[,total:=rowSums(vt.cast[,2:ncol(vt.cast), with = FALSE])][order(total, decreasing = TRUE)]
}
Expand All @@ -87,11 +98,16 @@ summarizeMaf = function(maf, anno = NULL, chatty = TRUE){
if(any(colnames(hs.cast) %in% c('Amp', 'Del'))){
hs.cast.cnv = hs.cast[,c('Hugo_Symbol', colnames(hs.cast)[colnames(hs.cast) %in% c('Amp', 'Del')]), with = FALSE]
hs.cast.cnv$CNV_total = rowSums(x = hs.cast.cnv[,2:ncol(hs.cast.cnv), with = FALSE], na.rm = TRUE)

hs.cast = hs.cast[,!colnames(hs.cast)[colnames(hs.cast) %in% c('Amp', 'Del')], with = FALSE]
hs.cast[,total:=rowSums(hs.cast[,2:ncol(hs.cast), with = FALSE], na.rm = TRUE)]

hs.cast = merge(hs.cast, hs.cast.cnv, by = 'Hugo_Symbol', all = TRUE)[order(total, CNV_total, decreasing = TRUE)]
##if hs.cast only has 3 columns: Hugo_Symbol, Amp, Del
if(sum(!(colnames(hs.cast) %in% c('Amp', 'Del')))==1){
hs.cast = hs.cast.cnv
colnames(hs.cast) = c("Hugo_Symbol", "Amp", "Del", "total" ) ## rename it to "total" prevent later hs.cast sorting error
} else {
hs.cast = hs.cast[,!colnames(hs.cast)[colnames(hs.cast) %in% c('Amp', 'Del')], with = FALSE]
hs.cast[,total:=rowSums(hs.cast[,2:ncol(hs.cast), with = FALSE], na.rm = TRUE)]

hs.cast = merge(hs.cast, hs.cast.cnv, by = 'Hugo_Symbol', all = TRUE)[order(total, CNV_total, decreasing = TRUE)]
}
}else{
hs.cast[,total:=rowSums(hs.cast[,2:ncol(hs.cast), with = FALSE])]
hs.cast = hs.cast[order(total, decreasing = TRUE)]
Expand Down