Mercurial > repos > simon-gladman > phyloseq_filter
annotate phyloseq_filter.R @ 2:54897b7e0551 draft default tip
Updated tool
| author | simon-gladman |
|---|---|
| date | Thu, 22 Nov 2018 08:13:52 -0500 |
| parents | 9fbb104e16d9 |
| children |
| rev | line source |
|---|---|
|
0
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
1 library('getopt') |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
2 library('ape') |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
3 library('ggplot2') |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
4 suppressPackageStartupMessages(library('phyloseq')) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
5 library(plyr) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
6 Sys.setenv("DISPLAY"=":1") |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
7 library(biomformat) |
| 1 | 8 library(jsonlite) |
|
0
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
9 suppressPackageStartupMessages(library(metagenomeSeq)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
10 suppressPackageStartupMessages(library("doParallel")) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
11 ncores = ceiling(detectCores() * 0.8) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
12 registerDoParallel(cores=ncores) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
13 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
14 options(warn=-1) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
15 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
16 theme_set(theme_bw()) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
17 ## ggplot |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
18 # http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
19 # https://gist.github.com/Mikeyj/5429538 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
20 # http://microbiome-tutorials.readthedocs.io/en/latest/_static/Composition.html |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
21 # https://rstudio-pubs-static.s3.amazonaws.com/268156_d3ea37937f4f4469839ab6fa2c483842.html#otus_that_differ_by (stacked bar plot) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
22 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
23 ## color |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
24 ## http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
25 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
26 #http://saml.rilspace.com/creating-a-galaxy-tool-for-r-scripts-that-output-images-and-pdfs |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
27 #http://joey711.github.io/phyloseq-demo/phyloseq-demo.html |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
28 option_specification = matrix(c( |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
29 'otu_table','o',2,'character', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
30 'tax_table','t',2,'character', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
31 'meta_table','m',2,'character', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
32 'biom','b',2,'character', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
33 'filter','f',2,'numeric', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
34 'kingdom','k',2,'character', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
35 'cutoff','c',2,'numeric', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
36 'keep','p',2,'numeric', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
37 'outbiom','h',2,'character', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
38 'outdir','d',2,'character', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
39 'htmlfile','w',2,'character' |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
40 ),byrow=TRUE,ncol=4); |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
41 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
42 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
43 options <- getopt(option_specification); |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
44 options(bitmapType="cairo") |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
45 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
46 if (!is.null(options$outdir)) { |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
47 # Create the directory |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
48 dir.create(options$outdir,FALSE) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
49 } |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
50 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
51 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
52 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
53 cutoff_value<-options$cutoff |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
54 ### select a kingdom for phyloseq plot (e.g., "phylum") |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
55 #kingdom_str<-colnames(tax_table)[options$kingdom] |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
56 kingdom_str<-options$kingdom |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
57 keep<-options$keep |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
58 filter<-options$filter |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
59 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
60 ### prepare the directory and file name |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
61 pdffile <- gsub("[ ]+", "", paste(options$outdir,"/pdffile.pdf")) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
62 pngfile_before_filtering <- gsub("[ ]+", "", paste(options$outdir,"/barplot_before_filtering.png")) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
63 pngfile_after_filtering <- gsub("[ ]+", "", paste(options$outdir,"/barplot_after_filtering.png")) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
64 pngfile_pre_phyla_filtering <- gsub("[ ]+", "", paste(options$outdir,"/barplot_before_phyla_filtering.png")) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
65 pngfile_post_phyla_filtering<- gsub("[ ]+", "", paste(options$outdir,"/barplot_after_phyla_filtering.png")) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
66 htmlfile <- gsub("[ ]+", "", paste(options$htmlfile)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
67 |
| 1 | 68 ### overwrite the write_biom function for proper BIOM format |
| 69 ### https://github.com/smdabdoub/biomformat/blob/master/R/IO-methods.R#L124 | |
| 70 write_biom <- function(x, biom_file){ | |
| 71 cat(toJSON(x, always_decimal=TRUE, auto_unbox=TRUE), file=biom_file) | |
| 72 } | |
| 73 | |
|
0
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
74 ### This function accepts different two different type of BIOM file format |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
75 readBIOM<-function(inBiom){ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
76 tryCatch({ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
77 phyloseq_obj<-import_biom(inBiom,parallel=TRUE) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
78 return(phyloseq_obj) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
79 }, |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
80 error=function(e){ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
81 biom_obj<-read_biom(inBiom) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
82 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
83 otu_matrix = as(biom_data(biom_obj), "matrix") |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
84 OTU_TABLE = otu_table(otu_matrix, taxa_are_rows=TRUE) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
85 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
86 taxonomy_matrix = as.matrix(observation_metadata(biom_obj), rownames.force=TRUE) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
87 TAXONOMY_TABLE = tax_table(taxonomy_matrix) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
88 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
89 metadata.temp<-sample_metadata(biom_obj) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
90 METADATA_TABLE<-plyr::ldply(metadata.temp, rbind) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
91 rownames(METADATA_TABLE)<-as.character(METADATA_TABLE$.id) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
92 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
93 phyloseq_obj = phyloseq(OTU_TABLE, TAXONOMY_TABLE,sample_data(METADATA_TABLE)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
94 return(phyloseq_obj) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
95 } |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
96 ) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
97 } |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
98 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
99 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
100 create_PDF<-function(pdf_file,OTU_DATAFRAME_BEFORE_FILTERING,OTU_DATAFRAME_AFTER_FILTERING,physeq_pre_phyla_filtering,physeq_post_phyla_filtering,kingdom_str,htmlfile,pngfile_before_filtering,pngfile_after_filtering,pngfile_pre_phyla_filtering,pngfile_post_phyla_filtering){ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
101 pdf(pdf_file); |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
102 barplot_before_filtering<-ggplot(OTU_DATAFRAME_BEFORE_FILTERING,aes(rownames(OTU_DATAFRAME_BEFORE_FILTERING))) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
103 geom_bar(aes(weight=Abundance),fill="tomato3") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
104 labs(title="Sample Depth Bar Chart",subtitle="Sample Vs Abundance (Before Filtering)",caption="source: Input Biom") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
105 xlab("Sample") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
106 ylab("Abundance") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
107 theme(axis.text.x=element_text(angle=65,vjust=0.6)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
108 print(barplot_before_filtering) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
109 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
110 barplot_after_filtering<-ggplot(OTU_DATAFRAME_AFTER_FILTERING,aes(rownames(OTU_DATAFRAME_AFTER_FILTERING))) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
111 geom_bar(aes(weight=Abundance),fill="blue") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
112 labs(title="Sample Depth Bar Chart",subtitle="Sample Vs Abundance (After Filtering)", caption="source: Input Biom") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
113 xlab("Sample") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
114 ylab("Abundance") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
115 theme(axis.text.x=element_text(angle=65,vjust=0.6)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
116 print(barplot_after_filtering) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
117 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
118 barplot_pre_phyla_filtering<-plot_bar(physeq_pre_phyla_filtering, x=colnames(sample_data(physeq_pre_phyla_filtering))[1], fill=kingdom_str) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
119 geom_bar(stat="identity", position="stack") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
120 labs(title=paste("Sample Depth Bar Chart",kingdom_str,sep=":"),subtitle="Sample Vs Abundance (Pre phyla Filtering)",caption="source: Input Biom") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
121 xlab("Sample") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
122 ylab("Abundance") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
123 theme(axis.text.x=element_text(angle=90,vjust=0.6)) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
124 scale_fill_hue() |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
125 print(barplot_pre_phyla_filtering) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
126 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
127 barplot_post_phyla_filtering<-plot_bar(physeq_post_phyla_filtering, x=colnames(sample_data(physeq_post_phyla_filtering))[1], fill=kingdom_str) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
128 geom_bar(stat="identity", position="stack") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
129 labs(title=paste("Sample Depth Bar Chart",kingdom_str,sep=":"),subtitle="Sample Vs Abundance (Post phyla Filtering)",caption="source: Input Biom") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
130 xlab("Sample") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
131 ylab("Abundance") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
132 theme(axis.text.x=element_text(angle=90,vjust=0.6)) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
133 scale_fill_hue() |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
134 print(barplot_post_phyla_filtering) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
135 garbage<-dev.off(); |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
136 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
137 #png('barplot_before_filtering.png') |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
138 bitmap(pngfile_before_filtering,"png16m") |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
139 barplot_before_filtering_png<-ggplot(OTU_DATAFRAME_BEFORE_FILTERING,aes(rownames(OTU_DATAFRAME_BEFORE_FILTERING))) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
140 geom_bar(aes(weight=Abundance),fill="tomato3") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
141 labs(title="Sample Depth Bar Chart",subtitle="Sample Vs Abundance (Before Filtering)",caption="source: Input Biom") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
142 xlab("Sample") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
143 ylab("Abundance") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
144 theme(axis.text.x=element_text(angle=65,vjust=0.6)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
145 print(barplot_before_filtering_png) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
146 garbage<-dev.off() |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
147 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
148 #png('barplot_after_filtering.png') |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
149 bitmap(pngfile_after_filtering,"png16m") |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
150 barplot_after_filtering_png<-ggplot(OTU_DATAFRAME_AFTER_FILTERING,aes(rownames(OTU_DATAFRAME_AFTER_FILTERING))) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
151 geom_bar(aes(weight=Abundance),fill="blue") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
152 labs(title="Sample Depth Bar Chart",subtitle="Sample Vs Abundance (After Filtering)", caption="source: Input Biom") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
153 xlab("Sample") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
154 ylab("Abundance") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
155 theme(axis.text.x=element_text(angle=65,vjust=0.6)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
156 print(barplot_after_filtering_png) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
157 garbage<-dev.off() |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
158 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
159 #png('barplot_pre_phyla_filtering.png') |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
160 bitmap(pngfile_pre_phyla_filtering,"png16m") |
| 1 | 161 #print(sample_data(physeq_pre_phyla_filtering)) |
|
0
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
162 barplot_pre_phyla_filtering<-plot_bar(physeq_pre_phyla_filtering, x=colnames(sample_data(physeq_pre_phyla_filtering))[1], fill=kingdom_str) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
163 geom_bar(stat="identity", position="stack") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
164 labs(title=paste("Sample Depth Bar Chart",kingdom_str,sep=":"),subtitle="Sample Vs Abundance (Pre Phyla Filtering)",caption="source: Input Biom") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
165 xlab("Sample") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
166 ylab("Abundance") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
167 theme(axis.text.x=element_text(angle=90,vjust=0.6)) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
168 scale_fill_hue() |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
169 print(barplot_pre_phyla_filtering) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
170 garbage<-dev.off() |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
171 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
172 #png('barplot_post_phyla_filtering.png') |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
173 bitmap(pngfile_post_phyla_filtering,"png16m") |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
174 barplot_post_phyla_filtering<-plot_bar(physeq_post_phyla_filtering, x=colnames(sample_data(physeq_post_phyla_filtering))[1], fill=kingdom_str) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
175 geom_bar(stat="identity", position="stack") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
176 labs(title=paste("Sample Depth Bar Chart",kingdom_str,sep=":"),subtitle="Sample Vs Abundance (Post Phyla Filtering)",caption="source: Input Biom") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
177 xlab("Sample") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
178 ylab("Abundance") + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
179 theme(axis.text.x=element_text(angle=90,vjust=0.6)) + |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
180 scale_fill_hue() |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
181 print(barplot_post_phyla_filtering) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
182 garbage<-dev.off() |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
183 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
184 create_HTML(htmlfile) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
185 } |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
186 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
187 create_HTML<-function(htmlfile){ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
188 htmlfile_handle <- file(htmlfile) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
189 html_output = c('<html><body>', |
| 1 | 190 '<table align="center">', |
|
0
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
191 '<tr>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
192 '<td valign="middle" style="vertical-align:middle;">', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
193 '<a href="pdffile.pdf"><img src="barplot_before_filtering.png"/></a>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
194 '</td>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
195 '</tr>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
196 '<tr>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
197 '<td valign="middle" style="vertical-align:middle;">', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
198 '<a href="pdffile.pdf"><img src="barplot_after_filtering.png"/></a>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
199 '</td>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
200 '</tr>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
201 '<tr>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
202 '<td valign="middle" style="vertical-align:middle;">', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
203 '<a href="pdffile.pdf"><img src="barplot_before_phyla_filtering.png"/></a>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
204 '</td>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
205 '</tr>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
206 '<tr>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
207 '<td valign="middle" style="vertical-align:middle;">', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
208 '<a href="pdffile.pdf"><img src="barplot_after_phyla_filtering.png"/></a>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
209 '</td>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
210 '</tr>', |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
211 '</table>', |
| 1 | 212 '</body></html>'); |
|
0
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
213 writeLines(html_output, htmlfile_handle); |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
214 close(htmlfile_handle); |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
215 } |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
216 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
217 convert_phyloseq_otutable_to_dataframe<-function(physeq_obj){ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
218 temp.df<-data.frame(otu_table(physeq_obj)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
219 temp.df.counts<-as.data.frame(colSums(temp.df)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
220 colnames(temp.df.counts)<-"Abundance" |
| 1 | 221 #print(temp.df.counts) |
|
0
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
222 return(temp.df.counts) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
223 } |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
224 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
225 if(!is.null(options$biom)){ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
226 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
227 #physeq<-import_biom(options$biom) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
228 physeq<-readBIOM(options$biom) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
229 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
230 if(length(rank_names(physeq)) == 8){ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
231 tax_table(physeq) <- tax_table(physeq)[,-1] |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
232 colnames(tax_table(physeq)) <- c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species") |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
233 } else { |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
234 colnames(tax_table(physeq)) <- c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species") |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
235 } |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
236 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
237 ### select column name from sample table for nmds plot |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
238 ## which(colnames(sample_data(biom)) == "vegetation_type_id") |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
239 #category_type<-colnames(sample_data(physeq))[options$subset] |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
240 #category_type <- options$subset |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
241 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
242 ### obtain the unique value in the selected column from sample table |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
243 #category_option<-unique(sample_data(physeq))[,options$subset] |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
244 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
245 }else{ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
246 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
247 ### read the data into correct data type to create phyloseq object |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
248 otu_table<-as.matrix(read.table(options$otu_table,header=T,sep="\t")) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
249 tax_table<-as.matrix(read.table(options$tax_table,header=T,sep="\t")) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
250 sample_table<-read.table(options$meta_table,header=T,sep="\t",stringsAsFactors=F) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
251 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
252 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
253 ### select column name from sample table for nmds plot |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
254 #category_type<-colnames(sample_table)[options$category] |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
255 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
256 ### obtain the unique value in the selected column from sample table |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
257 #category_option<-unique(sample_table[,options$category]) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
258 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
259 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
260 ### create a sample object for phyloseq |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
261 sample_object<-sample_data(sample_table) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
262 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
263 ### create otu object for phyloseq |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
264 OTU<-otu_table(otu_table, taxa_are_rows = TRUE) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
265 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
266 ### create tax object for phyloseq |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
267 TAX<-tax_table(tax_table) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
268 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
269 ### create a phyloseq object |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
270 physeq = phyloseq(OTU,TAX,sample_object) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
271 } |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
272 ### make the first column to be the sample ID in the phyloseq object |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
273 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
274 firstColumn = sample_data(physeq)[,1] |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
275 row_names = rownames(sample_data(physeq)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
276 check = all( firstColumn == row_names) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
277 if(!check){ |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
278 sample_data(physeq) <- cbind(SampleID= rownames(sample_data(physeq)),sample_data(physeq)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
279 } |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
280 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
281 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
282 ### extract otu table from phyloseq object |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
283 before_filtering_dataframe_sampleCounts<-convert_phyloseq_otutable_to_dataframe(physeq) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
284 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
285 ### filtering OTUs based on cutoff value (e.g., 5) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
286 #physeq_temp =genefilter_sample(physeq, filterfun_sample(function(x) x > cutoff_value), A=0.1*nsamples(physeq)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
287 physeq_temp =genefilter_sample(physeq, filterfun_sample(function(x) x > cutoff_value), A=filter*nsamples(physeq)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
288 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
289 ### phyloseq object after filtered |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
290 physeq_filter = prune_taxa(physeq_temp, physeq) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
291 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
292 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
293 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
294 ## Transform to even sampling depth |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
295 #physeq_filter = transform_sample_counts(physeq_filter, function(x) 1E6 * x/sum(x)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
296 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
297 #after_filtering.dataframe<-data.frame(otu_table(physeq_filter)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
298 #after_filtering_dataframe_sampleCounts<-as.data.frame(colSums(after_filtering.dataframe)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
299 #colnames(after_filtering_dataframe_sampleCounts)<-"Abundance" |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
300 after_filtering_dataframe_sampleCounts<-convert_phyloseq_otutable_to_dataframe(physeq_filter) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
301 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
302 # create_PDF(pdffile,before_filtering_dataframe_sampleCounts,after_filtering_dataframe_sampleCounts,htmlfile,pngfile_before_filtering,pngfile_after_filtering) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
303 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
304 # kingdom_str <- as.numeric(kingdom_str) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
305 ## Keep only the most abundant five phyla |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
306 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
307 ### Phyla - Pre transformation (Transform to even sampling depth) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
308 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
309 #physeq_filter_pre_transform = tapply(taxa_sums(physeq_filter), tax_table(physeq_filter)[, kingdom_str], sum,na.rm=TRUE) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
310 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
311 phylum.sum_pre_transform= tapply(taxa_sums(physeq_filter), tax_table(physeq_filter)[, kingdom_str], sum,na.rm=TRUE) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
312 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
313 topphyla_pre_transform = names(sort(phylum.sum_pre_transform, TRUE))[1:keep] |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
314 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
315 physeq_filter_pre_transform = prune_taxa((tax_table(physeq_filter)[, kingdom_str] %in% topphyla_pre_transform), physeq_filter) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
316 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
317 ### Phyla - Post Transformation (Transform to even sampling depth) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
318 physeq_filter_post_transform = transform_sample_counts(physeq_filter, function(x) 1E6 * x/sum(x)) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
319 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
320 phylum.sum_post_transform = tapply(taxa_sums(physeq_filter_post_transform), tax_table(physeq_filter_post_transform)[, kingdom_str], sum,na.rm=TRUE) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
321 ### number of most abundance phyla to keep |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
322 topphyla_post_transform = names(sort(phylum.sum_post_transform, TRUE))[1:keep] |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
323 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
324 physeq_filter_post_transform = prune_taxa((tax_table(physeq_filter_post_transform)[, kingdom_str] %in% topphyla_post_transform), physeq_filter_post_transform) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
325 |
| 1 | 326 ### remove samples with zero value |
| 327 otu_table(physeq_filter_post_transform)<-otu_table(physeq_filter_post_transform)[,colSums(otu_table(physeq_filter_post_transform)) > 0] | |
|
0
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
328 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
329 create_PDF(pdffile,before_filtering_dataframe_sampleCounts,after_filtering_dataframe_sampleCounts,physeq_filter_pre_transform,physeq_filter_post_transform,kingdom_str,htmlfile,pngfile_before_filtering,pngfile_after_filtering,pngfile_pre_phyla_filtering,pngfile_post_phyla_filtering) |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
330 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
331 ### convert phyloseq object to metagenomeSeq - preparing for BIOM output |
| 1 | 332 #metagenomeSeq_obj <- phyloseq_to_metagenomeSeq(physeq_filter_post_transform) |
| 333 #metagenomeSeq_biom <- MRexperiment2biom(metagenomeSeq_obj) | |
| 334 | |
| 335 biom_obj=make_biom(otu_table(physeq_filter_post_transform),sample_metadata=sample_data(physeq_filter_post_transform),observation_metadata=tax_table(physeq_filter_post_transform),matrix_element_type="float") | |
| 336 biom_obj_2_metagenomeSeq_obj<-biom2MRexperiment(biom_obj) | |
| 337 metagenomeSeq_biom <- MRexperiment2biom(biom_obj_2_metagenomeSeq_obj) | |
| 338 | |
|
0
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
339 |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
340 ## write biom file |
|
910739de7b80
planemo upload commit 555f91999a1164a4420492126fa7713c89e3c5f5-dirty
simon-gladman
parents:
diff
changeset
|
341 write_biom(metagenomeSeq_biom, biom_file=options$outbiom) |
