Genome-Model-Tools-Music
view release on metacpan or search on metacpan
lib/Genome/Model/Tools/Music/Plot/MutationRelation.pm.R view on Meta::CPAN
# Fetch command line arguments
args = commandArgs();
input_matrix = as.character(args[4]);
genes_to_plot = as.character(args[5]);
output_pdf = as.character(args[6]);
preserveGeneOrder = as.numeric(as.character(args[7]));
sort.data.frame <- function( x, by ) {
if(by[[1]] != "~")
stop("Argument 'by' must be a one-sided formula.")
## Make the formula into character and remove spaces
formc <- as.character(by[2])
formc <- gsub(" ", "", formc)
## If the first character is not + or -, add +
if(!is.element(substring(formc, 1, 1), c("+", "-")))
formc <- paste("+", formc, sep = "")
## Extract the variables from the formula
vars <- unlist(strsplit(formc, "[\\+\\-]"))
vars <- vars[vars != ""] # Remove any extra "" terms
## Build a list of arguments to pass to "order" function
calllist <- list()
pos <- 1 # Position of + or -
for(i in 1:length(vars)){
varsign <- substring(formc, pos, pos)
pos <- pos + 1 + nchar(vars[i])
if(is.factor(x[, vars[i]])){
if(varsign == "-") {
calllist[[i]] <- -rank(x[, vars[i]])
} else {
calllist[[i]] <- rank(x[, vars[i]])
}
} else {
if(varsign == "-") {
calllist[[i]] <- -x[, vars[i]]
} else {
calllist[[i]] <- x[,vars[i]]
}
}
}
return( x[do.call( "order", calllist ), ] )
}
plotMutRel <- function( infile, genes, outfile, preserveGeneOrder=FALSE) {
##------------------
a = read.table(infile,row.names=1,header=T)
gene_list = unlist(strsplit(genes, split=","))
print(genes)
df=a[,gene_list]
numSamp=length(df[,1])
numGenes=length(df)
if(numGenes < 1){
return("Error: genes to plot not found in matrix")
}
##adjustments to plot and text sizes for different numbers of samples
samptext=0.3
genetext=0.75
pdfwidth=numSamp/10
offset=2
if(numSamp < 50){
samptext=0.3
#genetext=0.85
pdfwidth=numSamp/5
offset=1.25
}
if(numSamp < 35){
samptext=0.4
}
if(pdfwidth < 3) { pdfwidth = 3 }
# if(numSamp >=100) { genetext=1.1 }
# if(numSamp >=200) { genetext=1.1 }
( run in 0.537 second using v1.01-cache-2.11-cpan-39bf76dae61 )