How to remove weird lines in my haplotype network using {pegas/ape}?

101 Views Asked by At

Haplotype network attempt, I am currently trying to make a haplotype network. My start script looks like this:

###Packageslijst
#Install Biospring
if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")
BiocManager::install("Biostrings")
if (!require("BiocManager", quietly = TRUE))
  install.packages("BiocManager")

BiocManager::install("msa")
install.packages('ape')
install.packages('ips')
install.packages('ggtree')
install.packages('tidyverse')
install.packages('haplotypes')
install.packages('pegas')
install.packages('stats')
BiocManager::install("ggtree")

library('Biostrings')
library('msa')
library('ape')
library('ips')
library('ggtree')
library('ggplot2')
library('haplotypes')
library('pegas')
library('stats')

#Commands-lijst:
###Import Fasta-file in R
#read FAST format file
DNAString<-readDNAStringSet('C:\\Users\\annet\\OneDrive - Wageningen University & Research\\Jaar 2\\Thesis\\Data\\Ruwe_Data\\CytoB_Fastafile.fas', format="fasta",nrec=-1L, skip=0L, seek.first.rec=FALSE,use.names=TRUE, with.qualities=FALSE) 
#Align samples to same length with ClustalW algoritm, stored as DNA stringset-object
DNAMSATEST<-msa(inputSeqs = DNAString, method = c("ClustalW"), cluster = "default", gapOpening = "default", gapExtension = "default", type = "default",order = c("aligned"), verbose = FALSE,help = FALSE)
#store multiple sequence alignments as DNAbinobject
DNABinTEST <- as.DNAbin(DNAMSATEST) 
#Demonstrate aligned sequences in phylogenetic tree<< TROUBLE
DNABinTEST

#Identified unique haplotype sequences by ingnoring matching nucleatides
#Calculate nr of haplotypes per population
HaploTEST<-haplotype(DNABinTEST, labels = NULL, strict = FALSE,
                     trailingGapsAsN = TRUE) 
HaploTEST
#Population frequency matrix was extracted > Seems correct

###Haplotype distance/heat map
dist.hamming(HaploTEST) #Calculate distance between haplotypes via Hammindistance method
###Heat map
IimpleR commands #symmetric distance matrix
heatmap() #Create heatmap based on a homemade haplotype sequence differences in pairs and putting in a symmetric matrix

###Haplotype network (3 different types)
#Options: individal datasets vs large populations vs haplotypical groups
#Extract haplotypes <works!
HaploTEST<-haplotype(DNABinTEST, labels = NULL, strict = FALSE,
                     trailingGapsAsN = TRUE) 
HaploNetTEST <- haploNet(HaploTEST, d = NULL, getProb = FALSE)
print(HaploNetTEST)
print.default(HaploNetTEST, digits = NULL, quote =TRUE, na.print = NULL, print.gap =  NULL, right = FALSE, max = NULL,useSource = TRUE)
plot(HaploNetTEST)

enter image description here

I thus followed the steps written in the manual of the pegas package PlotHaploNet, however, my output does not look the same. My output has a haplotype network, but all lines are exceeding the network and keep going to outside the graph.

This is what my output looks like. I want the 'normal' haplotype, with the lines only inbetween the circles instead of through the whole picture. Does anyone have an idea what to change in my code?

0

There are 0 best solutions below