Package Loading
library(Seroplacer)
Query_Sequences<-Query_ExampleWe will walk through an example placement of a set of query sequences. This query consists of 7 16S bacterial amplicon sequencing variants (ASVs) which are contained in a FASTA file. This is the only file needed to get started with using Seroplacer and attempting to make a serovar prediction based on a set of ASVs. This particular set of ASVs is highly similar to serovar Enteritidis from Salmonella Enterica.
library(ape)
Query_Sequences<-read.dna(file = "/PATH/TO/YOUR/FILE/data.fasta",format = "fasta",as.matrix = FALSE)If you are loading in a set of fresh sequence from a raw FASTA file, we recommend using the R package “ape” to load in the FASTA file in the form of a list DNAbin object. The read.dna function from “ape” will load in the correct format which will be appropriate for input into the next steps of the algorithm.
MAFFT Alignment
The first step is to prepare an aligned version of the input sequences. These will be done with the MAFFT tool. Installation instructions for Mac OS X and Windows can be found at https://mafft.cbrc.jp/alignment/software/source.html. After installation, we will use a MAFFT wrapper function to work with aligning the sequences in an R environment. It is required that the command line MAFFT tool is installed on your machine and the path leading to it is determined. After that, it is possible to use the wrapper function entirely in R in order to process the query sequence data.
Queries_Aligned_To_MSA<-mafft_wrap(Reference = "Salmonella",Query = Query_Sequences,options = "--keeplength")
Trimmed<-MSA_Trim(MSA = Queries_Aligned_To_MSA)FASTA Data Preparation
The next step is to prepare the sequences for input into the placement algorithm (EPA-NG). For this, the reference sequences need to be re-arranged into the best order which matches the query sequence alleles. After this, the 7 query alleles need to be concatenated, along with all groups of 7 reference alleles. The data preparation function will organize the data and output a list of 2 elements containing the concatenated reference database, and the concatenated query allele, both in proper format for input into EPA-NG.
Prepared_Sequences<-Data_Preparation(Aligned_Queries = Trimmed,Reference = "Salmonella")Sequence Placement using EPA-NG
The evolutionary placement algorithm (EPA-NG) will be used to best place the concatenated query sequences into the correct phylogenetic location among the concatenated 16S reference alleles.
JPlace_Result<-epa_ng_wrap(msa = Prepared_Sequences[[2]],query = Prepared_Sequences[[1]],Species = "Salmonella")Calculation of Pendant Adjusted Clade
This function will use the EPA-NG jplace output file in order to calculate an MRCA from the placement results. The MRCA reported here is used in further calculations to predict the serovar and plot the actual phylogeny for visualization.
MRCA_Node<-Clade_Hit_Finder_Pendant_Final(JPlace_Object = JPlace_Result,Pendant_Multi = 1.5,Species = "Salmonella")Serovar Results Table
This function will generate a shortened list of serovar results, removing any serovars below 5% representation. This function will output a table containing the following information for each resulting serovar: 1. The number of matches in the final resulting clade 2. The fraction of total matches which that serovar represents 3. The maximum depth, or the distance from the MRCA to the farthest hit in the clade (calculated for each serovar) 4. The sum of branch lengths, or the total sum of branch lengths from each hit to the MRCA (calculated for each serovar)
Placement_Results_Table<-Placement_Results_Output(MRCA = MRCA_Node,Species = "Salmonella")
Placement_Results_Table
#> Serovar Fraction Matches in Final Clade Maximum Depth
#> 2 Enteritidis 91.437309 299 0.040483
#> 1 Dublin 5.504587 18 0.039863
#> Sum of Branch Lengths
#> 2 6.276191
#> 1 0.400107Full Serovar Results Table
Alternatively, a full serovar report can be obtained by running the alternative function below. In order to see all results including low percentage results which are trimmed in the previous function, the following function should be used.
Full_Placement_Results_Table<-Placement_Results_Output_Full(MRCA = MRCA_Node,Species = "Salmonella")
Full_Placement_Results_Table
#> Serovar Fraction Matches in Final Clade Maximum Depth
#> 2 Enteritidis 91.4373089 299 0.040483
#> 1 Dublin 5.5045872 18 0.039863
#> 3 Gallinarum 2.7522936 9 0.040342
#> 4 Moscow 0.3058104 1 0.020031
#> Sum of Branch Lengths
#> 2 6.276191
#> 1 0.400107
#> 3 0.260271
#> 4 0.020031Serovar Result
This function will report the predicted serovar if there is a dominant serovar representing >30% of the results observed.
Serovar_Prediction<-Sero_Result(Sero = Full_Placement_Results_Table)
head(Serovar_Prediction)
#> [1] "Enteritidis"Phylogeny Plot of Results
The following function will generate a circular phylogeny plot for easier visualization and color the path from the clade MRCA to the resulting hits in red. After running the phylogeny plotting function below, plot the Phylogeny_Plot object to generate the actual plot. Because of the size of the actual phylogeny, it is reccomended to save the resulting plot as a PNG in dimensions of at least 15,000 x 15,000 pixels. An outside viewer should be used to open the PNG and zoom in to analyze the resulting phylogeny figure. Larger dimensions will increase clarity and allow better zooming at the cost of larger image size.
Plot_Output<-Phylogeny_Plotting(MRCA = MRCA_Node,Species = "Salmonella")
Plot_Output