-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
733 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
Package: qiime2R | ||
Type: Package | ||
Title: qiime2R | ||
Version: 0.99.13 | ||
Version: 0.99.20 | ||
Author: Jordan Bisanz <[email protected]> | ||
Maintainer: Jordan Bisanz <[email protected]> | ||
Description: Importing QIIME2 artifacts and associated data into R sessions. | ||
License: MIT | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 6.0.1 | ||
RoxygenNote: 7.1.0 | ||
Suggests: knitr, rmarkdown | ||
VignetteBuilder: knitr | ||
biocViews: Microbiome, DataImport | ||
|
@@ -20,6 +20,7 @@ Imports: | |
phyloseq (>= 1.22.3), | ||
Hmisc (>= 4.1-1), | ||
yaml (>= 2.2.0), | ||
tidyr (>= 0.8.3), | ||
dplyr (>= 0.8.1), | ||
stats, | ||
utils | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#' checks if metadata is in qiime2 (.tsv) | ||
#' | ||
#' Checks to see if a file is in qiime2 metadata format, ie contains #q2:types line dictating the type of variable (categorical/numeric) | ||
#' | ||
#' @param file path to the input file, ex: file="~/data/moving_pictures/table.qza" | ||
|
||
#' @return TRUE/FALSE | ||
#' | ||
#' @examples \dontrun{metadata<-is_q2metadata("q2metadata.tsv")} | ||
#' @export | ||
#' | ||
#' | ||
|
||
is_q2metadata <- function(file){ | ||
suppressWarnings( | ||
if(grepl("^#q2:types", readLines(file)[2])){return(TRUE)}else{return(FALSE)} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#' Parse an imported q2 ordination text file | ||
#' | ||
#' @param artifact takes an artifact containing the unparsed ordination format (result of readLines) | ||
#' @param tmp the tmp dir for artifact | ||
#' | ||
#' @return a data.frame with feature IDs as row names and the columns: Kingdom, Phylum, Class, Order, Family, Genus, Species | ||
#' | ||
#' @examples \dontrun{ord<-parse_ordination(ordination_artifact, tmpdir)} | ||
#' @export | ||
#' | ||
|
||
|
||
parse_ordination <- function(artifact, tmp){ | ||
if(missing(artifact)){stop("Ordination not provided.")} | ||
if(missing(tmp)){stop("Temp directory not passed.")} | ||
|
||
artifact$data<-artifact$data[sapply(artifact$data, function(x) x!="")] | ||
|
||
for (i in 1:length(artifact$data)){ | ||
if(grepl("^Eigvals\\t|^Proportion explained\\t|^Species\\t|^Site\\t|^Biplot\\t|^Site constraints\\t", artifact$data[i])){ | ||
curfile=strsplit(artifact$data[i],"\t")[[1]][1] | ||
} else { | ||
write(artifact$data[i], paste0(tmp,"/", artifact$uuid, "/data/",curfile,".tmp"), append=TRUE) | ||
} | ||
} | ||
|
||
backup<-artifact$data | ||
artifact$data<-list() | ||
for (outs in list.files(paste0(tmp,"/", artifact$uuid,"/data"), full.names = TRUE, pattern = "\\.tmp")){ | ||
NewLab<-gsub(" ", "", toTitleCase(gsub("\\.tmp", "", basename(outs)))) | ||
artifact$data[[NewLab]]<-read.table(outs,sep='\t', header=FALSE) | ||
if(NewLab %in% c("Eigvals","ProportionExplained")){colnames(artifact$data[[NewLab]])<-paste0("PC",1:ncol(artifact$data[[NewLab]]))} | ||
if(NewLab %in% c("Site","SiteConstraints")){colnames(artifact$data[[NewLab]])<-c("SampleID", paste0("PC",1:(ncol(artifact$data[[NewLab]])-1)))} | ||
if(NewLab %in% c("Species")){colnames(artifact$data[[NewLab]])<-c("FeatureID", paste0("PC",1:(ncol(artifact$data[[NewLab]])-1)))} | ||
} | ||
artifact$data$Vectors<-artifact$data$Site #Rename Site to Vectors so this matches up with the syntax used in the tutorials | ||
artifact$data$Site<-NULL | ||
return(artifact) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#' Parse Q2 taxonomy | ||
#' | ||
#' @param taxonomy the imported taxonomy object (the result of read_qza() containing columns Feature.ID, Taxon, and Confidence) | ||
#' @param tax_sep The separator between taxonomic levels. Defaults to one compatible with both GreenGenes and SILVA ("; " OR ";") | ||
#' @param trim_extra Remove leading characters from taxonomic levels: ex: k__ or D_0__. TRUE/FALSE. default=TRUE | ||
#' | ||
#' @return a data.frame with feature IDs as row names and the columns: Kingdom, Phylum, Class, Order, Family, Genus, Species | ||
#' | ||
#' @examples \dontrun{taxonomy<-parse_taxonomy(taxonomy_artifact)} | ||
#' @export | ||
#' | ||
|
||
|
||
parse_taxonomy <- function(taxonomy, tax_sep, trim_extra){ | ||
if(missing(taxonomy)){stop("Taxonomy Table not supplied.")} | ||
if(missing(trim_extra)){trim_extra=TRUE} | ||
if(missing(tax_sep)){tax_sep="; |;"} | ||
if(sum(colnames(taxonomy)==c("Feature.ID","Taxon","Confidence"))!=3){stop("Table does not match expected format (conames(obj) are Feature.ID, Taxon, Confience)")} | ||
|
||
taxonomy$Confidence<-NULL | ||
if(trim_extra){ | ||
taxonomy$Taxon<-gsub("[kpcofgs]__","", taxonomy$Taxon) #remove leading characters from GG | ||
taxonomy$Taxon<-gsub("D_\\d__","", taxonomy$Taxon) #remove leading characters from SILVA | ||
} | ||
taxonomy<-suppressWarnings(taxonomy %>% separate(Taxon, c("Kingdom","Phylum","Class","Order","Family","Genus","Species"), sep=tax_sep)) | ||
taxonomy<-apply(taxonomy, 2, function(x) if_else(x=="", NA_character_, x)) | ||
taxonomy<-as.data.frame(taxonomy) | ||
rownames(taxonomy)<-taxonomy$Feature.ID | ||
taxonomy$Feature.ID<-NULL | ||
return(taxonomy) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#' A ggplot2 theme for publication-style figures | ||
#' | ||
#' @examples \dontrun{ggplot(data) + theme_q2r()} | ||
#' @export | ||
#' | ||
#' | ||
#' | ||
|
||
theme_q2r<- function () { | ||
theme_classic(base_size=8, base_family="Helvetica") + | ||
theme(panel.border = element_rect(color="black", size=1, fill=NA)) + | ||
theme(axis.line = element_blank(), strip.background = element_blank()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#' Generates a read manifest for importing sequencing data into qiime2 | ||
#' | ||
#' Scans a directory for files with matching sequencing data (default: fastq.gz) and then generates a q2 compliant manifest. | ||
#' | ||
#' @param outfile filename for output (default: manifest_[timestamp].txt) | ||
#' @param directory directory containing reads | ||
#' @param extension file extension (default: .fastq.gz) | ||
#' @param paired are reads in paired format? TRUE/FALSE (default=FALSE) | ||
#' @param Fwd string used to denote a forward read (default= _R1) | ||
#' @param Rev string used to denote a reverse read (default= _R2) | ||
#' | ||
#' @examples \dontrun{write_q2manifest("q2manifest.txt","/yourdirhere/reads/", extension=".fastq.gz", paired=TRUE)} | ||
#' @export | ||
#' | ||
|
||
write_q2manifest<-function(outfile, directory, extension, paired){ | ||
if(missing(outfile)){outfile<-paste0("q2manifest_", gsub(" |:","", timestamp(prefix="", suffix="")),".txt")} | ||
if(missing(directory)){stop("Directory containing reads not provided.")} | ||
if(missing(extension)){extension=".fastq.gz"} | ||
if(missing(paired)){paired=FALSE} | ||
if(missing(Fwd)){Fwd="_R1"} | ||
if(missing(Rev)){Rev="_R2"} | ||
|
||
files<-list.files(reads, pattern=gsub("\\.", "\\.", extension)) | ||
|
||
if(!paired){ | ||
output<-data.frame(`sample-id`=gsub(gsub("\\.", "\\.", extension), "", files), `absolute-filepath`=paste0(getwd(), "/", files), check.names = FALSE) | ||
write.table(output, file=outfile, row.names=F, quote=F, sep="\t") | ||
} else { | ||
output<-data.frame(`sample-id`=gsub(gsub("\\.", "\\.", extension), "", files), file=paste0(getwd(), "/", files), check.names = FALSE) | ||
output$Read<-case_when( | ||
grepl(Fwd, output$file)~"forward-absolute-filepath", | ||
grepl(Rev, output$file)~"reverse-absolute-filepath", | ||
TRUE~"Error" | ||
) | ||
if(sum(grep("Error", output$Read))==0){stop("Could not assign all reads to forward or reverse in paired mode.")} | ||
output$`sample-id`<-gsub(Fwd, "", output$`sample-id`) | ||
output$`sample-id`<-gsub(Rev, "", output$`sample-id`) | ||
output<-spread(output, key=Read, value=file) | ||
write.table(output, file=outfile, row.names=F, quote=F, sep="\t") | ||
} | ||
|
||
message("Manifest written to", outfile) | ||
} | ||
|
Oops, something went wrong.