Mercurial > repos > qfabrepo > metadegalaxy_phyloseq_abundance_factor
comparison phyloseq_abundance_factor.r @ 0:3856a1590a11 draft default tip
"planemo upload for repository https://github.com/QFAB-Bioinformatics/metaDEGalaxy/tree/master/phyloseq_abundance_factor commit 8bd68662b72404f6291e9628327dcb109b5fa55e"
| author | qfabrepo |
|---|---|
| date | Mon, 14 Sep 2020 08:02:08 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3856a1590a11 |
|---|---|
| 1 | |
| 2 library('getopt') | |
| 3 suppressPackageStartupMessages(library('phyloseq')) | |
| 4 Sys.setenv("DISPLAY"=":1") | |
| 5 | |
| 6 | |
| 7 cmd_args <- commandArgs(TRUE) | |
| 8 options(warn=-1) | |
| 9 option_specification = matrix(c( | |
| 10 'biomfile','b',2,'character', | |
| 11 'metafile','m',2,'character', | |
| 12 'xcolumn','x',2,'numeric', | |
| 13 'lcolumn','l',2,'numeric', | |
| 14 'factor1','f1',2,'numeric', | |
| 15 'factor2','f2',1,'numeric', | |
| 16 'outdir','o',2,'character', | |
| 17 'htmlfile','h',2,'character' | |
| 18 ),byrow=TRUE,ncol=4); | |
| 19 | |
| 20 | |
| 21 options <- getopt(option_specification); | |
| 22 options(bitmapType="cairo") | |
| 23 | |
| 24 | |
| 25 | |
| 26 if (!is.null(options$outdir)) { | |
| 27 # Create the directory | |
| 28 dir.create(options$outdir,FALSE) | |
| 29 } | |
| 30 | |
| 31 | |
| 32 galaxy_biom <- import_biom(options$biomfile) | |
| 33 galaxy_map <- import_qiime_sample_data(options$metafile) | |
| 34 | |
| 35 | |
| 36 tax_col_norm <- c("Kingdom","Phylum","Class","Order","Family","Genus","Species") | |
| 37 tax_col_extra <- c("None","Kingdom","Phylum","Class","Order","Family","Genus","Species") | |
| 38 | |
| 39 number.of.tax.rank<-length(colnames(tax_table(galaxy_biom))) | |
| 40 | |
| 41 if( number.of.tax.rank == 7){ | |
| 42 colnames(tax_table(galaxy_biom)) <- tax_col_norm | |
| 43 }else{ | |
| 44 colnames(tax_table(galaxy_biom)) <- tax_col_extra | |
| 45 } | |
| 46 | |
| 47 | |
| 48 AIP_galaxy <- merge_phyloseq(galaxy_biom,galaxy_map) | |
| 49 | |
| 50 | |
| 51 pdffile <- gsub("[ ]+", "", paste(options$outdir,"/abundance.pdf")) | |
| 52 pngfile_abundance <- gsub("[ ]+", "", paste(options$outdir,"/abundance.png")) | |
| 53 htmlfile <- gsub("[ ]+", "", paste(options$htmlfile)) | |
| 54 | |
| 55 | |
| 56 ###### To obtain the column name in metadata ################ | |
| 57 x.selectedColumn<-colnames(galaxy_map)[options$xcolumn] | |
| 58 l.selectedColumn<-colnames(galaxy_map)[options$lcolumn] | |
| 59 f1.selectedColumn<-colnames(galaxy_map)[options$factor1] | |
| 60 | |
| 61 factor.var <- f1.selectedColumn | |
| 62 | |
| 63 if(!is.null(options$factor2)){ | |
| 64 f2.selectedColumn<-colnames(galaxy_map)[options$factor2] | |
| 65 factor.var <- paste(f1.selectedColumn,f2.selectedColumn,sep="+") | |
| 66 } | |
| 67 | |
| 68 | |
| 69 # Produce PDF file | |
| 70 pdf(pdffile); | |
| 71 plot_bar(AIP_galaxy,x=x.selectedColumn,facet_grid = paste('~', factor.var),fill=l.selectedColumn) | |
| 72 garbage<-dev.off(); | |
| 73 | |
| 74 #png('abundance_1.png') | |
| 75 bitmap(pngfile_abundance,"png16m") | |
| 76 plot_bar(AIP_galaxy,x=x.selectedColumn,facet_grid = paste('~', factor.var),fill=l.selectedColumn) | |
| 77 garbage<-dev.off() | |
| 78 | |
| 79 # Produce the HTML file | |
| 80 htmlfile_handle <- file(htmlfile) | |
| 81 html_output = c('<html><body>', | |
| 82 '<table align="center">', | |
| 83 '<tr>', | |
| 84 '<td valign="middle" style="vertical-align:middle;">', | |
| 85 '<a href="abundance.pdf"><img src="abundance.png"/></a>', | |
| 86 '</td>', | |
| 87 '</tr>', | |
| 88 '</table>', | |
| 89 '</html></body>'); | |
| 90 writeLines(html_output, htmlfile_handle); | |
| 91 close(htmlfile_handle); |
