Giter Club home page Giter Club logo

Comments (1)

stefpeschel avatar stefpeschel commented on August 14, 2024 1

Hi,

I think these are two questions: How to plot only nodes that are directly connected to a certain node? How to plot nodes belonging to a certain cluster?
Since I'm not sure what you're interested in, I'll give you an example for both :)

library(NetCoMi)
library(phyloseq)

# Load data sets from American Gut Project (from SpiecEasi package)
data("amgut2.filt.phy")

# Agglomerate to genus level
amgut_genus <- tax_glom(amgut2.filt.phy, taxrank = "Rank6")

# Rename taxonomic table and make Rank6 (genus) unique
amgut_genus_renamed <- renameTaxa(amgut_genus, 
                                  pat = "<name>", 
                                  substPat = "<name>_<subst_name>(<subst_R>)",
                                  numDupli = "Rank6")

# Network construction
amgut_net <- netConstruct(amgut_genus_renamed, 
                          taxRank = "Rank6",
                          measure = "pearson",
                          #filtTax = "highestVar",
                          #filtTaxPar = list(highestVar = 50),
                          zeroMethod = "pseudoZO",
                          normMethod = "clr",
                          sparsMethod = "threshold", 
                          thresh = 0.3)

# Network analysis
amgut_props <- netAnalyze(amgut_net)

### Network plots ###
# Plot the whole network
plot(amgut_props, nodeColor = "cluster")

# Plot only nodes belonging to cluster 1
clust1 <- amgut_props$clustering$clust1
cl1 <- names(clust1[clust1 == 1])

plot(amgut_props, nodeFilter = "names", nodeFilterPar = cl1)

# Plot only nodes that are connected to a certain taxon (here Salmonella)
sel <- amgut_net$edgelist1[amgut_net$edgelist1$v1 == "Salmonella", "v2"]
sel <- c("Salmonella", sel)

# Alternatively, you can extract them from the adjacency matrix
adja_salmon <- amgut_net$adjaMat1["Salmonella", ]
sel <- names(adja_salmon[adja_salmon != 0])

plot(amgut_props, nodeFilter = "names", nodeFilterPar = sel)

from netcomi.

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.