I must ask this question as I am not sure if it is difficult or easy. I'd like to extract a subgraph in igraph but with the following bindings: starting from Viridiplantae-3
to Proteobacteria-2
(see image)
I can find the path from shortest.path() but I am not sure how to extract a subgraph based on list of nodes. Because shortest.path will not include Proteobacteria-1
and Proteobacteria-2
. I don't want to include 100.2
:Viridiplantae-1
,Viridiplantae-2
and 68.1
:Stramenopiles-1
,Rhodophyta-1
.
In short, given Viridiplantae-3
and Proteobacteria-2
, I want to extract everything that is in the red.
Reproducible instructions:
library(ape)
library(igraph)
cat("(((Viridiplantae_1:1.22123006e-06,Viridiplantae_2:1.22123006e-06)100.2:0.9709833387,Viridiplantae_3:1.217705775)100.1:1.394125713,((Proteobacteria_1:0.2479324862,Proteobacteria_2:0.4385740351)100.3:0.696357212,(Rhodophyta_1:1.675875775,Stramenopiles_1:1.869948709)68.1:0.48853466)52.1:0.2231628399,Proteobacteria_3:0.8491431473);", file = "testTree.tre", sep = "\n")
cur_Tree <- read.tree("testTree.tre")
cur_Tree$node.label[1] <- "root"
cur_Grph <- as.igraph(cur_Tree)
cur_Grph is the graph in the image