PoisonAlien / maftools

Summarize, Analyze and Visualize MAF files from TCGA or in-house studies.
http://bioconductor.org/packages/release/bioc/html/maftools.html
MIT License
450 stars 222 forks source link

change Tumor_Sample_Barcode for gisticOncoPlot #1004

Closed dansteiert closed 9 months ago

dansteiert commented 9 months ago

Hi all,

I had an issue, where I wanted to change the Tumor_Sample_Barcode of my gistic object for the gisticOncoPlot.

I found after a look into the code, that it is not like in a maf object the maf@data$Tumor_Sample_Barcode which needs changing but the column names of gistic@numericMatrix and gistic@cnMatrix. One of the two might also work -> better safe then sorry though.

Here I wrote a function in case somebody else runs into a similar problem and does not know where to look for an awnser.

rename_Tumor_Sample_Barcode = function(gistic, rename_func){
  new_colname_cnMatrix = rename_func(colnames(gistic@cnMatrix))
  new_colname_numericMatrix = rename_func(colnames(gistic@numericMatrix))
  new_TSB = rename_func(gistic@data$Tumor_Sample_Barcode)

  colnames(gistic@cnMatrix) = new_colname_cnMatrix
  colnames(gistic@numericMatrix) = new_colname_numericMatrix
  gistic@data$Tumor_Sample_Barcode = as.factor(new_TSB)
  return (gistic)

}

My rename_func is quite ugly and needs the respectiv customization, but for me it looked like this:

rename_func = function(v){
  new_colname = c()
  for (i in v){
    if (grepl("LYFR",  i)){
        new_colname = c(new_colname, paste(c(unlist(strsplit(SplitPath(i)$filename, "_"))[c(1, 2, 3, 4)]), collapse="_"))
    }else{
    new_colname = c(new_colname, paste(c(unlist(strsplit(SplitPath(i)$filename, "_"))[c(1, 2, 3)]), collapse="_"))

    }
  }
  return (new_colname)
}
dansteiert commented 9 months ago

Something similar also applies for the maf object:

rename_Tumor_Sample_Barcode_mafObj = function(maf, rename_func){
  maf@clinical.data$Tumor_Sample_Barcode = as.factor(rename_func(maf@clinical.data$Tumor_Sample_Barcode))
  maf@variants.per.sample$Tumor_Sample_Barcode = as.factor(rename_func(maf@variants.per.sample$Tumor_Sample_Barcode))
  maf@variant.classification.summary$Tumor_Sample_Barcode = as.factor(rename_func(maf@variant.classification.summary$Tumor_Sample_Barcode))
  maf@maf.silent$Tumor_Sample_Barcode = as.factor(rename_func(maf@maf.silent$Tumor_Sample_Barcode))
  maf@data$Tumor_Sample_Barcode = as.factor(rename_func(maf@data$Tumor_Sample_Barcode))
  return (maf)

}