[Genabel-commits] r1622 - pkg/GenABEL/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Feb 23 23:13:03 CET 2014


Author: lckarssen
Date: 2014-02-23 23:13:03 +0100 (Sun, 23 Feb 2014)
New Revision: 1622

Modified:
   pkg/GenABEL/R/mach2databel.R
Log:
Brought GenABEL's mach2databel.R up to our coding standards (spaces after coma's, TRUE/FALSE instead of T/F, no spaces at EOL, etc.)


Modified: pkg/GenABEL/R/mach2databel.R
===================================================================
--- pkg/GenABEL/R/mach2databel.R	2014-02-23 22:07:57 UTC (rev 1621)
+++ pkg/GenABEL/R/mach2databel.R	2014-02-23 22:13:03 UTC (rev 1622)
@@ -1,87 +1,99 @@
 #'
 #' converts MACH-imputed files to DatABEL (filevector) format
-#' 
-#' This function converts mach-imputed files to \code{DatABEL} (filevector) format.
-#' After conversion, two files (outfile.fvi and outfile.fvd), corresponding 
-#' to single filevector object, will appear on the disk; 'databel-class' 
+#'
+#' This function converts mach-imputed files to \code{DatABEL} (filevector)
+#' format.
+#' After conversion, two files (outfile.fvi and outfile.fvd), corresponding
+#' to single filevector object, will appear on the disk; 'databel-class'
 #' object connected to these files will be returned to R
-#' 
+#'
 #' @param imputedgenofile MACH mldose (or mlprob) file name
 #' @param mlinfofile MACH mlinfo file name
 #' @param outfile output file name
-#' @param isprobfile whether imputedgenofile is a prob-file 
-#' (default is FALSE, that is dose-file assumed) 
+#' @param isprobfile whether imputedgenofile is a prob-file
+#' (default is FALSE, that is dose-file assumed)
 #' @param dataOutType the output data type, either "FLOAT" or "DOUBLE" (or
-#'        other DatABEL/filevector type) 
-#' 
+#'        other DatABEL/filevector type)
+#'
 #' @return databel-class object
-#' 
+#'
 #' @author Yurii Aulchenko
-#' 
+#'
 #' @keywords IO manip
-#' 
-#' 
+#'
+#'
 
 
-mach2databel <- function(imputedgenofile,mlinfofile,outfile,
-                         isprobfile=FALSE, dataOutType = "FLOAT") 
+mach2databel <- function(imputedgenofile, mlinfofile, outfile,
+                         isprobfile=FALSE, dataOutType = "FLOAT")
 {
-	if (!require(DatABEL))
-		stop("this function requires DatABEL package to be installed")
-	if (missing(imputedgenofile))
-		stop("mldose file must be specified")
-	if (missing(outfile)) outfile <- imputedgenofile
-    if (dataOutType != "FLOAT") 
-        warning("The non-float dataOutType os not fully supported; your outputs may be in 'FLOAT'...",
+    if (!require(DatABEL)) {
+        stop("this function requires DatABEL package to be installed")
+    }
+
+    if (missing(imputedgenofile)) {
+        stop("mldose file must be specified")
+    }
+
+    if (missing(outfile)) {
+        outfile <- imputedgenofile
+    }
+
+    if (dataOutType != "FLOAT") {
+        warning(paste0("The non-float dataOutType os not fully supported;",
+                       " your outputs may be in 'FLOAT'..."),
                 immediate. = TRUE);
-# extract snp names (varnames)
-	tmpname <- ""
-	if (!missing(mlinfofile))
-	{
-		tmp <- scan(mlinfofile,what="character",skip=1)
-		tmp <- tmp[c(T,F,F,F,F,F,F)]
-		#print(tmp[1:10])
-		tmpname <- get_temporary_file_name()
-		if (isprobfile) {
-			tmp2 <- rep("missing",length(tmp)*2)
-			tmp2[c(T,F)] <- paste(tmp,"_11",sep="")
-			tmp2[c(F,T)] <- paste(tmp,"_01",sep="")
-			tmp <- tmp2
-		}
-		write(tmp,file=tmpname)
-		rm(tmp);gc()
-	} else 
-		warning("mlinfo file not specified, you will not be able to use snp names (only index)")
-	
-	if (tmpname != "")
-		dfaobj <- text2databel(infile=imputedgenofile,outfile=outfile,
-				colnames=tmpname,
-				rownames=1,skipcols=2,
-				#skiprows,
-				transpose=FALSE,R_matrix=FALSE,
-                                       type = dataOutType, readonly = FALSE)
-	else 
-		dfaobj <- text2databel(infile=imputedgenofile,outfile=outfile,
-				rownames=1,skipcols=2,
-				#skiprows,
-				transpose=FALSE,R_matrix=FALSE,
-                                       type = dataOutType, readonly = FALSE)
+    }
 
-	dnames <- get_dimnames(dfaobj)
-	subjs <- dnames[[1]]
-	#print(subjs[1:10])
-	subjs <- sub("[0-9]*->","",subjs)
-	#print(subjs[1:10])
-	#print(dim(dfaobj))
-	#print(length(subjs))
-	dimnames(dfaobj) <- list(subjs,dnames[[2]])
-	#print(dimnames(dfaobj)[[1]][1:5])
-	
-	if (tmpname != "") {
-		unlink(paste(tmpname,"*",sep=""))
-	}
-	
-	#disconnect(dfaobj)
-	#connect(dfaobj)
-	return(dfaobj)
+    ## extract snp names (varnames)
+    tmpname <- ""
+    if (!missing(mlinfofile)) {
+        tmp <- scan(mlinfofile, what="character", skip=1)
+        tmp <- tmp[c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)]
+                                        #print(tmp[1:10])
+        tmpname <- get_temporary_file_name()
+        if (isprobfile) {
+            tmp2 <- rep("missing", length(tmp)*2)
+            tmp2[c(TRUE, FALSE)] <- paste(tmp, "_11", sep="")
+            tmp2[c(FALSE, TRUE)] <- paste(tmp, "_01", sep="")
+            tmp <- tmp2
+        }
+        write(tmp, file=tmpname)
+        rm(tmp);gc()
+    } else
+        warning(paste0("mlinfo file not specified, you will not be ",
+                       "able to use snp names (only index)"))
+
+    if (tmpname != "") {
+        dfaobj <- text2databel(infile=imputedgenofile, outfile=outfile,
+                               colnames=tmpname,
+                               rownames=1, skipcols=2,
+                                        #skiprows,
+                               transpose=FALSE, R_matrix=FALSE,
+                               type = dataOutType,  readonly = FALSE)
+    } else {
+        dfaobj <- text2databel(infile=imputedgenofile, outfile=outfile,
+                               rownames=1, skipcols=2,
+                                        #skiprows,
+                               transpose=FALSE, R_matrix=FALSE,
+                               type = dataOutType, readonly = FALSE)
+    }
+
+    dnames <- get_dimnames(dfaobj)
+    subjs <- dnames[[1]]
+    #print(subjs[1:10])
+    subjs <- sub("[0-9]*->", "", subjs)
+    #print(subjs[1:10])
+    #print(dim(dfaobj))
+    #print(length(subjs))
+    dimnames(dfaobj) <- list(subjs, dnames[[2]])
+    #print(dimnames(dfaobj)[[1]][1:5])
+
+    if (tmpname != "") {
+        unlink(paste(tmpname, "*", sep=""))
+    }
+
+    # disconnect(dfaobj)
+    # connect(dfaobj)
+    return(dfaobj)
 }



More information about the Genabel-commits mailing list