---
title: "Bootanomyia_script_distance-matrix"
author: "G. Brown"
date: "2024-12-09"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

### After aligning sequences of B. dorsalis in UGene and creating a maximum likelihood phylogeny through IQTree and ModelFinder, I need to parse out some sequence distances. UGene has a function for this but it is not as refined as I need it. By that, I mean it does not produce decimals but rather rounded percentages of similarity. This script will take the alignment from UGene, which was created using a MUSCLE algorithm, and create a matrix of percent sequence identity for all pairwise comparisons saved to a .csv.

```{r Initialization, include=FALSE}
# Empties environment to prevent misinterpretation of data
rm(list=ls())

# Loads Library
library(bio3d)

# Sets working directory
setwd("F:/path/to/data")

# Path to data
data <- "F:/path/to/data/Bootanomyia_alignment_muscle.fa"

# Reading alignment
dna <- bio3d::read.fasta(data)
```

```{r}
# Performing calculation of percent sequence identity
pid <- seqidentity(dna)

# Saving the matrix as a .csv
write.csv(pid, file = "F:/path/to/output/")
```