Git Product home page Git Product logo

Comments (4)

fconstancias avatar fconstancias commented on August 16, 2024 1

Hi. You can use the kreport2mpa.py script from bracken (https://github.com/jenniferlu717/Bracken) to generate mpa reports and you can merge them using one of the metaphlan2 script and then load everything into phyloseq :)

from centrifuge.

fconstancias avatar fconstancias commented on August 16, 2024

I am also interested in that ... Very easy then to process the data with phyloseq

from centrifuge.

markopetek avatar markopetek commented on August 16, 2024

I was able to generate the mpa reports and merge them using MetaPhlAn2/utils/merge_metaphlan_tables.py but don't know how to import them using phyloseq R library. Please help.

from centrifuge.

ashishdamania avatar ashishdamania commented on August 16, 2024

This is a way to do it. Not sure if this is efficient.
It is heavily based from this page:
https://joey711.github.io/phyloseq/import-data.html

#This assumes you have access to Linux/Mac or other similar computing environment

#This needs to be done on Bash

# Create file for the OTU count
Computer:~$ cut -f2- Merged_File.txt >  Merged_file_OTU.txt

#Create file for Taxonomy
Computer:~$ cut -f1  Merged_File.txt > Merged_file_TAX.txt

Remove “ID” from the taxonomy file before loading it in the R (This is the on the exterme top left of the screen

#Now in the R Environment

library(phyloseq)
otumat=read.table("Merged_file_OTU.txt",fill=TRUE,header=TRUE,check.names = F)

#Convert table to matrix
otumat<-as.matrix(otumat)

#Count the depth of taxonomy
nc<-max(count.fields("Merged_file_TAX.txt",sep="|"))


#Use the count in previous step to fill in the RANKS as R1,R2  and so forth
tax<-read.table(" Merged_file_TAX.txt",sep="|",col.names = paste("R",1:nc,sep=""),fill=T)

#Convert table to matrix
taxmat<-as.matrix(tax)

#Number your rows as OTUs
rownames(otumat)<-paste0("OTU",1:nrow(otumat))

#This makes sure that both the OTUs and Taxnomy have same row ids
rownames(taxmat)<-rownames(otumat)

#Creates OTU table for Phyloseq
OTU<-otu_table(otumat,taxa_are_rows = T)

#Create taxnomy table for phyloseq
TAX<-tax_table(taxmat)


#This is where you get the phyloseq object
physeq=phyloseq(OTU,TAX)


#Load optional meta data (This is must for anything meaningful)
samat=read.table("Metadata.tsv")

#Merge sample metadata with the phyloseq object
physeq_with_samples<-merge_phyloseq(physeq,sample_data(data.frame(samat)))


#Save the data for later use so we don't have to repeat the above steps
save(physeq_with_samples,file="phyobject.rda")

Thanks!

from centrifuge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.