Antes que nada. Cada genoma puede contener ID’s correspondientes a plasmidos. En este tutorial solo usare los cromosomas de cada especie. Es decir, omitiremos los plásmidos.
for f in *.fna; do seqkit split --by-id $f;done
Luego creo una carpeta (only_chromosomes) y paso ahi los Fasta correspondientes a los cromosomas.
Vamos a usar otro programa para la alineación ya que el archivo maf de salida es mas informativo y facil de reformatear.
Primero necestiamos un archivo con los genomas de entrada: Este debe traer el arbol filogenetico en una linea y la etiqueta de los genomas con su respectiva ubicación.
Es muy importante que los nodos del el arbol no estén etiquetados o si lo están, que esta etoqueta sea distinta para cada nodo. De lo contrario habrá errores a la hora de correr cactus
Con el nombre de los nodos me refiero a la etiqueta que esta entre ) y :
((JA-2-3Ba:0.0670244,JA-3-3Ab:0.0689779)0.991577:0.125746,(PCC_7336:0.294593,((ABRG5-3:0.216985,PCC_7502:0.222311)0.44487:0.0568413,PCC_7367:0.240041)0.91807:0.216802)0.9915770:0.1257460);
JA-2-3Ba /home/lalibelulalo/PIPELINES_2023/ASR_GENOMES/Pseudoanabaena_clade/fna/only_chromosomes/JA-2-3Ba.fna
JA-3-3Ab /home/lalibelulalo/PIPELINES_2023/ASR_GENOMES/Pseudoanabaena_clade/fna/only_chromosomes/JA-3-3Ab.fna
PCC_7336 /home/lalibelulalo/PIPELINES_2023/ASR_GENOMES/Pseudoanabaena_clade/fna/only_chromosomes/PCC_7336.fna
ABRG5-3 /home/lalibelulalo/PIPELINES_2023/ASR_GENOMES/Pseudoanabaena_clade/fna/only_chromosomes/ABRG5-3.fna
PCC_7502 /home/lalibelulalo/PIPELINES_2023/ASR_GENOMES/Pseudoanabaena_clade/fna/only_chromosomes/PCC_7502.fna
PCC_7367 /home/lalibelulalo/PIPELINES_2023/ASR_GENOMES/Pseudoanabaena_clade/fna/only_chromosomes/PCC_7367.fna
Creo un ambiente para correr cactus en la carpeta de cactus Esto que sigue lo hago en la carpeta de cactus
cd cactus
virtualenv -p python3 cactus_env
echo "export PATH=$(pwd)/bin:\$PATH" >> cactus_env/bin/activate
echo "export PYTHONPATH=$(pwd)/lib:\$PYTHONPATH" >> cactus_env/bin/activate
source cactus_env/bin/activate
python3 -m pip install -U setuptools pip
python3 -m pip install -U .
python3 -m pip install -U -r ./toil-requirement.txt
Corro cactus:
cactus ./thermosynechococcus ./examples/evolverThermosynechococcus.txt ./evolverThermosynechococcus.hal
como resultado tenemos el archivo evolverPico.hal
Pasamos dicho archivo a formato mfa Usamos a JA-2-3Ba como referencia:
hal2maf evolverThermosynechococcus.hal evolverThermosynechococcus.hal.maf --refGenome PCC_6312 --noAncestors --inMemory
como resultado tenemos el archivo evolverThermosynechococcus.hal.maf
###
##maf version=1 scoring=N/A
# hal (D10:0.207465,((PCC_6312:0.219069,(PCC_6715:0.108601,((HN-54:0.0249223,(SCTE542:0.0196779,(CL-1:0.00898716,TA-1:0.0104842)0.667697:0.0123202)0.316847:0.00806593)0.426584:0.0112348,(NK55a:0.0270078,BP-1:0.0251884)0.771252:0.0190448)0.940495:0.0609613)0.968315:0.131647)0.743431:0.0826038,(MBIC11017:0.0318053,(Moss_Beach:0.0103806,S15:0.002769)0.908037:0.0350612)0.992272:0.276644)1:0.207465)Anc00;
a
s PCC_6312 0 1000 + 3697276 AGCCGTGATGAATTATTGCAAGCAAAAAATCAAATAGATTTTTCCCATTTAGGTATTTCTAAGCGGGATTCTGATTATACCATGCCCAATCCAAATTCATATTCCCAGTTTGCATCCCCAGAGGCCAGTGTGGAGATTTCCCCAGAAACATTTTGGAATCAAATTCTAGAGCGACTACAACTCCTCCTCAGCCGCCCCACCTTTGAAACCTGGATTAAAACTGCCACTGTGGAAAGCTTTGATGGTAAGGTGCTGGTGGTCTGTATGCCAAATCCTTTTGCCCGTAATTGGCTGCATAAGTACTATCTAAAAACCATCTCTGATGTTGCCCATGATGTAATGGGATATCCGGTGGATATCCGCTTAGCGATTGCCCAAGGCAGTGAAGAGTCAACAGAGATACCTAATCCTCCTCCCCAAACCATGGAGCTGGTACCGAATCAATCTGGCCCCTCTTTGCTCGTCCCGCCCCCAGCCCCCAGTCGTGACCGCATTGGCGAACTTAATCCCAAGTATGTTTTTTCCCGCTATGTGGTTGGGCCCAATAACCGCATGGCCCACGCGGCCTGTTTAGCAGTTGCCGAGTCCCCAGGCCGTGAATTTAACCCCCTCTTTCTCTGCGGAGGAGTCGGCCTGGGAAAAACTCATTTGATGCAGGCCATTGGCCACTATCGGCTCGAAATTGACCCCCAGGCCAAAATTTTCTATGTTTCCACAGAGCAATTTACCAATGACCTAATTGCGGCAATTCGCAAAGATAGTATGCAAACTTTTCGGGAGCACTATCGGGCCGTAGATGTCATTTTGGTCGATGATATTCAATTTATTGAAGGCAAAGAATACACCCAAGAAGAGTTTTTCCACACCTTTAACACCCTCCATGAAGCCGGTAAACAGGTGGTTCTCGCCTCAGATCGCCCCCCGAGCCAAATTCCCCGGCTCCAAGAACGACTGTGTTCACGTTTTTCTATGGGCCTGATTGCGGATATTCAACCGCCAG
a
s PCC_6312 1000 1000 + 3697276 ATTTAGAAACTAGAATGGCGATTCTCCAGAAAAAAGCCGAGTACGAAAACATTCGCTTACCGAGGGAAGTTGTGGAATACATTGCCTCTAGCTACACCTCGAACATCCGCGAACTAGAGGGCGCGTTAATTCGGGCTGTGGCTTATATTTCAATTTCTGGCTTATCTATGACTGTGGAAAATATTGCCCCAGTTTTAAATCCTGCCAATCGAAAAATTGAAGCCTCACCAGAAATTATTTTCAACGTGATTACAGAGTCCTTTGGCATTGCAATTGAAGACCTCAAAGGCAACTCACGGCGGCGAGAAATTAGCGTGGCCCGCCAGGTGGGGATGTACCTGATGCGTCAATACACCGGGTTGAGCTTACCCAAAATTGGCGAAGAATTTGGCGGCAAAGATCATACGACCGTGATGTATAGCTGTGAAAAAGTGACAGAACTTCAGCGCACCGATCCGGAAATGGGTTCCCTTTTGAGACAACTCAGCGACCGGATTAATCTTGCCAGTCGCCCCGCCGAAGCCTGAGGAAAACCTCAGAACTCAATAAGATTCAAGCAGAGTTTTGTGGAAAAGTGCCTATTTTCTGTGGAAAACCTTGGGAAAAACCTGTGGAAAACATGAAGGAGTTGTGGAAAAAGATTACAAAATTTAATGTCCTGTGGAAAACTTACCTACTTTATCCACAGGTTTTCCACAGGCTTAAAGTGGTTCAATCCCTTATGGAAAGAGACTTTCAAAAAGTTTTCCACAGTTTCCACAGGCCCTACTACTACTATAAGAAGATCTATTTATCTAGAATTAGTAGATCAGAGACTATTAAAAAAAGAAAATATGCGGTTATGTTCTAGTGAACTGCTTAAGTCAGGATTGTGCATTGAGGTAGTAAATTCTTTTGTTCTTAAATCAGGACTGAGCCTAGAAAACCTGGAAACTGCTTTGAAGATCGGAATAAATTTTTTCAATCTGCTGAGATTCTGACTCGTTATCCCCAGTTGAGA
... etc
###
Reformateo las etiquetas de los genomas:
Esta parte lo hago con expresiones regulares en el bloc de notas.
Copio evolverThermosynechococcus.hal.maf a la carpeta de chromosomes_only y convierto maf a fasta:
mafToFastaStitcher --maf evolverThermosynechococcus.hal.maf --seqs PCC_6312.fna,BP-1.fna,CL-1.fna,D10.fna,HN-54.fna,MBIC11017.fna,Moss_Beach.fna,NK55a.fna,PCC_6715.fna,S15.fna,SCTE542.fna,TA-1.fna --breakpointPenalty 5 --interstitialSequence 20 --outMfa evolverThermosynechococcus.hal.maf.sed.cactus
Quito las columnas con muchos gaps:
trimal -in evolverPico.hal.maf.sed.mfa -gt 0.8 -out evolverPico.hal.maf.sed.mfa.trimal
#convierto a philyp
python3 Fasta2Phylip.py only_chromosomes/
Obtengo las coordenadas del palindromo: En esta parte edito la linea28 del código (Spp == ‘PCC_6312’). Spp es la especie que estoy usando como referencia.
python3 AlignmentPalindromeCoords.py only_chromosomes/
El ultimo script tiene como salida el archivo Orthologues_Palindrome_sites.txt el cual contiene 2 columnas, una con el nombre del archivo del ortólogo y otra con el intervalo de sitios en donde se encuentra el palindromo:
###
FILE PAL START END
evolverThermosynechococcus.hal.maf.sed.cactus.phy CAGGCCTG 3911 3918
evolverThermosynechococcus.hal.maf.sed.cactus.phy CAGGCCTG 8028 8035
evolverThermosynechococcus.hal.maf.sed.cactus.phy CAGGCCTG 11080 11087
evolverThermosynechococcus.hal.maf.sed.cactus.phy CAGGCCTG 13147 13154
evolverThermosynechococcus.hal.maf.sed.cactus.phy CAGGCCTG 14215 14222
evolverThermosynechococcus.hal.maf.sed.cactus.phy CAGGCCTG 15622 15629
evolverThermosynechococcus.hal.maf.sed.cactus.phy CAGGCCTG 16413 16420
evolverThermosynechococcus.hal.maf.sed.cactus.phy CAGGCCTG 17841 17848
evolverThermosynechococcus.hal.maf.sed.cactus.phy CAGGCCTG 19015 19022
... etc
###
primero cargo las librerias necesarias
library(ggplot2)
library(ggtree)
library(ape)
library(tidyverse)
library(tidytree)
library(phangorn)
library(dplyr)
Primero cargo Orthologues_Palindrome_sites.txt del paso anterior.
## /home/lalibelulalo/PIPELINES_2023/ASR_GENOMES/Thermosynechococcus_clade/
Sites <- read.table("fna/Orthologues_Palindrome_sites.txt", sep = "\t", header = TRUE)
Creo la matriz que va a contener unicamente las transiciones
DF <- matrix(0,
nrow = 0,
ncol = 2)
colnames(DF) <- c("from","to")
Creo una matriz adicional que tendra las transiciones y una columna extra con la direccion de la transición
{LINKS <- matrix(0,
nrow = 0,
ncol = 3)
colnames(LINKS) <- c("from","to","direction")}
Cargo el modelo de evolucion, el metodo de reconstrucción (bayesiano), la filogenia (previamente calculada con orthofinder) la cual enraizo en PCC_8801.
EvolModel = "F81"
Method = "bayes"
Tree = read.tree("SpeciesTree_rooted.txt")#"SpeciesTree_rooted.txt"
#Root = 'PCC_8801'
#Tree <-root(Tree, outgroup = Root, edgelabel = TRUE)
Alignment = "fna/only_chromosomes/evolverThermosynechococcus.hal.maf.sed.cactus.phy"
Esta filogenia contiene 11 nodos, sin embargo posteriormente para el analisis se quita la raiz y quedan 10.
ggtree(Tree,branch.length="none",) +
geom_tiplab(color='firebrick', offset = .14)+
geom_label(aes(label = node),show.legend = FALSE)
En el archivo Orthologues_Palindrome_sites.txt hay 2593 sitios en total. Cargamos el primer sitio el cual corresponde a:
###
FILE PAL START END
evolverThermosynechococcus.hal.maf.sed.cactus.phy CAGGCCTG 3911 3918
###
El numero ORTH correponde al numero de sitio. Por lo tanto cargamos el PATH del alineamiento del primer sitio (Alignment), así como su inicio (SI) y su termino (EI)
ORTH = 1
SI = Sites[ORTH,3]
EI = Sites[ORTH,4]
Cargo la alineación multiple
cyanobacterias <- read.phyDat(Alignment, format = "interleaved")
## Cambio el attributo site.patter a FALSE para poder acceder a todos los indices
cyanobacterias <- subset(cyanobacterias, site.pattern = FALSE)
#TreeR = pratchet(cyanobacterias, trace = 0)|>acctran(cyanobacterias)
parsimony(Tree, cyanobacterias)
## [1] 463002
Estimo los parametros para el modelo. en esta parte uso el modelo de evolucion elegido anteriormente (“F81”). Además en esta parte el arbol se desenraiza y ahora tenemos 10 nodos. Por lo tanto, debo cambiar el arbol al nuevo sin raiz para evitar errores.
fit <- pml(Tree, cyanobacterias)
fit <- optim.pml(fit, model=EvolModel, control = pml.control(trace=0))
Tree2 <- fit[["tree"]]
ggtree(Tree2,branch.length="none",) +
geom_tiplab(color='firebrick', offset = .14)+
geom_label(aes(label = node),show.legend = FALSE)
Hago la reconstruccion de estados ancestrales para cada sitio. Para esto hay dos métodos: bayesiano o máxima verosimilitud. Anteriormente habia declarado la variable Method como bayes.
## Calculo la probabilidad del árbol filogenético dado el alineamiento y el modelo
if(Method == "bayes"){
anc.bayes <- ancestral.pml(fit, type="bayes", return = "prob")
Reconstruction <- anc.bayes
}
if(Method == "ml"){
anc.ml <- ancestral.pml(fit, "ml")
Reconstruction <- anc.ml
}
Armo los palindromos ancestrales de acuerdo a los estados ancestrales usando los sitios de inicio y fin de cada sitio palindromico (SI y EI). Posteriormente uso dicho intervalo para buscar lel estado de cada nucleotido del intervalo y guardarlo en el vector (PalindromeNucleotidePositions). Tambien extraigo los nombres de cada nodo de la reconstrucción:
PalInterval = SI:EI ## ESTE ES EL INTERVALO DEL SITIO PALINDROMICO
## Obtengo las posiciones para la posicion PalInterval
PalindromeNucleotidePositions <- attributes(cyanobacterias)$index[PalInterval]
## Nombre de los nodos
Nodos <- attributes(Reconstruction)$names
Ahora creo una matriz que contendra 9 columnas, la primera contendrá los Nodos y las 8 restantes contendran los nucleotidos correspondientes a su palindromo y prosigo a rellenar la matriz. Sin embargo, en este paso hay un detalle.
La reconstrucción de estado ancestral para cada sitio arroja una probabilidad para cada uno de los 4 sitios posibles (A, T ,G o C). Si hay equivalencia en la probabilidad en los estados, es decir que el estado ancestral de un nucleotido tenga la misma probabilidad de haber estado en cualesquiera de los 4 posibles estados, entonces dicho estado se omite, de lo contrario se toma aquel estado con la mayor probabilidad. Otro punto importante es que hay sitios en los que una especie puede contener deleciones. Para estos casos, si gfalta algún nucleotido sew rellena con un “-”.
## Transformo el arbol en data frame para extraer las etiquetas de los nodos.
a.1 <- as_tibble(Tree2)
## NA.NODE corresponde al nodo a partir del cual ya no estan las puntas del arbol
NA.NODE = length(cyanobacterias)+1
## Esto es para agregar la etiqueta de los nodos a los que faltan, es decir a los nodos que no son puntas del arbol.
for (i in NA.NODE:length(Nodos)){ ## ESTO DEPENDE DE LA ESTRUCTURA DEL ARBOL
a.1$label[i] <- a.1$node[i] # x$node[i-1]
}
## Agrego las etiquetas de nodo al arbol
b.1 <- tibble::tibble(label = Nodos)
c.1 <- full_join(a.1, b.1, by = 'label')
NodeLabels <- c.1$label
TipLabels <- Tree2$tip.label
NodeLabels2 <- NodeLabels[-c(1:length(TipLabels))]
## Creo una matriz de 8 x length(Nodos) (8 nucleotidos x numero de nodos) para guardar los resultados
ScoresMtx <- matrix(0,
nrow = length(Nodos),
ncol = 8)
colnames(ScoresMtx) <- c("1","2","3","4","5","6","7","8")
rownames(ScoresMtx) <- Nodos
## Relleno la matriz con los scores.
## ESTE CICLO ES UNICAMENTE PARA LAS PUNTAS DE LOS NODOS
j = 1
i = 1
k = 0
for (Position in PalindromeNucleotidePositions){
for (Nodo in TipLabels){
PositionScores <- Reconstruction[[Nodo]][Position,] ## Extraigo los scores para el nodo "NODO" en la posicion "POSITION" de la secuencia
if (length(unique(PositionScores)) == 1){
k=k+1
WinnerNucleotide = "-"
ScoresMtx[i,j] <- WinnerNucleotide
i=i+1 ## contador para cada Nodo
}else{
PositionWinnerScore <- max(PositionScores) ## Extraigo el valor mas grande. Este es el valor de la probabilidad de que el nucleotido ancestral sea ese
WinnerNucleotide <- which(PositionScores == PositionWinnerScore, arr.ind = T) ## pregunto a que numero (Nucleótido) corresponde ese valor
ScoresMtx[i,j] <- WinnerNucleotide ## Guardo dicho valor en la matriz de resultados
i=i+1 ## contador para cada Nodo
}
}
j=j+1 ## contador para cada posición
i=1 ## Reiniciamoa el contador de Nodo para la siguiente posicion
}
## Relleno la matriz con los scores
## ESTA PARTE ES PARA TODOS LOS NODOS RESTANTES QUE NO SON PUNTAS
j = 1
i = length(TipLabels)+1
k = 0
#(length(TipLabels)+1):length(NodeLabels)
for (Position in PalindromeNucleotidePositions){
for (Nodo in NodeLabels2){
PositionScores <- Reconstruction[[Nodo]][Position,] ## Extraigo los scores para el nodo "NODO" en la posicion "POSITION" de la secuencia
if (length(unique(PositionScores)) == 1){
k=k+1
WinnerNucleotide = "X"
ScoresMtx[i,j] <- WinnerNucleotide
i=i+1 ## contador para cada Nodo
}else{
PositionWinnerScore <- max(PositionScores) ## Extraigo el valor mas grande. Este es el valor de la probabilidad de que el nucleotido ancestral sea ese
WinnerNucleotide <- which(PositionScores == PositionWinnerScore, arr.ind = T) ## pregunto a que numero (Nucleótido) corresponde ese valor
ScoresMtx[i,j] <- WinnerNucleotide ## Guardo dicho valor en la matriz de resultados
i=i+1 ## contador para cada Nodo
}
}
j=j+1 ## contador para cada posición
i=length(TipLabels)+1 ## Reiniciamoa el contador de Nodo para la siguiente posicion
}
Ahora decodificamos el palindromo a nucleotidos para esto creo una nueva matriz que contendra dos columnas: nodos y sus correspondientes palíndromos.
## Creo un matriz de 1x14 para guardar la etiqueta (palindromo) de cada nodo
PalsMtx <- matrix(0,
nrow = length(Nodos),
ncol = 1)
colnames(PalsMtx) <- c("Palindrome")
rownames(PalsMtx) <- Nodos
## Extraigo cada palindromo, cambio el codigo de numero por el codigo de letras y lo guardo en la matriz 1x14
i=0
j=0
for (Nodo in Nodos){
j=j+1
Palindrome <- as.character(ScoresMtx[j,]) # Este es el palindromo
pal =""
for (nuc in Palindrome){
if(nuc== 1){nuc = 'A'}
if(nuc== 2){nuc = 'C'}
if(nuc== 3){nuc = 'G'}
if(nuc== 4){nuc = 'T'}
pal = paste(pal,nuc,sep = "")
}
PalsMtx[j,1] <- pal
}
Guardo los nodos y los palindromos de cada nodo en 2 vectores. Los cuales voy a usar para anotar el arbol filogenetico.
l <- as.list(PalsMtx[,1])
Nodes = names(l)
NodePals = as.character(PalsMtx[,1])
Para poder hacer esto, primero transformo el arbol filogenetico en una tabla y agrego 2 columnas: (label) que contendra el nombre de cada nodo y (Palindromo) que contendra el palindromo de dicho nodo.
## Transformo el arbol en data frame para poder agregar los palindromos de cada nodo
x <- as_tibble(Tree2)
## Extraigo el Boostrap por si se ocupa
NA.NODE = length(cyanobacterias)+1
BootStrap <- x$label[NA.NODE:length(Nodes)]
for (i in NA.NODE:length(Nodes)){ ## ESTO DEPENDE DE LA ESTRUCTURA DEL ARBOL
x$label[i] <- x$node[i] # x$node[i-1]
}
## Agrego los datos de los palindromos al arbol
d <- tibble::tibble(label = Nodes,
Palindromo = NodePals)
y <- full_join(x, d, by = 'label')
Hasta aqui tenemos una filogenoa anotada con su palindromo ancestral en cada nodo:
ggtree(as.treedata(y),branch.length="none") +
geom_tiplab(color='firebrick', offset = .14)+
geom_label(aes(label = Palindromo,color=Palindromo),show.legend = FALSE)+
aes(color=Palindromo)+
guides(fill = guide_legend(override.aes = list(color = NA)),
color = FALSE,
shape = 1)
Ahora necesito crear una matriz que tenga las tranmsiciones entre cada nodo. Para esto extraigo las direcciones de los nodos desde el arbol filogenetico previamente anotado es decir las columnas from y to y las guardo en una nueva matriz:
## Esta es la configuracion del arbol
from<-y$label#c("336-3","7","7","8","8","9","9","10","10")
to<-y$parent#c("7","NIES-3974","8","PCC_6303","9","PCC_7716","10","NIES-4071","NIES-4105")
LinksMtx <- matrix(0,
nrow = length(from),
ncol = 2)
colnames(LinksMtx) <- c("from","to")
for (i in 1:length(from)){
LinksMtx[i,1] = from[i]
LinksMtx[i,2] = to[i]
}
Luego extraigo las columnas label y Palindromo y las guardo en otra matriz. Dicha matriz me servira como diccionario para obtener las transiciones en cada nodo. Posteriormente la convierto a data frame.
## AQUI VOY A CREAR LA MATRIZ QUE ME SERVIRA COMO DICCIONARIO PARA RELLENAR LA MATRIZ DE TRANSICIONES
Mat <- y[,4:5]
Mat2 <- as.data.frame(Mat) ## CONVIERTO A DF
Mat2
## label Palindromo
## 1 D10 --------
## 2 PCC_6312 CAGGCCTG
## 3 PCC_6715 --------
## 4 HN-54 --------
## 5 SCTE542 --------
## 6 CL-1 --------
## 7 TA-1 --------
## 8 NK55a --------
## 9 BP-1 --------
## 10 MBIC11017 --------
## 11 Moss_Beach --------
## 12 S15 --------
## 13 13 CAGGCCTG
## 14 14 CAGGCCTG
## 15 15 CAGGCCTG
## 16 16 CAGGCCTG
## 17 17 CAGGCCTG
## 18 18 CAGGCCTG
## 19 19 CAGGCCTG
## 20 20 CAGGCCTG
## 21 21 CAGGCCTG
## 22 22 CAGGCCTG
Ahora creo una nueva matriz que va a tener todas las transiciones. Para esto uso las ultimas dos matrices. La matriz LinksMtx que tiene las direcciones entre nodos la paso a palindromos con ayuda de Mat2 la cual me sirve como diccionario y convierto esta ultima matriz (LinksMtx2) a dataframe.
## AQUI CREO LA MATRIZ DE TRANSICIONES.
LinksMtx2 <- matrix(0,
nrow = length(from),
ncol = 2)
colnames(LinksMtx2) <- c("from","to")
## AQUI RELLENO LA MATRIZ DE TRANSICIONES USANDO COMO DICCIONARIO A LA MATRIZ ANTERIOR (Mat2)
for (i in 1:length(from)) {
for (j in 1:length(from)){
if (LinksMtx[i,1]==Mat2[j,1]){
LinksMtx2[i,1] = Mat2[j,2]
}
if (LinksMtx[i,2]==Mat2[j,1]){
LinksMtx2[i,2] = Mat2[j,2]
}
}
}
df <- as.data.frame(LinksMtx2) ## CONVIERTO A DF LA MATRIZ DE TRANSICIONES
Creo una matriz adicional la cual es identica a la anterior salvo que le agrego las direcciones de cada transicion, las cuales podrian ser de utilidad.
directions<-paste(from,to,sep="--") ## ESTE VECTOR CONTIENE LAS DIRECCIONES
Links0 = as.data.frame(LinksMtx2) ## HAGO UNA COPIA DE LA MATRIZ DE TRANSICIONES
Links0$direction<-directions ## AGREGO COMO COLUMNA NUEVA A "directions"
Al final de este paso tendre dos matrices DF y LINKS
DF contiene solo las transiciones
DF <- rbind(DF,df) ## UNO LA MATRIZ ACTUAL DE TRANSICIONES CON LA ANTERIOR PARA CREAR UNA SOLA
DF
## from to
## 1 -------- CAGGCCTG
## 2 CAGGCCTG CAGGCCTG
## 3 -------- CAGGCCTG
## 4 -------- CAGGCCTG
## 5 -------- CAGGCCTG
## 6 -------- CAGGCCTG
## 7 -------- CAGGCCTG
## 8 -------- CAGGCCTG
## 9 -------- CAGGCCTG
## 10 -------- CAGGCCTG
## 11 -------- CAGGCCTG
## 12 -------- CAGGCCTG
## 13 CAGGCCTG CAGGCCTG
## 14 CAGGCCTG CAGGCCTG
## 15 CAGGCCTG CAGGCCTG
## 16 CAGGCCTG CAGGCCTG
## 17 CAGGCCTG CAGGCCTG
## 18 CAGGCCTG CAGGCCTG
## 19 CAGGCCTG CAGGCCTG
## 20 CAGGCCTG CAGGCCTG
## 21 CAGGCCTG CAGGCCTG
## 22 CAGGCCTG CAGGCCTG
y LINKS las transiciones con sus respectivas direcciones.
LINKS<-rbind(LINKS,Links0) ## UNO LA MATRIZ ACTUAL DE TRANSICIONES(CON DIRECCIONES) CON LA ANTERIOR PARA CREAR UNA SOLA
LINKS
## from to direction
## 1 -------- CAGGCCTG D10--13
## 2 CAGGCCTG CAGGCCTG PCC_6312--14
## 3 -------- CAGGCCTG PCC_6715--15
## 4 -------- CAGGCCTG HN-54--17
## 5 -------- CAGGCCTG SCTE542--18
## 6 -------- CAGGCCTG CL-1--19
## 7 -------- CAGGCCTG TA-1--19
## 8 -------- CAGGCCTG NK55a--20
## 9 -------- CAGGCCTG BP-1--20
## 10 -------- CAGGCCTG MBIC11017--21
## 11 -------- CAGGCCTG Moss_Beach--22
## 12 -------- CAGGCCTG S15--22
## 13 CAGGCCTG CAGGCCTG 13--13
## 14 CAGGCCTG CAGGCCTG 14--13
## 15 CAGGCCTG CAGGCCTG 15--14
## 16 CAGGCCTG CAGGCCTG 16--15
## 17 CAGGCCTG CAGGCCTG 17--16
## 18 CAGGCCTG CAGGCCTG 18--17
## 19 CAGGCCTG CAGGCCTG 19--18
## 20 CAGGCCTG CAGGCCTG 20--16
## 21 CAGGCCTG CAGGCCTG 21--13
## 22 CAGGCCTG CAGGCCTG 22--21
Finalmente repito esto para los 2592 sitios palindromicos restantes:
#EvolModel = "F81"
#Method = "bayes"
#Tree = read.tree("SpeciesTree_rooted.txt")#"SpeciesTree_rooted.txt"
#Root = '336-3'
#Tree <-root(Tree, outgroup = Root, edgelabel = TRUE)
for (ORTH in 2:length(Sites[,1])){ ## HAY 2593 ortólogos
#Alignment = paste0("fna/only_chromosomes/",Sites[ORTH,1])
SI = Sites[ORTH,3]
EI = Sites[ORTH,4]
## Cargo la alineación multiple
#cyanobacterias <- read.phyDat(Alignment, format = "interleaved")
## Cambio el attributo site.patter a FALSE para poder acceder a todos los indices
#cyanobacterias <- subset(cyanobacterias, site.pattern = FALSE)
#TreeR = pratchet(cyanobacterias, trace = 0)|>acctran(cyanobacterias)
#parsimony(Tree, cyanobacterias)
## Estimo los parametros para el modelo
#fit <- pml(Tree, cyanobacterias)
#fit <- optim.pml(fit, model=EvolModel, control = pml.control(trace=0))
#Tree2 <- fit[["tree"]]
## Calculo la probabilidad del árbol filogenético dado el alineamiento y el modelo
#if(Method == "bayes"){
# anc.bayes <- ancestral.pml(fit, type="bayes", return = "prob")
# Reconstruction <- anc.bayes
#}
#if(Method == "ml"){
# anc.ml <- ancestral.pml(fit, "ml")
# Reconstruction <- anc.ml
#}
#plotAnc(Tree2, anc.bayes, 1)
PalInterval = SI:EI ## ESTE ES EL INTERVALO DEL SITIO PALINDROMICO
## Obtengo las posiciones para la posicion PalInterval
PalindromeNucleotidePositions <- attributes(cyanobacterias)$index[PalInterval]
## Nombre de los nodos
Nodos <- attributes(Reconstruction)$names
########################################################################################################
## Transformo el arbol en data frame para poder agregar los palindromos de cada nodo
a.1 <- as_tibble(Tree2)
## Extraigo el Boostrap por si se ocupa
NA.NODE = length(cyanobacterias)+1
for (i in NA.NODE:length(Nodos)){ ## ESTO DEPENDE DE LA ESTRUCTURA DEL ARBOL
a.1$label[i] <- a.1$node[i] # x$node[i-1]
}
## Agrego los datos de los palindromos al arbol
b.1 <- tibble::tibble(label = Nodos)
c.1 <- full_join(a.1, b.1, by = 'label')
NodeLabels <- c.1$label
TipLabels <- Tree2$tip.label
NodeLabels2 <- NodeLabels[-c(1:length(TipLabels))]
## Creo una matriz de 8 x length(Nodos) (8 nucleotidos, numero de nodos) para guardar los resultados
ScoresMtx <- matrix(0,
nrow = length(Nodos),
ncol = 8)
colnames(ScoresMtx) <- c("1","2","3","4","5","6","7","8")
rownames(ScoresMtx) <- Nodos
## Relleno la matriz con los scores
j = 1
i = 1
k = 0
for (Position in PalindromeNucleotidePositions){
for (Nodo in TipLabels){
PositionScores <- Reconstruction[[Nodo]][Position,] ## Extraigo los scores para el nodo "NODO" en la posicion "POSITION" de la secuencia
if (length(unique(PositionScores)) == 1){
k=k+1
WinnerNucleotide = "-"
ScoresMtx[i,j] <- WinnerNucleotide
i=i+1 ## contador para cada Nodo
}else{
PositionWinnerScore <- max(PositionScores) ## Extraigo el valor mas grande. Este es el valor de la probabilidad de que el nucleotido ancestral sea ese
WinnerNucleotide <- which(PositionScores == PositionWinnerScore, arr.ind = T) ## pregunto a que numero (Nucleótido) corresponde ese valor
ScoresMtx[i,j] <- WinnerNucleotide ## Guardo dicho valor en la matriz de resultados
i=i+1 ## contador para cada Nodo
}
}
j=j+1 ## contador para cada posición
i=1 ## Reiniciamoa el contador de Nodo para la siguiente posicion
}
## Relleno la matriz con los scores
j = 1
i = length(TipLabels)+1
k = 0
#(length(TipLabels)+1):length(NodeLabels)
for (Position in PalindromeNucleotidePositions){
for (Nodo in NodeLabels2){
PositionScores <- Reconstruction[[Nodo]][Position,] ## Extraigo los scores para el nodo "NODO" en la posicion "POSITION" de la secuencia
if (length(unique(PositionScores)) == 1){
k=k+1
WinnerNucleotide = "X"
ScoresMtx[i,j] <- WinnerNucleotide
i=i+1 ## contador para cada Nodo
}else{
PositionWinnerScore <- max(PositionScores) ## Extraigo el valor mas grande. Este es el valor de la probabilidad de que el nucleotido ancestral sea ese
WinnerNucleotide <- which(PositionScores == PositionWinnerScore, arr.ind = T) ## pregunto a que numero (Nucleótido) corresponde ese valor
ScoresMtx[i,j] <- WinnerNucleotide ## Guardo dicho valor en la matriz de resultados
i=i+1 ## contador para cada Nodo
}
}
j=j+1 ## contador para cada posición
i=length(TipLabels)+1 ## Reiniciamoa el contador de Nodo para la siguiente posicion
}
########################################################################################################
## EN ESTA PARTE ARMAREMOS EL PALINDROMO PARA CADA NODO
## Creo un matriz de 1x14 para guardar la etiqueta (palindromo) de cada nodo
PalsMtx <- matrix(0,
nrow = length(Nodos),
ncol = 1)
colnames(PalsMtx) <- c("Palindrome")
rownames(PalsMtx) <- Nodos
## Extraigo cada palindromo, cambio el codigo de numero por el codigo de letras y lo guardo en la matriz 1x14
i=0
j=0
for (Nodo in Nodos){
j=j+1
Palindrome <- as.character(ScoresMtx[j,]) # Este es el palindromo
pal =""
for (nuc in Palindrome){
if(nuc== 1){nuc = 'A'}
if(nuc== 2){nuc = 'C'}
if(nuc== 3){nuc = 'G'}
if(nuc== 4){nuc = 'T'}
pal = paste(pal,nuc,sep = "")
}
PalsMtx[j,1] <- pal
}
## ESTA PATRTE ES PARA GUARDAR LOS PALINDROMOS DE CADA NODO
l <- as.list(PalsMtx[,1])
Nodes = names(l)
NodePals = as.character(PalsMtx[,1])
## Transformo el arbol en data frame para poder agregar los palindromos de cada nodo
x <- as_tibble(Tree2)
## Extraigo el Boostrap por si se ocupa
NA.NODE = length(cyanobacterias)+1
BootStrap <- x$label[NA.NODE:length(Nodes)]
for (i in NA.NODE:length(Nodes)){ ## ESTO DEPENDE DE LA ESTRUCTURA DEL ARBOL
x$label[i] <- x$node[i] # x$node[i-1]
}
## Agrego los datos de los palindromos al arbol
d <- tibble::tibble(label = Nodes,
Palindromo = NodePals)
y <- full_join(x, d, by = 'label')
#------------------------
## Esta es la configuracion del arbol
from<-y$label#c("336-3","7","7","8","8","9","9","10","10")
to<-y$parent#c("7","NIES-3974","8","PCC_6303","9","PCC_7716","10","NIES-4071","NIES-4105")
LinksMtx <- matrix(0,
nrow = length(from),
ncol = 2)
colnames(LinksMtx) <- c("from","to")
for (i in 1:length(from)){
LinksMtx[i,1] = from[i]
LinksMtx[i,2] = to[i]
}
## AQUI VOY A CREAR LA MATRIZ QUE ME SERVIRA COMO DICCIONARIO PARA RELLENAR LA MATRIZ DE TRANSICIONES
Mat <- y[,4:5]
#Mat <- Mat %>% ## AQJUI QUITO EL RENGLON 7 QUE NO CONTIENE NADA. ESTE CORRESPONDE A LA RAIZ DEL ARBOL
# filter(!is.na(Palindromo))
Mat
Mat2 <- as.data.frame(Mat) ## CONVIERTO A DF
Mat2
## AQUI CREO LA MATRIZ DE TRANSICIONES.
LinksMtx2 <- matrix(0,
nrow = length(from),
ncol = 2)
colnames(LinksMtx2) <- c("from","to")
## AQUI RELLENO LA MATRIZ DE TRANSICIONES USANDO COMO DICCIONARIO A LA MATRIZ ANTERIOR (Mat2)
for (i in 1:length(from)) {
for (j in 1:length(from)){
if (LinksMtx[i,1]==Mat2[j,1]){
LinksMtx2[i,1] = Mat2[j,2]
}
if (LinksMtx[i,2]==Mat2[j,1]){
LinksMtx2[i,2] = Mat2[j,2]
}
}
}
directions<-paste(from,to,sep="--") ## ESTE VECTOR CONTIENE LAS DIRECCIONES
Links0 = as.data.frame(LinksMtx2) ## HAGO UNA COPIA DE LA MATRIZ DE TRANSICIONES
Links0$direction<-directions ## AGREGO COMO COLUMNA NUEVA A "directions"
Links0
LINKS<-rbind(LINKS,Links0) ## UNO LA MATRIZ ACTUAL DE TRANSICIONES(CON DIRECCIONES) CON LA ANTERIOR PARA CREAR UNA SOLA
df <- as.data.frame(LinksMtx2) ## CONVIERTO A DF LA MATRIZ DE TRANSICIONES
DF <- rbind(DF,df) ## UNO LA MATRIZ ACTUAL DE TRANSICIONES CON LA ANTERIOR PARA CREAR UNA SOLA
#print(paste0("Archivo ",ORTH, " de ",length(Sites$FILE),"."))
write.table(LINKS,file="LINKS.txt", sep="\t", row.names = FALSE)
}
Ahora las matrices DF y LINKS contienen todas las transiciones de todos los sitios. En total son 25930 transiciones ya que son 10 transiciones por arbol y tenemos 2593 arboles.
length(DF$from)
## [1] 29480
length(LINKS$from)
## [1] 29480
Primero cuento el numero de veces que se repite cada linea de la matriz de transiciones. El conteo para cada transicion sera el peso de cada vertice. Luego cambio el nombre de la columna counts a weight, paso su contenido a numeros enteros y la convierto a tibble. En total tengo 25930 transiciones:
library(data.table)
RowCts <- setDT(DF)[,list(Count=as.numeric(.N)),names(DF)] ## CUENTO EL NUMERO DE OCURRENCIAS DE CADA TRANSICIÓN #7211
colnames(RowCts) <- c("from","to","weight")
RowCts = transform(RowCts, weight = as.integer(weight)) ## CONVIERTO A ENTEROS LA COLUMNA "weight"
RowCts <-as_tibble(RowCts) ## CONVIERTO A TIBBLE
RowCts #7211
## # A tibble: 1,017 × 3
## from to weight
## <chr> <chr> <int>
## 1 -------- CAGGCCTG 13471
## 2 CAGGCCTG CAGGCCTG 13536
## 3 -------- TAGACCGG 2
## 4 CAGGCCTG TAGGCCTG 2
## 5 -------- TAGGCCTG 5
## 6 TA------ TAGGCCTG 5
## 7 TC------ TAGGCCTG 1
## 8 T-GACTGG TAGACTGG 1
## 9 T-GATGGG TAGATGGG 2
## 10 TAGACCGG TAGACCGG 6
## # ℹ 1,007 more rows
Filtro conteos bajos (<=10) y loops. Al final me quedo con 63 transiciones.
RowCts<-RowCts%>% ##QUITO LOS LOOPS. ES DECIR QUITO AQUELLAS TRANSICIONES QUE VAYAN ASI MISMA
filter(from!=to)
length(RowCts$from) #5604
## [1] 731
RowCts<-RowCts%>% ## QUIRO AQUELLAS TRANSICIONES CON UN PESO MENOR A 10
filter(weight>=7)
length(RowCts$from) #63
## [1] 8
Extraigo todos los nodos posibles y los agrego a una matriz que va a contener los nodos del grafo. Adiconalmente le agrego una columna score que me indicara que tan parecido es el aplindromo a HIP1 (despues la quito porque no creo que sea un buen índice)
GraphNodes <- c(RowCts$from, RowCts$to) ## OBTENGO LOS PALINDROMOS DE CADA NODO
length(GraphNodes) #126
## [1] 16
GNMtx <- matrix(0, ## CREO LA MATRIZ QUE CONTENDRÁ LAS NODOS PARA EL GRAFO
nrow = length(GraphNodes),
ncol = 2)
colnames(GNMtx) <- c("pal","score") ## ETIQUETO LAS COLUMNAS DE LA MATRIZ
for (i in 1:length(GraphNodes)){ ## RELLENO LA MATRIZ
GNMtx[i,1] = GraphNodes[i] ## AGREGO LOS NODOS
GNMtx[i,2] = RecordLinkage::levenshteinSim(GraphNodes[i], 'GCGATCGC')*1000 ## AGREGO UN SCORE QUE SERÁ EL PORCENTAJE DE IDENTIDAD CON HIP1 MULTIPLICADO POR 1000
}
GNMtx <- as.data.frame(GNMtx) ## CONVIERTO LA MATRIZ DE NODOS A DF
GNMtx <- GNMtx[!duplicated(GNMtx), ] ## ELIMINO LOS NODOS DUPLICADOS
Creo un vector que enumerará los palindromos. Dicha enumeracion correspondera a su ID
palindromes<-GNMtx[,1] #34 ## EXTRAIGO LOS NODOS DE LA MATRIZ DEL GRAFO. ESTO LO HAGO PARA POSTERIAMENTE ENUMERARLAS Y ASOCIAR CADA NUMERO COMO ID
ids<-c() ## CREO UN VECTOR VACIO QUE CONTENDRÁ LOS ID'S
for (k in 1:length(palindromes)){ ## ENUMERO LOS PALINDROMOS. ESTOS NUMEROS SERAN LOS IDS
ids <-append(ids, k)
}
ids
## [1] 1 2 3 4 5 6 7 8 9
length(ids) #34
## [1] 9
length(GNMtx[,1]) #34
## [1] 9
Creo una matriz nueva que contendrá los nodos del grafo pero con su ID para cada palindromo:
Nodes2 <-cbind(GNMtx,ids) ## CREO UNA MATRIZ NUEVA CON LA MATRIZ DE NODOS Y LOS IDS. ESTA LA VOY A USAR COMO UN DICCIONARIO ID-NODO
length(Nodes2$pal)
## [1] 9
Nodes2<-Nodes2[,c(3,1,2)] ## REORDENO LAS COLUMNAS DE LA MATRIZ
colnames(Nodes2)<-c("id","label","score") ## ETIQUETO LAS COLUMNAS
Creo la matriz de vertices del grafo y tambien sustituyo el nombre de los nodos por sus respectivos ID’S. Adicionalmente cambio los scores que tengan 0 por 1’s ya que hay errores. Sin embargo, la columna score no la uso mas adelante.
GEMtx <- RowCts ## ESTA VA A SER LA MATRIZ DE VERTICES
Edges2 <- as.matrix(RowCts)#RowCts ESTA ES OTRA MATRIZ DE VERTICES DE LA CUAL VOY A SUSTITUIR LOS NODOS POR SUS IDS
for (n in 1:length(Nodes2[,2])){ ##AQUI CAMBIARE LOS PALINDROMOS DE LOS NODOS POR IDS
Edges2[Edges2==Nodes2[n,2]] <- as.numeric(Nodes2[n,1])
#print(n)
}
for (n in 1:length(Nodes2[,2])){ ## HANDLE 0's
Nodes2[Nodes2==0] <- as.numeric(1)
#print(n)
}
Cargo las librerias
library(visNetwork)
library(networkD3)
library(tidygraph)
library(ggraph)
Para empezar cargo los nodos y los vertices. En esta parte quito la columna score de los nodos.
nodes = as_tibble(Nodes2)
nodes = select(nodes, -score)
edges = as_tibble(Edges2)
edges = transform(edges, from = as.integer(from))
edges = transform(edges, to = as.integer(to))
edges = transform(edges, weight = as.integer(weight))
edges = as_tibble(edges)
Creo un grafo dirigido agregando un peso de acuerdo a la columna weight.
routes_tidy <- tbl_graph(nodes = nodes,
edges = edges,
directed = TRUE)
routes_tidy
## # A tbl_graph: 9 nodes and 8 edges
## #
## # A rooted tree
## #
## # A tibble: 9 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 C-------
## 3 3 CAGGCCTG
## 4 4 C------G
## 5 5 CAGCCCTG
## 6 6 CAGGGCTG
## # ℹ 3 more rows
## #
## # A tibble: 8 × 3
## from to weight
## <int> <int> <int>
## 1 1 3 13471
## 2 1 5 9
## 3 2 3 7
## # ℹ 5 more rows
routes_tidy %>%
activate(edges) %>%
arrange(desc(weight))
## # A tbl_graph: 9 nodes and 8 edges
## #
## # A rooted tree
## #
## # A tibble: 8 × 3
## from to weight
## <int> <int> <int>
## 1 1 3 13471
## 2 1 5 9
## 3 3 9 9
## 4 1 7 8
## 5 2 3 7
## 6 1 6 7
## # ℹ 2 more rows
## #
## # A tibble: 9 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 C-------
## 3 3 CAGGCCTG
## # ℹ 6 more rows
Visualizo el grafo:
ggraph(routes_tidy, layout = "graphopt") +
geom_node_point() +
geom_edge_link(aes(width = weight), alpha = 0.8) +
scale_edge_width(range = c(0.2, 2)) +
geom_node_text(aes(label = label), repel = TRUE) +
labs(edge_width = "Times") +
theme_graph()
Este es un grafo sin peso en los vertices.
visNetwork(nodes, edges)
Este es el mismo grafo pero con peso en sus vertices
edges <- mutate(edges, width = weight/5 + 1)
visNetwork(nodes, edges) %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visEdges(arrows = "middle")
Este es otro grafo de fuerzas con peso en sus vertices y te muestra las conceciones de cada nodo de manera mas visual
nodes_d3 <- mutate(nodes, id = id - 1)
edges_d3 <- mutate(edges, from = from - 1, to = to - 1)
forceNetwork(Links = edges_d3, Nodes = nodes_d3,
Source = "from", Target = "to",
NodeID = "label", Group = "id", Value = "weight",
opacity = 1, fontSize = 16, zoom = TRUE)
Este ultimo grafo muestra el grafo anterior pero de una forma mas analizable.
sankeyNetwork(Links = edges_d3, Nodes = nodes_d3, Source = "from", Target = "to",
NodeID = "label", Value = "weight", fontSize = 16, unit = "TIME(s)")
WGHT = 4
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 D10--13 1224
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 3 nodes and 2 edges
## #
## # A rooted tree
## #
## # A tibble: 2 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 PCC_6312--14 6
## 2 1 3 PCC_6312--14 5
## #
## # A tibble: 3 × 2
## id label
## <int> <chr>
## 1 1 CAGGCCTG
## 2 2 CAGCCCTG
## 3 3 CAAGCCTG
}
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 PCC_6715--15 1228
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 HN-54--17 1228
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 SCTE542--18 1228
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
}
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 CL-1--19 1228
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 TA-1--19 1228
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 NK55a--20 1228
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
}
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 BP-1--20 1228
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 MBIC11017--21 1217
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 Moss_Beach--22 1217
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
}
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 S15--22 1217
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 --------
## 2 2 CAGGCCTG
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 14--13 2
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 CAGGCCTG
## 2 2 CAGGCCTT
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 5 nodes and 4 edges
## #
## # A rooted tree
## #
## # A tibble: 4 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 5 15--14 2
## 2 2 5 15--14 2
## 3 3 5 15--14 2
## 4 4 5 15--14 2
## #
## # A tibble: 5 × 2
## id label
## <int> <chr>
## 1 1 CAGGTCTG
## 2 2 CAAGCCTG
## 3 3 CGGGCCTG
## # ℹ 2 more rows
}
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 16--15 2
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 CGGGGCTA
## 2 2 CGGGCCTG
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 30 nodes and 15 edges
## #
## # A rooted forest with 15 trees
## #
## # A tibble: 15 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 16 17--16 1
## 2 2 17 17--16 1
## 3 3 18 17--16 1
## 4 4 19 17--16 1
## 5 5 20 17--16 1
## 6 6 21 17--16 1
## # ℹ 9 more rows
## #
## # A tibble: 30 × 2
## id label
## <int> <chr>
## 1 1 AAGATTTA
## 2 2 CATGTTGG
## 3 3 TAGGGTCG
## # ℹ 27 more rows
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 12 nodes and 6 edges
## #
## # A rooted forest with 6 trees
## #
## # A tibble: 6 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 7 18--17 1
## 2 2 8 18--17 1
## 3 3 9 18--17 1
## 4 4 10 18--17 1
## 5 5 11 18--17 1
## 6 6 12 18--17 1
## #
## # A tibble: 12 × 2
## id label
## <int> <chr>
## 1 1 CACAGGTG
## 2 2 AACCCCTG
## 3 3 CAGGCTGT
## # ℹ 9 more rows
}
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 2 nodes and 1 edges
## #
## # A rooted tree
## #
## # A tibble: 1 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 2 19--18 2
## #
## # A tibble: 2 × 2
## id label
## <int> <chr>
## 1 1 CAGGCTTA
## 2 2 CGGGGCTA
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 49 nodes and 25 edges
## #
## # A rooted forest with 24 trees
## #
## # A tibble: 25 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 26 20--16 1
## 2 2 27 20--16 1
## 3 3 28 20--16 1
## 4 4 29 20--16 1
## 5 5 30 20--16 1
## 6 6 31 20--16 1
## # ℹ 19 more rows
## #
## # A tibble: 49 × 2
## id label
## <int> <chr>
## 1 1 CAGGGGTG
## 2 2 AAGGGCAG
## 3 3 CAGATCTG
## # ℹ 46 more rows
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 86 nodes and 51 edges
## #
## # A rooted forest with 35 trees
## #
## # A tibble: 51 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 51 21--13 1
## 2 2 52 21--13 1
## 3 3 53 21--13 1
## 4 4 54 21--13 1
## 5 5 55 21--13 1
## 6 6 56 21--13 1
## # ℹ 45 more rows
## #
## # A tibble: 86 × 2
## id label
## <int> <chr>
## 1 1 TAGACTGG
## 2 2 CAGCCTTT
## 3 3 CAAGCTTT
## # ℹ 83 more rows
ggtree(Tree2) +
geom_tiplab(color='firebrick', offset = .10, hjust=2.5)+
geom_label(aes(label = node),show.legend = TRUE)
## [1] 2319
## # A tbl_graph: 58 nodes and 29 edges
## #
## # A rooted forest with 29 trees
## #
## # A tibble: 29 × 4
## from to direction weight
## <int> <int> <chr> <int>
## 1 1 30 22--21 1
## 2 2 31 22--21 1
## 3 3 32 22--21 1
## 4 4 33 22--21 1
## 5 5 34 22--21 1
## 6 6 35 22--21 1
## # ℹ 23 more rows
## #
## # A tibble: 58 × 2
## id label
## <int> <chr>
## 1 1 TAGATGGG
## 2 2 CAACCTTT
## 3 3 TAAGCTTT
## # ℹ 55 more rows