annotate maaslin-4450aa4ecc84/src/lib/scriptBiplotTSV.R @ 1:a87d5a5f2776

Uploaded the version running on the prod server
author george-weingart
date Sun, 08 Feb 2015 23:08:38 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
1 #!/usr/bin/env Rscript
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
2
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
3 library(vegan)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
4 library(optparse)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
5
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
6 funcGetCentroidForMetadatum <- function(
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
7 ### Given a binary metadatum, calculate the centroid of the samples associated with the metadata value of 1
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
8 # 1. Get all samples that have the metadata value of 1
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
9 # 2. Get the x and y coordinates of the selected samples
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
10 # 3. Get the median value for the x and ys
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
11 # 4. Return those coordinates as the centroid's X and Y value
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
12 vfMetadata,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
13 ### Logical or integer (0,1) vector, TRUE or 1 values indicate correspoinding samples in the
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
14 ### mSamplePoints which will be used to define the centroid
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
15 mSamplePoints
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
16 ### Coordinates (columns;n=2) of samples (rows) corresponding to the vfMetadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
17 ){
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
18 # Check the lengths which should be equal
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
19 if(length(vfMetadata)!=nrow(mSamplePoints))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
20 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
21 print(paste("funcGetCentroidForMetadata::Error: Should have received metadata and samples of the same length, received metadata length ",length(vfMetadata)," and sample ",nrow(mSamplePoints)," length.",sep=""))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
22 return( FALSE )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
23 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
24
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
25 # Get all the samples that have the metadata value of 1
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
26 viMetadataSamples = which(as.integer(vfMetadata)==1)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
27
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
28 # Get the x and y coordinates for the selected samples
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
29 mSelectedPoints = mSamplePoints[viMetadataSamples,]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
30
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
31 # Get the median value for the x and the ys
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
32 if(!is.null(nrow(mSelectedPoints)))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
33 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
34 return( list(x=median(mSelectedPoints[,1],na.rm = TRUE),y=median(mSelectedPoints[,2],na.rm = TRUE)) )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
35 } else {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
36 return( list(x=mSelectedPoints[1],y=mSelectedPoints[2]) )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
37 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
38 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
39
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
40 funcGetMaximumForMetadatum <- function(
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
41 ### Given a continuous metadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
42 ### 1. Use the x and ys from mSamplePoints for coordinates and the metadata value as a height (z)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
43 ### 2. Use lowess to smooth the landscape
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
44 ### 3. Take the maximum of the landscape
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
45 ### 4. Return the coordiantes for the maximum as the centroid
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
46 vdMetadata,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
47 ### Continuous (numeric or integer) metadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
48 mSamplePoints
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
49 ### Coordinates (columns;n=2) of samples (rows) corresponding to the vfMetadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
50 ){
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
51 # Work with data frame
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
52 if(class(mSamplePoints)=="matrix")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
53 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
54 mSamplePoints = data.frame(mSamplePoints)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
55 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
56 # Check the lengths of the dataframes and the metadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
57 if(length(vdMetadata)!=nrow(mSamplePoints))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
58 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
59 print(paste("funcGetMaximumForMetadatum::Error: Should have received metadata and samples of the same length, received metadata length ",length(vdMetadata)," and sample ",nrow(mSamplePoints)," length.",sep=""))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
60 return( FALSE )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
61 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
62
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
63 # Add the metadata value to the points
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
64 mSamplePoints[3] = vdMetadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
65 names(mSamplePoints) = c("x","y","z")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
66
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
67 # Create lowess to smooth the surface
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
68 # And calculate the fitted heights
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
69 # x = sample coordinate 1
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
70 # y = sample coordinate 2
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
71 # z = metadata value
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
72 loessSamples = loess(z~x*y, data=mSamplePoints, degree = 1, normalize = FALSE, na.action=na.omit)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
73
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
74 # Naively get the max
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
75 vdCoordinates = loessSamples$x[which(loessSamples$y==max(loessSamples$y)),]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
76 return(list(lsmod = loessSamples, x=vdCoordinates[1],y=vdCoordinates[2]))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
77 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
78
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
79 funcMakeShapes <- function(
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
80 ### Takes care of defining shapes for the plot
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
81 dfInput,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
82 ### Data frame of metadata measurements
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
83 sShapeBy,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
84 ### The metadata to shape by
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
85 sShapes,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
86 ### List of custom metadata (per level if factor).
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
87 ### Should correspond to the number of levels in shapeBy; the format is level:shape,level:shape for example HighLuminosity:14,LowLuminosity:2,HighPH:10,LowPH:18
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
88 cDefaultShape
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
89 ### Shape to default to if custom shapes are not used
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
90 ){
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
91 lShapes = list()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
92 vsShapeValues = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
93 vsShapeShapes = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
94 vsShapes = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
95 sMetadataId = sShapeBy
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
96
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
97 # Set default shape, color, and color ranges
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
98 if(!is.null(cDefaultShape))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
99 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
100 # Default shape should be an int for the int pch options
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
101 if(!is.na(as.integer(cDefaultShape)))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
102 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
103 cDefaultShape = as.integer(cDefaultShape)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
104 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
105 } else {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
106 cDefaultShape = 16
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
107 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
108
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
109 # Make shapes
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
110 vsShapes = rep(cDefaultShape,nrow(dfInput))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
111
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
112 if(!is.null(sMetadataId))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
113 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
114 if(is.null(sShapes))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
115 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
116 vsShapeValues = unique(dfInput[[sMetadataId]])
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
117 vsShapeShapes = 1:length(vsShapeValues)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
118 } else {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
119 # Put the markers in the order of the values)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
120 vsShapeBy = unlist(strsplit(sShapes,","))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
121 for(sShapeBy in vsShapeBy)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
122 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
123 vsShapeByPieces = unlist(strsplit(sShapeBy,":"))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
124 lShapes[vsShapeByPieces[1]] = as.integer(vsShapeByPieces[2])
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
125 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
126 vsShapeValues = names(lShapes)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
127 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
128
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
129 # Shapes in the correct order
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
130 if(!is.null(sShapes))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
131 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
132 vsShapeShapes = unlist(lapply(vsShapeValues,function(x) lShapes[[x]]))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
133 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
134 vsShapeValues = paste(vsShapeValues)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
135
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
136 # Make the list of shapes
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
137 for(iShape in 1:length(vsShapeValues))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
138 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
139 vsShapes[which(paste(dfInput[[sMetadataId]])==vsShapeValues[iShape])]=vsShapeShapes[iShape]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
140 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
141
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
142 # If they are all numeric characters, make numeric
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
143 viIntNas = which(is.na(as.integer(vsShapes)))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
144 viNas = which(is.na(vsShapes))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
145 if(length(setdiff(viIntNas,viNas))==0)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
146 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
147 vsShapes = as.integer(vsShapes)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
148 } else {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
149 print("funcMakeShapes::Error: Please supply numbers 1-25 for shape in the -y,--shapeBy option")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
150 vsShapeValues = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
151 vsShapeShapes = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
152 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
153 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
154 return(list(PlotShapes=vsShapes,Values=vsShapeValues,Shapes=vsShapeShapes,ID=sMetadataId,DefaultShape=cDefaultShape))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
155 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
156
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
157 ### Global defaults
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
158 c_sDefaultColorBy = NULL
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
159 c_sDefaultColorRange = "orange,cyan"
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
160 c_sDefaultTextColor = "black"
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
161 c_sDefaultArrowColor = "cyan"
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
162 c_sDefaultArrowTextColor = "Blue"
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
163 c_sDefaultNAColor = "grey"
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
164 c_sDefaultShapeBy = NULL
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
165 c_sDefaultShapes = NULL
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
166 c_sDefaultMarker = "16"
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
167 c_sDefaultRotateByMetadata = NULL
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
168 c_sDefaultResizeArrow = 1
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
169 c_sDefaultTitle = "Custom Biplot of Bugs and Samples - Metadata Plotted with Centroids"
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
170 c_sDefaultOutputFile = NULL
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
171
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
172 ### Create command line argument parser
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
173 pArgs <- OptionParser( usage = "%prog last_metadata input.tsv" )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
174
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
175 # Selecting features to plot
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
176 pArgs <- add_option( pArgs, c("-b", "--bugs"), type="character", action="store", default=NULL, dest="sBugs", metavar="BugsToPlot", help="Comma delimited list of data to plot as text. Bug|1,Bug|2")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
177 pArgs <- add_option( pArgs, c("-m", "--metadata"), type="character", action="store", default=NULL, dest="sMetadata", metavar="MetadataToPlot", help="Comma delimited list of metadata to plot as arrows. metadata1,metadata2,metadata3")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
178
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
179 # Colors
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
180 pArgs <- add_option( pArgs, c("-c", "--colorBy"), type="character", action="store", default=c_sDefaultColorBy, dest="sColorBy", metavar="MetadataToColorBy", help="The id of the metadatum to use to make the marker colors. Expected to be a continuous metadata.")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
181 pArgs <- add_option( pArgs, c("-r", "--colorRange"), type="character", action="store", default=c_sDefaultColorRange, dest="sColorRange", metavar="ColorRange", help=paste("Colors used to color the samples; a gradient will be formed between the color.Default=", c_sDefaultColorRange))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
182 pArgs <- add_option( pArgs, c("-t", "--textColor"), type="character", action="store", default=c_sDefaultTextColor, dest="sTextColor", metavar="TextColor", help=paste("The color bug features will be plotted with as text. Default =", c_sDefaultTextColor))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
183 pArgs <- add_option( pArgs, c("-a", "--arrowColor"), type="character", action="store", default=c_sDefaultArrowColor, dest="sArrowColor", metavar="ArrowColor", help=paste("The color metadata features will be plotted with as an arrow and text. Default", c_sDefaultArrowColor))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
184 pArgs <- add_option( pArgs, c("-w", "--arrowTextColor"), type="character", action="store", default=c_sDefaultArrowTextColor, dest="sArrowTextColor", metavar="ArrowTextColor", help=paste("The color for the metadata text ploted by the head of the metadata arrow. Default", c_sDefaultArrowTextColor))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
185 pArgs <- add_option(pArgs, c("-n","--plotNAColor"), type="character", action="store", default=c_sDefaultNAColor, dest="sPlotNAColor", metavar="PlotNAColor", help=paste("Plot NA values as this color. Example -n", c_sDefaultNAColor))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
186
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
187 # Shapes
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
188 pArgs <- add_option( pArgs, c("-y", "--shapeby"), type="character", action="store", default=c_sDefaultShapeBy, dest="sShapeBy", metavar="MetadataToShapeBy", help="The metadata to use to make marker shapes. Expected to be a discrete metadatum. An example would be -y Environment")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
189 pArgs <- add_option( pArgs, c("-s", "--shapes"), type="character", action="store", default=c_sDefaultShapes, dest="sShapes", metavar="ShapesForPlotting", help="This is to be used to specify the shapes to use for plotting. Can use numbers recognized by R as shapes (see pch). Should correspond to the number of levels in shapeBy; the format is level:shape,level:shape for example HighLuminosity:14,LowLuminosity:2,HighPH:10,LowPH:18 . Need to specify -y/--shapeBy for this option to work.")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
190 pArgs <- add_option( pArgs, c("-d", "--defaultMarker"), type="character", action="store", default=c_sDefaultMarker, dest="sDefaultMarker", metavar="DefaultColorMarker", help="Default shape for markers which are not otherwise indicated in --shapes, can be used for unspecified values or NA. Must not be a shape in --shapes.")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
191
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
192 # Plot manipulations
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
193 pArgs <- add_option( pArgs, c("-e","--rotateByMetadata"), type="character", action="store", default=c_sDefaultRotateByMetadata, dest="sRotateByMetadata", metavar="RotateByMetadata", help="Rotate the ordination by a metadata. Give both the metadata and value to weight it by. The larger the weight, the more the ordination is influenced by the metadata. If the metadata is continuous, use the metadata id; if the metadata is discrete, the ordination will be by one of the levels so use the metadata ID and level seperated by a '_'. Discrete example -e Environment_HighLumninosity,100 ; Continuous example -e Environment,100 .")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
194 pArgs <- add_option( pArgs, c("-z","--resizeArrow"), type="numeric", action="store", default=c_sDefaultResizeArrow, dest="dResizeArrow", metavar="ArrowScaleFactor", help="A constant to multiple the length of the arrow to expand or shorten all arrows together. This will not change the angle of the arrow nor the relative length of arrows to each other.")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
195
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
196 # Misc
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
197 pArgs <- add_option( pArgs, c("-i", "--title"), type="character", action="store", default=c_sDefaultTitle, dest="sTitle", metavar="Title", help="This is the title text to add to the plot.")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
198 pArgs <- add_option( pArgs, c("-o", "--outputfile"), type="character", action="store", default=c_sDefaultOutputFile, dest="sOutputFileName", metavar="OutputFile", help="This is the name for the output pdf file. If an output file is not given, an output file name is made based on the input file name.")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
199
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
200 funcDoBiplot <- function(
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
201 ### Perform biplot. Samples are markers, bugs are text, and metadata are text with arrows. Markers and bugs are dtermined usiing NMDS and Bray-Curtis dissimilarity. Metadata are placed on the ordination in one of two ways: 1. Factor data - for each level take the ordination points for the samples that have that level and plot the metadata text at the average orindation point. 2. For continuous data - make a landscape (x and y form ordination of the points) and z (height) as the metadata value. Use a lowess line to get the fitted values for z and take the max of the landscape. Plot the metadata text at that smoothed max.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
202 sBugs,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
203 ### Comma delimited list of data to plot as text. Bug|1,Bug|2
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
204 sMetadata,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
205 ### Comma delimited list of metadata to plot as arrows. metadata1,metadata2,metadata3.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
206 sColorBy = c_sDefaultColorBy,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
207 ### The id of the metadatum to use to make the marker colors. Expected to be a continuous metadata.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
208 sColorRange = c_sDefaultColorRange,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
209 ### Colors used to color the samples; a gradient will be formed between the color. Example orange,cyan
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
210 sTextColor = c_sDefaultTextColor,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
211 ### The color bug features will be plotted with as text. Example black
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
212 sArrowColor = c_sDefaultArrowColor,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
213 ### The color metadata features will be plotted with as an arrow and text. Example cyan
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
214 sArrowTextColor = c_sDefaultArrowTextColor,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
215 ### The color for the metadata text ploted by the head of the metadata arrow. Example Blue
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
216 sPlotNAColor = c_sDefaultNAColor,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
217 ### Plot NA values as this color. Example grey
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
218 sShapeBy = c_sDefaultShapeBy,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
219 ### The metadata to use to make marker shapes. Expected to be a discrete metadatum.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
220 sShapes = c_sDefaultShapes,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
221 ### This is to be used to specify the shapes to use for plotting. Can use numbers recognized by R as shapes (see pch). Should correspond to the number of levels in shapeBy; the format is level:shape,level:shape for example HighLuminosity:14,LowLuminosity:2,HighPH:10,LowPH:18 . Works with sShapesBy.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
222 sDefaultMarker = c_sDefaultMarker,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
223 ### The default marker shape to use if shapes are not otherwise indicated.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
224 sRotateByMetadata = c_sDefaultRotateByMetadata,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
225 ### Metadata and value to rotate by. example Environment_HighLumninosity,100
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
226 dResizeArrow = c_sDefaultResizeArrow,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
227 ### Scale factor to resize tthe metadata arrows
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
228 sTitle = c_sDefaultTitle,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
229 ### The title for the figure.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
230 sInputFileName,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
231 ### File to input (tsv file: tab separated, row = sample file)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
232 sLastMetadata,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
233 ### Last metadata that seperates data and metadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
234 sOutputFileName = c_sDefaultOutputFile
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
235 ### The file name to save the figure.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
236 ){
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
237 print("IN Biplot")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
238 # Define the colors
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
239 vsColorRange = c("blue","orange")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
240 cDefaultColor = "black"
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
241 if(!is.null(sColorRange))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
242 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
243 vsColorRange = unlist(strsplit(sColorRange,","))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
244 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
245
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
246 # List of bugs to plot
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
247 # If there is a list it needs to be more than one.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
248 vsBugsToPlot = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
249 if(!is.null(sBugs))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
250 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
251 vsBugsToPlot = unlist(strsplit(sBugs,","))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
252 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
253
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
254 print("vsBugsToPlot")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
255 print(vsBugsToPlot)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
256 # Metadata to plot
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
257 vsMetadata = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
258 if(!is.null(sMetadata))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
259 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
260 vsMetadata = unlist(strsplit(sMetadata,","))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
261 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
262
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
263 print("vsMetadata")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
264 print(vsMetadata)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
265 ### Load table
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
266 if(class(sInputFileName)=="character")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
267 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
268 dfInput = read.table(sInputFileName, sep = "\t", header=TRUE)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
269 names(dfInput) = unlist(lapply(names(dfInput),function(x) gsub(".","|",x,fixed=TRUE)))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
270 row.names(dfInput) = dfInput[,1]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
271 dfInput = dfInput[-1]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
272 } else {dfInput = sInputFileName}
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
273
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
274 ### Get positions of all metadata or all data
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
275 iLastMetadata = which(names(dfInput)==sLastMetadata)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
276 viMetadata = 1:iLastMetadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
277 viData = (iLastMetadata+1):ncol(dfInput)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
278
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
279 ### Dummy the metadata if discontinuous
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
280 ### Leave the continous metadata alone but include
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
281 listMetadata = list()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
282 vsRowNames = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
283 viContinuousMetadata = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
284 for(i in viMetadata)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
285 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
286 print( names( dfInput )[i] )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
287 vCurMetadata = unlist(dfInput[i])
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
288 if( ( is.numeric(vCurMetadata)||is.integer(vCurMetadata) ) && ( length( unique( vCurMetadata ) ) >= c_iNonFactorLevelThreshold ) )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
289 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
290 vCurMetadata[which(is.na(vCurMetadata))] = mean(vCurMetadata,na.rm=TRUE)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
291 listMetadata[[length(listMetadata)+1]] = vCurMetadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
292 vsRowNames = c(vsRowNames,names(dfInput)[i])
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
293 viContinuousMetadata = c(viContinuousMetadata,length(listMetadata))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
294 } else {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
295 vCurMetadata = as.factor(vCurMetadata)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
296 vsLevels = levels(vCurMetadata)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
297 for(sLevel in vsLevels)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
298 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
299 vNewMetadata = rep(0,length(vCurMetadata))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
300 vNewMetadata[which(vCurMetadata == sLevel)] = 1
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
301 listMetadata[[length(listMetadata)+1]] = vNewMetadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
302 vsRowNames = c(vsRowNames,paste(names(dfInput)[i],sLevel,sep="_"))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
303 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
304 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
305 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
306
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
307 # Convert to data frame
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
308 dfDummyMetadata = as.data.frame(sapply(listMetadata,rbind))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
309 names(dfDummyMetadata) = vsRowNames
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
310 iNumberMetadata = ncol(dfDummyMetadata)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
311
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
312 # Data to use in ordination in NMDS
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
313 # All cleaned bug data
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
314 dfData = dfInput[viData]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
315
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
316 # If rotating the ordination by a metadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
317 # 1. Add in the metadata as a bug
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
318 # 2. Multiply the bug by the weight
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
319 # 3. Push this through the NMDS
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
320 if(!is.null(sRotateByMetadata))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
321 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
322 vsRotateMetadata = unlist(strsplit(sRotateByMetadata,","))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
323 sMetadata = vsRotateMetadata[1]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
324 dWeight = as.numeric(vsRotateMetadata[2])
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
325 sOrdinationMetadata = dfDummyMetadata[sMetadata]*dWeight
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
326 dfData[sMetadata] = sOrdinationMetadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
327 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
328
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
329 # Run NMDS on bug data (Default B-C)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
330 # Will have species and points because working off of raw data
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
331 mNMDSData = metaMDS(dfData,k=2)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
332
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
333 ## Make shapes
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
334 # Defines the shapes and the metadata they are based on
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
335 # Metadata to use as shapes
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
336 lShapeInfo = funcMakeShapes(dfInput=dfInput, sShapeBy=sShapeBy, sShapes=sShapes, cDefaultShape=sDefaultMarker)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
337
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
338 sMetadataShape = lShapeInfo[["ID"]]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
339 vsShapeValues = lShapeInfo[["Values"]]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
340 vsShapeShapes = lShapeInfo[["Shapes"]]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
341 vsShapes = lShapeInfo[["PlotShapes"]]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
342 cDefaultShape = lShapeInfo[["DefaultShape"]]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
343
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
344 # Colors
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
345 vsColors = rep(cDefaultColor,nrow(dfInput))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
346 vsColorValues = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
347 vsColorRBG = c()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
348 if(!is.null(sColorBy))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
349 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
350 vsColorValues = paste(sort(unique(unlist(dfInput[[sColorBy]])),na.last=TRUE))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
351 iLengthColorValues = length(vsColorValues)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
352
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
353 vsColorRBG = lapply(1:iLengthColorValues/iLengthColorValues,colorRamp(vsColorRange))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
354 vsColorRBG = unlist(lapply(vsColorRBG, function(x) rgb(x[1]/255,x[2]/255,x[3]/255)))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
355
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
356 for(iColor in 1:length(vsColorRBG))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
357 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
358 vsColors[which(paste(dfInput[[sColorBy]])==vsColorValues[iColor])]=vsColorRBG[iColor]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
359 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
360
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
361 #If NAs are seperately given color, then color here
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
362 if(!is.null(sPlotNAColor))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
363 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
364 vsColors[which(is.na(dfInput[[sColorBy]]))] = sPlotNAColor
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
365 vsColorRBG[which(vsColorValues=="NA")] = sPlotNAColor
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
366 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
367 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
368
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
369 print("names(dfDummyMetadata)")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
370 print(names(dfDummyMetadata))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
371
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
372 # Reduce the bugs down to the ones in the list to be plotted
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
373 viBugsToPlot = which(row.names(mNMDSData$species) %in% vsBugsToPlot)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
374 viMetadataDummy = which(names(dfDummyMetadata) %in% vsMetadata)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
375
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
376 print("viBugsToPlot")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
377 print(viBugsToPlot)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
378 print("viMetadataDummy")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
379 print(names(dfDummyMetadata)[viMetadataDummy])
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
380
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
381 # Build the matrix of metadata coordinates
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
382 mMetadataCoordinates = matrix(rep(NA, iNumberMetadata*2),nrow=iNumberMetadata)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
383 for( i in 1:iNumberMetadata )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
384 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
385 lxReturn = NA
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
386 if( i %in% viContinuousMetadata )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
387 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
388 lxReturn = funcGetMaximumForMetadatum(dfDummyMetadata[[i]],mNMDSData$points)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
389 } else {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
390 lxReturn = funcGetCentroidForMetadatum(dfDummyMetadata[[i]],mNMDSData$points)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
391 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
392 mMetadataCoordinates[i,] = c(lxReturn$x,lxReturn$y)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
393 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
394 row.names(mMetadataCoordinates) = vsRowNames
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
395
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
396 # Plot the biplot with the centroid constructed metadata coordinates
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
397 if(length(viMetadataDummy)==0)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
398 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
399 viMetadataDummy = 1:nrow(mMetadataCoordinates)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
400 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
401
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
402 # Plot samples
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
403 # Make output name
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
404 if(is.null(sOutputFileName))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
405 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
406 viPeriods = which(sInputFileName==".")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
407 if(length(viPeriods)>0)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
408 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
409 sOutputFileName = paste(OutputFileName[1:viPeriods[length(viPeriods)]],"pdf",sep=".")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
410 } else {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
411 sOutputFileName = paste(sInputFileName,"pdf",sep=".")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
412 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
413 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
414
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
415 pdf(sOutputFileName, useDingbats=FALSE)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
416 plot(mNMDSData$points, xlab=paste("NMDS1","Stress=",mNMDSData$stress), ylab="NMDS2", pch=vsShapes, col=vsColors)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
417 title(sTitle,line=3)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
418
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
419 # Plot Bugs
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
420 mPlotBugs = mNMDSData$species[viBugsToPlot,]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
421 if(length(viBugsToPlot)==1)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
422 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
423 text(x=mPlotBugs[1],y=mPlotBugs[2],labels=row.names(mNMDSData$species)[viBugsToPlot],col=sTextColor)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
424 } else if(length(viBugsToPlot)>1){
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
425 text(x=mPlotBugs[,1],y=mPlotBugs[,2],labels=row.names(mNMDSData$species)[viBugsToPlot],col=sTextColor)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
426 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
427
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
428 # Add alternative axes
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
429 axis(3, col=sArrowColor)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
430 axis(4, col=sArrowColor)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
431 box(col = "black")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
432
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
433 # Plot Metadata
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
434 if(length(viMetadataDummy)>0)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
435 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
436 for(i in viMetadataDummy)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
437 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
438 curCoordinates = mMetadataCoordinates[i,]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
439 curCoordinates = curCoordinates * dResizeArrow
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
440 # Plot Arrow
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
441 arrows(0,0, curCoordinates[1] * 0.8, curCoordinates[2] * 0.8, col=sArrowColor, length=0.1 )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
442 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
443 # Plot text
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
444 if(length(viMetadataDummy)==1)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
445 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
446 text(x=mMetadataCoordinates[viMetadataDummy,][1]*dResizeArrow*0.8, y=mMetadataCoordinates[viMetadataDummy,][2]*dResizeArrow*0.8, labels=row.names(mMetadataCoordinates)[viMetadataDummy],col=sArrowTextColor)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
447 } else {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
448 text(x=mMetadataCoordinates[viMetadataDummy,1]*dResizeArrow*0.8, y=mMetadataCoordinates[viMetadataDummy,2]*dResizeArrow*0.8, labels=row.names(mMetadataCoordinates)[viMetadataDummy],col=sArrowTextColor)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
449 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
450 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
451
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
452 # Create Legend
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
453 # The text default is the colorMetadata_level (one per level) plus the ShapeMetadata_level (one per level)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
454 # The color default is already determined colors plus grey for shapes.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
455 sLegendText = c(paste(vsColorValues,sColorBy,sep="_"),paste(sMetadataShape,vsShapeValues,sep="_"))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
456 sLegendColors = c(vsColorRBG,rep(cDefaultColor,length(vsShapeValues)))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
457
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
458 # If the color values are numeric
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
459 # Too many values may be given in the legend (given they may be a continuous range of values)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
460 # To reduce this they are summarized instead, given the colors and values for the extreme ends.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
461 if( !sum( is.na( as.numeric( vsColorValues[ which( !is.na( vsColorValues ) ) ] ) ) ) )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
462 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
463 vdNumericColors = as.numeric( vsColorValues )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
464 vdNumericColors = vdNumericColors[ which( !is.na( vdNumericColors ) ) ]
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
465 vdSortedNumericColors = sort( vdNumericColors )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
466 sLegendText = c( paste( sColorBy, vdSortedNumericColors[ 1 ], sep="_" ),
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
467 paste( sColorBy, vdSortedNumericColors[ length(vdSortedNumericColors) ], sep="_" ),
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
468 paste( sMetadataShape, vsShapeValues, sep="_" ) )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
469 sLegendColors = c(vsColorRBG[ which( vdNumericColors == vdSortedNumericColors[ 1 ] )[ 1 ] ],
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
470 vsColorRBG[ which( vdNumericColors == vdSortedNumericColors[ length( vdSortedNumericColors ) ] )[ 1 ] ],
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
471 rep(cDefaultColor,length(vsShapeValues)))
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
472 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
473 sLegendShapes = c( rep( cDefaultShape, length( sLegendText ) - length( vsShapeShapes ) ), vsShapeShapes )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
474
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
475 # If any legend text was constructed then make the legend.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
476 if( length( sLegendText ) >0 )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
477 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
478 legend( "topright", legend = sLegendText, pch = sLegendShapes, col = sLegendColors )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
479 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
480
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
481 # Original biplot call if you want to check the custom plotting of the script
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
482 # There will be one difference where the biplot call scales an axis, this one does not. In relation to the axes, the points, text and arrows should still match.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
483 # Axes to the top and right are for the arrow, others are for markers and bug names.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
484 #biplot(mNMDSData$points,mMetadataCoordinates[viMetadataDummy,],xlabs=vsShapes,xlab=paste("MDS1","Stress=",mNMDSData$stress),main="Biplot function Bugs and Sampes - Metadata Plotted with Centroids")
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
485 dev.off()
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
486 }
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
487
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
488 # This is the equivalent of __name__ == "__main__" in Python.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
489 # That is, if it's true we're being called as a command line script;
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
490 # if it's false, we're being sourced or otherwise included, such as for
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
491 # library or inlinedocs.
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
492 if( identical( environment( ), globalenv( ) ) &&
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
493 !length( grep( "^source\\(", sys.calls( ) ) ) )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
494 {
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
495 lsArgs <- parse_args( pArgs, positional_arguments=TRUE )
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
496
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
497 funcDoBiplot(
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
498 sBugs = lsArgs$options$sBugs,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
499 sMetadata = lsArgs$options$sMetadata,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
500 sColorBy = lsArgs$options$sColorBy,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
501 sColorRange = lsArgs$options$sColorRange,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
502 sTextColor = lsArgs$options$sTextColor,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
503 sArrowColor = lsArgs$options$sArrowColor,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
504 sArrowTextColor = lsArgs$options$sArrowTextColor,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
505 sPlotNAColor = lsArgs$options$sPlotNAColor,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
506 sShapeBy = lsArgs$options$sShapeBy,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
507 sShapes = lsArgs$options$sShapes,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
508 sDefaultMarker = lsArgs$options$sDefaultMarker,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
509 sRotateByMetadata = lsArgs$options$sRotateByMetadata,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
510 dResizeArrow = lsArgs$options$dResizeArrow,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
511 sTitle = lsArgs$options$sTitle,
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
512 sInputFileName = lsArgs$args[2],
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
513 sLastMetadata = lsArgs$args[1],
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
514 sOutputFileName = lsArgs$options$sOutputFileName)
a87d5a5f2776 Uploaded the version running on the prod server
george-weingart
parents:
diff changeset
515 }