diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0589549 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "master" + ] +} \ No newline at end of file diff --git a/R/keggview.graph.R b/R/keggview.graph.R index 750fa41..d77b833 100644 --- a/R/keggview.graph.R +++ b/R/keggview.graph.R @@ -8,6 +8,7 @@ keggview.graph <-function( pathway.name, out.suffix="pathview", pdf.size=c(7,7), + output.dir = ".", multi.state=TRUE, same.layer=TRUE, @@ -276,9 +277,13 @@ if(multi.state) { if(sum(cpd.idx)>0) ell.col.plot=ell.col } -for(np in 1:nplots){ - gfile=paste(pathway.name, pn.suffix[np],"pdf", sep=".") -# gfile=paste(pathway.name, pn.suffix[1],"pdf", sep=".") +for(np in 1:nplots) { + if (!dir.exists(output.dir)) { + warning("Specified output directory ", output.dir, " does not exist. Saved images in working directory.") + output.dir = "." + } + gfile <- file.path(output.dir, paste(pathway.name, pn.suffix[np], "pdf", sep = ".")) + out.msg=sprintf(out.fmt, gfile) message("Info: ", out.msg) diff --git a/R/keggview.native.R b/R/keggview.native.R index 9e946da..89a8626 100644 --- a/R/keggview.native.R +++ b/R/keggview.native.R @@ -8,8 +8,10 @@ function( pathway.name, out.suffix="pathview", kegg.dir=".", + output.dir = ".", multi.state=TRUE, + multi.labels="", match.data=TRUE, same.layer=TRUE, # res=300, # @@ -82,7 +84,12 @@ if(multi.state) { for(np in 1:nplots){ #plot setup - img.file =paste(pathway.name,pn.suffix[np],"png", sep=".") + if (!dir.exists(output.dir)) { + warning("Specified output directory ", output.dir, " does not exist. Saved images in working directory.") + output.dir = "." + } + img.file <- file.path(output.dir, paste(pathway.name, pn.suffix[np], "png", sep = ".")) + out.msg=sprintf(out.fmt, img.file) message("Info: ", out.msg) png(img.file, width = width, height = height, res=res) @@ -122,6 +129,9 @@ if(!is.null(cols.ts.cpd) & nc.cpd>=np){ off.sets=c(x=0,y=0) align="n" +if (multi.state & length(multi.labels) > 0) + text(x = 30, y = height - 15, labels = paste(multi.labels, collapse = "|"), pos = 4, cex = 0.25) + # na.col=colorpanel2(1, low=na.col, high=na.col) ucol.gene=unique(as.vector(cols.ts.gene)) na.col.gene=ucol.gene %in% c(na.col, NA) diff --git a/R/pathview.R b/R/pathview.R index 2c7adbc..7eec004 100644 --- a/R/pathview.R +++ b/R/pathview.R @@ -6,6 +6,7 @@ function( pathway.id, species = "hsa", kegg.dir=".", + output.dir = ".", cpd.idtype="kegg", gene.idtype="entrez", gene.annotpkg=NULL, @@ -252,9 +253,9 @@ function( } else plot.data.cpd=cols.ts.cpd=NULL if(kegg.native){ - pv.pars= keggview.native(plot.data.gene=plot.data.gene, cols.ts.gene=cols.ts.gene, plot.data.cpd=plot.data.cpd, cols.ts.cpd=cols.ts.cpd, node.data=node.data, pathway.name=pathway.name[i], kegg.dir=kegg.dir, limit=limit, bins=bins, both.dirs=both.dirs,discrete=discrete, low=low, mid=mid, high=high, na.col=na.col, ...) + pv.pars= keggview.native(plot.data.gene=plot.data.gene, cols.ts.gene=cols.ts.gene, plot.data.cpd=plot.data.cpd, cols.ts.cpd=cols.ts.cpd, node.data=node.data, pathway.name=pathway.name[i], kegg.dir=kegg.dir, output.dir = output.dir, limit=limit, bins=bins, both.dirs=both.dirs,discrete=discrete, low=low, mid=mid, high=high, na.col=na.col, ...) } else{ - pv.pars= keggview.graph(plot.data.gene=plot.data.gene, cols.ts.gene=cols.ts.gene, plot.data.cpd=plot.data.cpd, cols.ts.cpd=cols.ts.cpd, node.data=node.data, path.graph=gR1, pathway.name=pathway.name[i], map.cpdname=map.cpdname, split.group=split.group, limit=limit, bins=bins, both.dirs=both.dirs, discrete=discrete, low=low, mid=mid, high=high, na.col=na.col, ...) + pv.pars= keggview.graph(plot.data.gene=plot.data.gene, cols.ts.gene=cols.ts.gene, plot.data.cpd=plot.data.cpd, cols.ts.cpd=cols.ts.cpd, node.data=node.data, path.graph=gR1, pathway.name=pathway.name[i], map.cpdname=map.cpdname, split.group=split.group, limit=limit, bins=bins, both.dirs=both.dirs, discrete=discrete, low=low, mid=mid, high=high, na.col=na.col, output.dir = output.dir, ...) } plot.data.gene=cbind(plot.data.gene, cols.ts.gene) diff --git a/man/pathview.Rd b/man/pathview.Rd index 93fb647..3c6fa49 100644 --- a/man/pathview.Rd +++ b/man/pathview.Rd @@ -21,7 +21,7 @@ interface to downloader, parser, mapper and viewer functions. } \usage{ pathview(gene.data = NULL, cpd.data = NULL, pathway.id, -species = "hsa", kegg.dir = ".", cpd.idtype = "kegg", gene.idtype = +species = "hsa", kegg.dir = ".", output.dir = ".", cpd.idtype = "kegg", gene.idtype = "entrez", gene.annotpkg = NULL, min.nnodes = 3, kegg.native = TRUE, map.null = TRUE, expand.node = FALSE, split.group = FALSE, map.symbol = TRUE, map.cpdname = TRUE, node.sum = "sum", discrete=list(gene=FALSE, @@ -93,6 +93,9 @@ character, the directory of KEGG pathway data file (.xml) and image file naming convention of KEGG's (species code + pathway id, e.g. hsa04110.xml, hsa04110.png etc) in this directory. Default kegg.dir="." (current working directory). +} + \item{output.dir}{ +character, the directory for the output (.png or .pdf). Default output.dir = "." (current working directory) } \item{cpd.idtype}{ character, ID type used for the cpd.data. Default cpd.idtype="kegg" (include @@ -132,7 +135,7 @@ logical, whether the multiple-gene nodes are expanded into single-gene nodes. Each expanded single-gene nodes inherits all edges from the original multiple-gene node. This option only affects graphviz graph view, i.e. when kegg.native=FALSE. This option is not effective for most metabolic -pathways where it conflits with converting reactions to edges. Default expand.node=FLASE. +pathways where it conflits with converting reactions to edges. Default expand.node=FALSE. } \item{split.group}{ logical, whether split node groups are split to individual nodes. Each @@ -141,8 +144,8 @@ option only affects graphviz graph view, i.e. when kegg.native=FALSE. This option also effects most metabolic pathways even without group nodes defined orginally. For these pathways, genes involved in the same reaction are grouped automatically when -converting reactions to edges unless split.group=TRUE. d -split.group=FLASE. +converting reactions to edges unless split.group=TRUE. Default +split.group=FALSE. } \item{map.symbol}{ logical, whether map gene IDs to symbols for gene node labels or use the @@ -165,7 +168,7 @@ kept. Default map.cpdname=TRUE. \item{discrete}{ a list of two logical elements with "gene" and "cpd" as the names. This argument tells whether gene.data or cpd.data should be treated as -discrete. Default dsicrete=list(gene=FALSE, cpd=FALSE), i.e. both data should +discrete. Default discrete=list(gene=FALSE, cpd=FALSE), i.e. both data should be treated as continuous. } \item{limit}{ @@ -179,18 +182,18 @@ directional data. Default limit=list(gene=1, cpd=1). \item{bins}{ a list of two integer elements with "gene" and "cpd" as the names. This argument specifies the number of levels or bins for gene.data and cpd.data when converting -them to pseudo colors. Default limit=list(gene=10, cpd=10). +them to pseudo colors. Default bins=list(gene=10, cpd=10). } \item{both.dirs}{ a list of two logical elements with "gene" and "cpd" as the names. This argument specifies whether gene.data and cpd.data are 1 directional or 2 -directional data when converting them to pseudo colors. Default limit=list(gene=TRUE, cpd=TRUE). +directional data when converting them to pseudo colors. Default both.dirs=list(gene=TRUE, cpd=TRUE). } \item{trans.fun}{ a list of two function (not character) elements with "gene" and "cpd" as the names. This argument specifies whether and how gene.data and cpd.data are transformed. Examples are \code{log}, \code{abs} or users' own -functions. Default limit=list(gene=NULL, cpd=NULL). +functions. Default trans.fun=list(gene=NULL, cpd=NULL). } \item{low, mid, high}{ each is a list of two colors with "gene" and "cpd" as the names. This @@ -204,7 +207,7 @@ The values for 'low, mid, high' can be given as color names ("\#FF0000"=red). } \item{na.col}{ -color used for NA's or missing values in gene.data and cpd.data. d +color used for NA's or missing values in gene.data and cpd.data. Default na.col="transparent". } \item{\dots}{ @@ -216,7 +219,7 @@ special arguments for keggview.native or keggview.graph function. data.frame returned by node.map function for rendering mapped gene nodes, including node name, type, positions (x, y), sizes (width, height), and mapped gene.data. This data is also used as input for - pseduo-color coding through node.color function. Default plot.data.gene=NULL. + pseudo-color coding through node.color function. Default plot.data.gene=NULL. } \item{plot.data.cpd}{ same as plot.data.gene function, except for mapped compound node data. d @@ -257,7 +260,7 @@ character, the suffix to be added after the pathway name as part of the paired. Default match.data=TRUE. When let sample sizes of gene.data and cpd.data be m and n, when m>n, extra columns of NA's (mapped to no color) will be added to cpd.data as to make the sample size the - same. This will result in the smae number of slice in gene nodes and + same. This will result in the same number of slice in gene nodes and compound when multi.state=TRUE. } \item{same.layer}{ @@ -292,15 +295,15 @@ character, controlling how the color keys are aligned when both by x coordinates, and "y", aligned by y coordinates. Default key.align="x". } \item{key.pos}{ -character, controlling the position of color key(s). Potentail values - are "bottomleft", "bottomright", "topleft" and "topright". d +character, controlling the position of color key(s). Potential values + are "bottomleft", "bottomright", "topleft" and "topright". Default key.pos="topright". } \item{sign.pos}{ character, controlling the position of pathview signature. Only effective when kegg.native=FALSE, Signature position is fixed in place - of the original KEGG signature when kegg.native=TRUE. Potentail values - are "bottomleft", "bottomright", "topleft" and "topright". d + of the original KEGG signature when kegg.native=TRUE. Potential values + are "bottomleft", "bottomright", "topleft" and "topright". Default sign.pos="bottomright". } @@ -328,7 +331,7 @@ kegg.native=FALSE. Default is.signal=TRUE. \item{afactor}{ numeric, node amplifying factor. This argument is for node size fine-tuning, its effect is subtler than expected. Only effective when -kegg.native=FALSE. Default afctor=1. +kegg.native=FALSE. Default afactor=1. } \item{text.width}{ numeric, specifying the line width for text wrap. Only effective when @@ -459,4 +462,4 @@ head(pv.out$plot.data.cpd) % Add one or more standard keywords, see file 'KEYWORDS' in the % R documentation directory. \keyword{ ~kwd1 } -\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line +\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line \ No newline at end of file