Mercurial > repos > simon-gladman > phyloseq_nmds
annotate phyloseq_nmds.R @ 2:20adf95eb758 draft
Updated phyloseq_nmds.xml to allow for new datatype.
author | simon-gladman |
---|---|
date | Fri, 20 Jul 2018 00:23:53 -0400 |
parents | e376a618eb9f |
children |
rev | line source |
---|---|
0 | 1 library('getopt') |
2 library('ape') | |
3 suppressPackageStartupMessages(library('phyloseq')) | |
1
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
4 library(biomformat) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
5 library(plyr) |
0 | 6 Sys.setenv("DISPLAY"=":1") |
7 library("ggplot2") | |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
8 suppressPackageStartupMessages(library("doParallel")) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
9 ncores = ceiling(detectCores() * 0.8) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
10 registerDoParallel(cores=ncores) |
0 | 11 |
12 options(warn=-1) | |
13 | |
14 theme_set(theme_bw()) | |
15 | |
16 #http://saml.rilspace.com/creating-a-galaxy-tool-for-r-scripts-that-output-images-and-pdfs | |
17 #http://joey711.github.io/phyloseq-demo/phyloseq-demo.html | |
18 option_specification = matrix(c( | |
19 'otu_table','o',2,'character', | |
20 'tax_table','t',2,'character', | |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
21 'meta_table','m',2,'character', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
22 'biom','b',2,'character', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
23 'filter','f',2,'numeric', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
24 'subset','s',2,'character', |
0 | 25 'method','n',2,'character', |
26 'distance','d',2,'character', | |
27 'kingdom','k',2,'character', | |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
28 'plottype','e',2,'numeric', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
29 'cutoff','c',2,'numeric', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
30 'category','g',2,'numeric', |
0 | 31 'keep','p',2,'numeric', |
32 'outdir','r',2,'character', | |
33 'htmlfile','h',2,'character' | |
34 ),byrow=TRUE,ncol=4); | |
35 | |
36 | |
37 options <- getopt(option_specification); | |
38 options(bitmapType="cairo") | |
39 | |
40 if (!is.null(options$outdir)) { | |
41 # Create the directory | |
42 dir.create(options$outdir,FALSE) | |
43 } | |
44 | |
45 | |
46 | |
47 method<-options$method | |
48 cutoff_value<-options$cutoff | |
49 ### select a kingdom for phyloseq plot (e.g., "phylum") | |
50 #kingdom_str<-colnames(tax_table)[options$kingdom] | |
51 kingdom_str<-options$kingdom | |
52 distance<-options$distance | |
53 keep<-options$keep | |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
54 plottype<-options$plottype |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
55 filter<-options$filter |
0 | 56 |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
57 ### prepare the directory and file name |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
58 pdffile <- gsub("[ ]+", "", paste(options$outdir,"/pdffile.pdf")) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
59 pngfile_nmds <- gsub("[ ]+", "", paste(options$outdir,"/nmds.png")) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
60 pngfile_nmds_facet <- gsub("[ ]+", "", paste(options$outdir,"/nmds_facet.png")) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
61 htmlfile <- gsub("[ ]+", "", paste(options$htmlfile)) |
0 | 62 |
1
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
63 |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
64 ### This function accepts different two different type of BIOM file format |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
65 readBIOM<-function(inBiom){ |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
66 tryCatch({ |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
67 phyloseq_obj<-import_biom(inBiom,parallel=TRUE) |
1
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
68 return(phyloseq_obj) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
69 }, |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
70 error=function(e){ |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
71 biom_obj<-read_biom(inBiom) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
72 |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
73 otu_matrix = as(biom_data(biom_obj), "matrix") |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
74 OTU_TABLE = otu_table(otu_matrix, taxa_are_rows=TRUE) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
75 |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
76 taxonomy_matrix = as.matrix(observation_metadata(biom_obj), rownames.force=TRUE) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
77 TAXONOMY_TABLE = tax_table(taxonomy_matrix) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
78 |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
79 metadata.temp<-sample_metadata(biom_obj) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
80 METADATA_TABLE<-plyr::ldply(metadata.temp, rbind) |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
81 rownames(METADATA_TABLE)<-as.character(METADATA_TABLE$.id) |
1
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
82 |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
83 phyloseq_obj = phyloseq(OTU_TABLE, TAXONOMY_TABLE,sample_data(METADATA_TABLE)) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
84 return(phyloseq_obj) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
85 } |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
86 ) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
87 } |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
88 |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
89 |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
90 create_OTU_PDF<-function(pdf_file,phyloseq_obj,phyloseq_ord,kingdom_str,htmlfile,pngfile_nmds,pngfile_nmds_facet){ |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
91 pdf(pdf_file); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
92 p1<-plot_ordination(physeq,physeq_ord,type="taxa",color="Phylum",title="taxa") |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
93 print(p1) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
94 p2<-plot_ordination(physeq,physeq_ord,type="taxa",color="Phylum",title="taxa") + facet_wrap(formula(paste('~',kingdom_str)),3) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
95 print(p2) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
96 garbage<-dev.off(); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
97 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
98 #png('nmds.png') |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
99 bitmap(pngfile_nmds,"png16m") |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
100 p3<-plot_ordination(physeq,physeq_ord,type="taxa",color="Phylum",title="taxa") |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
101 print(p3) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
102 garbage<-dev.off() |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
103 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
104 #png('nmds_facet.png') |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
105 bitmap(pngfile_nmds_facet,"png16m") |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
106 p4<-plot_ordination(physeq,physeq_ord,type="taxa",color="Phylum",title="taxa") + facet_wrap(formula(paste('~',kingdom_str)),3) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
107 print(p4) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
108 garbage<-dev.off() |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
109 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
110 create_HTML_1(htmlfile) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
111 } |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
112 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
113 create_SAMPLE_PDF<-function(pdf_file,phyloseq_obj,phyloseq_ord,htmlfile,pngfile_nmds,category_type){ |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
114 pdf(pdf_file); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
115 p <- plot_ordination(physeq_filter, physeq_ord, type="samples", color=category_type) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
116 p <- p + geom_point(aes(fill=category_type)) + geom_point(size=5) + ggtitle("samples") |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
117 print(p) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
118 garbage<-dev.off(); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
119 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
120 #png('nmds.png') |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
121 bitmap(pngfile_nmds,"png16m") |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
122 p1 <- plot_ordination(physeq_filter, physeq_ord, type="samples", color=category_type) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
123 p1 <- p1 + geom_point(aes(fill=category_type)) + geom_point(size=5) + ggtitle("samples") |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
124 print(p1) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
125 garbage<-dev.off(); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
126 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
127 create_HTML_2(htmlfile) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
128 } |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
129 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
130 create_HTML_1<-function(htmlfile){ |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
131 htmlfile_handle <- file(htmlfile) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
132 html_output = c('<html><body>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
133 '<table align="center>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
134 '<tr>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
135 '<td valign="middle" style="vertical-align:middle;">', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
136 '<a href="pdffile.pdf"><img src="nmds.png"/></a>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
137 '</td>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
138 '</tr>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
139 '<tr>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
140 '<td valign="middle" style="vertical-align:middle;">', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
141 '<a href="pdffile.pdf"><img src="nmds_facet.png"/></a>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
142 '</td>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
143 '</tr>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
144 '</table>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
145 '</html></body>'); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
146 writeLines(html_output, htmlfile_handle); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
147 close(htmlfile_handle); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
148 } |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
149 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
150 create_HTML_2<-function(htmlfile){ |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
151 htmlfile_handle <- file(htmlfile) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
152 html_output = c('<html><body>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
153 '<table align="center>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
154 '<tr>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
155 '<td valign="middle" style="vertical-align:middle;">', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
156 '<a href="pdffile.pdf"><img src="nmds.png"/></a>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
157 '</td>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
158 '</tr>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
159 '</table>', |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
160 '</html></body>'); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
161 writeLines(html_output, htmlfile_handle); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
162 close(htmlfile_handle); |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
163 } |
1
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
164 |
0 | 165 if(!is.null(options$biom)){ |
166 | |
1
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
167 #physeq<-import_biom(options$biom) |
e376a618eb9f
Updated phyloseq_nmds.R to allow for non standard BIOM files.
simon-gladman
parents:
0
diff
changeset
|
168 physeq<-readBIOM(options$biom) |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
169 |
0 | 170 if(length(rank_names(physeq)) == 8){ |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
171 tax_table(physeq) <- tax_table(physeq)[,-1] |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
172 colnames(tax_table(physeq)) <- c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species") |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
173 } else { |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
174 colnames(tax_table(physeq)) <- c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species") |
0 | 175 } |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
176 |
0 | 177 ### select column name from sample table for nmds plot |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
178 ## which(colnames(sample_data(biom)) == "vegetation_type_id") |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
179 #category_type<-colnames(sample_data(physeq))[options$subset] |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
180 category_type <- options$subset |
0 | 181 |
182 ### obtain the unique value in the selected column from sample table | |
183 category_option<-unique(sample_data(physeq))[,options$subset] | |
184 | |
185 }else{ | |
186 | |
187 ### read the data into correct data type to create phyloseq object | |
188 otu_table<-as.matrix(read.table(options$otu_table,header=T,sep="\t")) | |
189 tax_table<-as.matrix(read.table(options$tax_table,header=T,sep="\t")) | |
190 sample_table<-read.table(options$meta_table,header=T,sep="\t",stringsAsFactors=F) | |
191 | |
192 | |
193 ### select column name from sample table for nmds plot | |
194 category_type<-colnames(sample_table)[options$category] | |
195 | |
196 ### obtain the unique value in the selected column from sample table | |
197 category_option<-unique(sample_table[,options$category]) | |
198 | |
199 | |
200 ### create a sample object for phyloseq | |
201 sample_object<-sample_data(sample_table) | |
202 | |
203 ### create otu object for phyloseq | |
204 OTU<-otu_table(otu_table, taxa_are_rows = TRUE) | |
205 | |
206 ### create tax object for phyloseq | |
207 TAX<-tax_table(tax_table) | |
208 | |
209 ### create a phyloseq object | |
210 physeq = phyloseq(OTU,TAX,sample_object) | |
211 } | |
212 ### select a kingdom for phyloseq plot (e.g., "phylum") | |
213 #kingdom_str<-colnames(tax_table)[options$kingdom] | |
214 #kingdom_str<-options$kingdom | |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
215 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
216 |
0 | 217 ### filtering OTUs based on cutoff value (e.g., 5) |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
218 #physeq_temp =genefilter_sample(physeq, filterfun_sample(function(x) x > cutoff_value), A=0.1*nsamples(physeq)) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
219 physeq_temp =genefilter_sample(physeq, filterfun_sample(function(x) x > cutoff_value), A=filter*nsamples(physeq)) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
220 |
0 | 221 ### phyloseq object after filtered |
222 physeq_filter = prune_taxa(physeq_temp, physeq) | |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
223 |
0 | 224 ## Transform to even sampling depth |
225 physeq_filter = transform_sample_counts(physeq_filter, function(x) 1E6 * x/sum(x)) | |
226 | |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
227 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
228 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
229 if(plottype == 1){ |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
230 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
231 # kingdom_str <- as.numeric(kingdom_str) |
0 | 232 ## Keep only the most abundant five phyla |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
233 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
234 phylum.sum = tapply(taxa_sums(physeq_filter), tax_table(physeq_filter)[, kingdom_str], sum,na.rm=TRUE) |
0 | 235 ### number of most abundance phyla to keep |
236 topphyla = names(sort(phylum.sum, TRUE))[1:keep] | |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
237 |
0 | 238 physeq_filter = prune_taxa((tax_table(physeq_filter)[, kingdom_str] %in% topphyla), physeq_filter) |
239 | |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
240 }else{ |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
241 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
242 otu_table(physeq_filter)<-otu_table(physeq_filter)[,colSums(otu_table(physeq_filter)) > 1] |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
243 |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
244 } |
0 | 245 ### select category to plot NMDS |
246 category_input = get_variable(physeq_filter, category_type) %in% category_option | |
247 sample_data(physeq_filter)$category_input <- factor(category_input) | |
248 | |
249 physeq_ord<-ordinate(physeq_filter,method,distance) | |
250 | |
2
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
251 if(plottype == 1){ |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
252 #kingdom_str = colnames(tax_table)[2] |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
253 create_OTU_PDF(pdffile,physeq_filter,physeq_ord,kingdom_str,htmlfile,pngfile_nmds,pngfile_nmds_facet) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
254 }else{ |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
255 create_SAMPLE_PDF(pdffile,physeq_filter,physeq_ord,htmlfile,pngfile_nmds,category_type) |
20adf95eb758
Updated phyloseq_nmds.xml to allow for new datatype.
simon-gladman
parents:
1
diff
changeset
|
256 } |
0 | 257 |