g3viz icon indicating copy to clipboard operation
g3viz copied to clipboard

Option to use readMAF to parse data from a data frame instead of reading from a file

Open rdmorin opened this issue 3 years ago • 1 comments

In some scenarios, the user may have a MAF already loaded into a data frame. This is the case for our workflows because MAF data is retrieved from a local database. I couldn't find an option to allow readMAF to process a data frame directly instead of relying on a file. I added this functionality but cannot create a pull request. I wonder if others might find this useful if added to the existing code:

@@ -46,24 +46,28 @@ readMAF <- function(maf.file,
                     mutation.type.to.class.df = NA,
                     sep = "\t",
                     quote = "",
+                    maf.df,
                     ...) {
-  if(missing(maf.file)){
-    stop("maf.file is missing")
+  if(missing(maf.file) & missing(maf.df)){
+    stop("maf.file and maf.dat are missing, you must provide one or the other")
   }
-
+
   # ===============================
   # TODO:
   # - check "Mutation_Status" as "Somatic"
   # ===============================
   # read data in
-  if(grepl(pattern = 'gz$', maf.file)){
-    suppressWarnings(
-      maf.df <- read.table(gzfile(description = maf.file), header = TRUE, sep = sep, quote = quote, ...)
-    )
-  } else {
-    maf.df <- read.table(maf.file, header = TRUE, sep = sep, quote = quote, ...)
+  if(missing(maf.df)){
+    if(grepl(pattern = 'gz$', maf.file)){
+      suppressWarnings(
+        maf.df <- read.table(gzfile(description = maf.file), header = TRUE, sep = sep, quote = quote, ...)
+      )
+    } else {
+      maf.df <- read.table(maf.file, header = TRUE, sep = sep, quote = quote, ...)
+    }
   }

+

rdmorin avatar Nov 29 '21 17:11 rdmorin