R Markdown

This script shows you how to read in a Galaxy taxonomic report and output files with counts at the Species level only.

#Read in file from Unit 2 Example history
allTax <- read.table('Galaxy28-[Report__Kraken2_on_data_1].tabular', sep="\t", fill = TRUE)

#Create dataframe with just species rows using logical filter
sRows <- allTax[grepl("\\|s", allTax[["V1"]]),]

#Use for loop with gsub to simplify Species name
for (i in 1:nrow(sRows)){
  sRows[i,1]<-gsub("d__.*s__","",sRows[i,1],perl=TRUE)
}

#Format column names and write file
names(sRows) <- c('Species','Count')
write.csv(sRows,"Species.csv",row.names=FALSE,quote=FALSE)