Advanced User Guide - SangerContig (AB1)¶
SangerContig is the second level in sangeranalyseR showed in Figure_1 which corresponds to a contig in Sanger sequencing. Among slots inside it, there are two lists, forward and reverse read list, storing SangerRead in the corresponding direction. In this section, we are going to go through details about sangeranalyseR data analysis in SangerContig level from AB1 file input.

Figure 1. Hierarchy of classes in sangeranalyseR, SangerContig level.¶
Preparing SangerContig AB1 input¶
The main input file format to create SangerRead instance is AB1. Before starting the analysis, users need to prepare all AB1 files inside one directory. It is the parent directory and all AB1 files must be in the first layer of it; in other words, there should not be any directory containing any AB1 files inside the parent directory. Because sangeranalyseR will group AB1 files based on their direction automatically, users have to follow the file naming regulations below:
Note
All the input files must have .ab1 as its file extension
All the input files must have the same contig name in its filename.
Forward or reverse direction also has to be specified in the filename.
There are four parameters, parentDirectory
, contigName
, suffixForwardRegExp
and suffixReverseRegExp
,that users need to provide so that program can automatically match correct AB1 files and divide them into forward and reverse direction.
Note
parentDirectory
: The root directory that contains all the AB1 files. It can be absolute or relative path. We suggest users to put only target AB1 files inside this directory without other unrelated files.contigName
: The value of this parameter is a regular expression that matches filenames that are going to be included in the SangerContig level analysis.grepl
function in R is used.suffixForwardRegExp
: The value of this parameter is a regular expression that matches all filenames in forward direction.grepl
function in R is used to select forward reads from all AB1 files.suffixReverseRegExp
: The value of this parameter is a regular expression that matches all filenames in reverse direction.grepl
function in R is used to select reverse reads from all AB1 files.
Here, we have an example:

Figure 2. SangerContig filename regulation.¶
Figure_2 shows the file naming regulation and hierarchy. In this example, ACHLO
is the parent directory that contains all AB1 files. They must be in the first layer of the directory.
sangeranalyseR will first match the contigName
to exclude unrelated files and then separate the forward and reverse reads by matching suffixForwardRegExp
and suffixReverseRegExp
. Therefore, it is important to make sure all target AB1 files share the same contigName
and carefully select suffixForwardRegExp
and suffixReverseRegExp
. The bad file naming and wrong regex matching might accidentally include reverse reads into the forward read list or vice versa, which will make the program generate totally wrong results. Therefore, users should have a consistent naming strategy. In this example, "_[0-9]+_F"
, "_[0-9]+_R"
for matching forward and reverse reads are highly suggested and are used as default. Moreover, it is a good habit to index your reads in the same contig group because there might be more than one read that are in the forward or reverse direction.

Figure 3. Suggested AB1 file naming regulation - SangerContig.¶
Figure_3 shows the suggested AB1 file naming regulation. Users are strongly recommended to follow this file naming regulation and use the default suffixForwardRegExp
: "_[0-9]+_F
" and suffixReverseRegExp
: "_[0-9]+_R
" to reduce any chance of error.
Creating SangerContig instance from AB1¶
After preparing the input directory, we can create the SangerContig S4 instance by running SangerContig
constructor function or new
method. The constructor function is a wrapper for new
method and it makes instance creation more intuitive. Most parameters in the constructor have their own default values. In the constructor below, we list important parameters.
sangerContig <- SangerContig(inputSource = "ABIF",
parentDirectory = "./tmp/",
contigName = "Achl_ACHLO006-09",
suffixForwardRegExp = "[0-9]*_F.ab1",
suffixReverseRegExp = "[0-9]*_R.ab1",
TrimmingMethod = "M1",
M1TrimmingCutoff = 0.0001,
M2CutoffQualityScore = NULL,
M2SlidingWindowSize = NULL,
baseNumPerRow = 100,
heightPerRow = 200,
signalRatioCutoff = 0.33,
showTrimmed = TRUE,
refAminoAcidSeq = "",
minReadsNum = 2,
minReadLength = 20,
minFractionCall = 0.5,
maxFractionLost = 0.5,
geneticCode = GENETIC_CODE,
acceptStopCodons = TRUE,
readingFrame = 1,
processorsNum = NULL)
In this example, contigName
is set to "Achl_ACHLO006-09"
, so only "Achl_ACHLO006-09_1_F.ab1"
and "Achl_ACHLO006-09_2_R.ab1"
will be selected to align to a contig.
The inputs of SangerContig
constructor function and new
method are same. For more details about SangerContig inputs and slots definition, please refer to sangeranalyseR reference manual (need update). The created SangerContig instance, sangerContig
, is used as the input for the following functions.
Updating SangerContig quality trimming parameters¶
In the previous Creating SangerContig instance from AB1 part, the constructor function will apply the quality trimming parameters to all reads. After creating the SangerContig S4 instance, users can change the trimming parameters by running updateQualityParam
function which will update all reads with the new trimming parameters and redo reads alignment. If users want to do quality trimming read by read instead of all at once, please read Launching SangerContig Shiny app page.
newSangerContig <- updateQualityParam(sangerContig,
TrimmingMethod = "M2",
M1TrimmingCutoff = NULL,
M2CutoffQualityScore = 20,
M2SlidingWindowSize = 15)
Launching SangerContig Shiny app¶
We create an interactive local Shiny app for users to go into each SangerRead in SangerContig instance. Users only need to run one function, launchApp
, with previously created instance as input and the SangerContig Shiny app will pop up. Here, we will go through pages in the two levels, SangerRead and SangerContig pages.
launchApp(newSangerContig)
SangerContig page (SC app)¶
SangerContig page is the initial page of SangerContig Shiny app. Figure 4 shows the overview page of the contig. Notice that there is a red "Re-calculate Contig" button. Users need to click the button after changing the quality trimming parameters in order to get the updated information. In SangerContig page, there are two expendable tabs, “Forward Reads” and “Reverse Reads” storing the corresponding reads on the left-hand side navigation panel in Figure 4. See SangerRead page (SC app) for more details of the subpage.

Figure 4. SangerContig Shiny app initial page - SangerContig page.¶
The information provided in this page are input parameters and contig results including “genetic code table”, “reference amino acid sequence”, “reads alignment”, “difference data frame”, “dendrogram”, “sample distance heatmap”, “indels data frame”, and “stop codons data frame”.
Figure 5 shows reads alignment result and difference data frame. The alignment is generated by AlignSeqs
or AlignTranslation
function in DECIPHER package.

Figure 5. SangerContig page - reads alignment and difference data frame.¶
Figure 6 shows dendrogram result in both plot and in data frame. The results are generated by IdClusters
function in DECIPHER package.

Figure 6. SangerContig page - dendrogram.¶
Figure 7 shows distance between AB1 files. The results are generated by DistanceMatrix
function in DECIPHER package. The heatmap is generated by plot_ly
function in plotly package.

Figure 7. SangerContig page - samples distance.¶
Figure 8 shows insertions, deletions and stop codons data frame.

Figure 8. SangerContig page - indels and stop codons data frame.¶
SangerRead page (SC app)¶
Now, let's go to the next level which is also the lowest level, SangerRead page. SangerRead page contains all details of a read including its trimming and chromatogram inputs and results. All reads are in "forward" or "reverse" direction. In this example, there is one read in each direction and Figure 9 shows "1 Forward Read" page. This page provides basic information, quality trimming inputs, chromatogram plotting inputs etc. Primary/secondary sequences and quality Phred scores table in this figure are dynamic based on the signalRatioCutoff
value for base calling and the length of them are always same. Another thing to mention is that primary/secondary sequences and the sequences in the chromatogram in Figure 14 below will always be same after trimming and their color codings for A/T/C/G are same as well.

Figure 9. SangerContig Shiny app - SangerRead page¶
In quality trimming steps, we removes fragment at both ends of sequencing reads with low quality score. It is important because trimmed reads will improves alignment results. Figure 10 shows the UI for Trimming Method 1 (M1): ‘Modified Mott Trimming’. This method is implemented in Phred. Users can change the cutoff score and click “Apply Trimming Parameters" button to update the UI. The value of input must be between 0 and 1. If the input is invalid, the cutoff score will be set to default 0.0001.

Figure 10. SangerRead page - Trimming Method 1 (M1): ‘Modified Mott Trimming’ UI.¶
Figure 11 shows another quality trimming method for users to choose from, Trimming Method 2 (M2): ‘Trimmomatics Sliding Window Trimming’. This method is implemented in Trimmomatics. Users can change the cutoff quality score as well as sliding window size and click “Apply Trimming Parameters" button to update the UI. The value of cutoff quality score must be between 0 and 60 (default 20); the value of sliding window size must be between 0 and 40 (default 10). If the inputs are invalid, their values will be set to default.

Figure 11. SangerRead page - Trimming Method 2 (M2): ‘Trimmomatics Sliding Window Trimming’ UI.¶
Figure 12 shows the quality report before and after trimming. After clicking the “Apply Trimming Parameters” button in Figure 10 or Figure 11, the values of these information boxes will be updated to the latest values.

Figure 12. SangerRead page - read quality report before / after trimming.¶
In Figure 13, the x-axis is the index of the base pairs; the y-axis is the Phred quality score. The green horizontal bar at the top of the plot is the raw read region and the orange horizontal bar represents the remaining read region. Both Figure 13 trimming plot and Figure 14 chromatogram will be updated once users change the quality trimming parameters and click the “Apply Trimming Parameters" button in Figure 14.

Figure 13. SangerContig page - quality trimming plot.¶
If we only see primary and secondary sequences in the table, we will loose some variations. Chromatogram is very helpful to check the peak resolution. Figure 14 shows the panel of plotting chromatogram. Users can change four parameters: Base Number Per Row
, Height Per Row
, Signal Ratio Cutoff
, and Show Trimmed Region
. Among them, Signal Ratio Cutoff
is a key parameter. If its value is default value 0.33, it indicates that the lower peak should be at least 1/3rd as high as the higher peak for it count as a secondary peak.

Figure 14. SangerContig page - chromatogram panel.¶
Here is an example of applying new chromatogram parameters. We click “Show Trimmed Region” to set its value from FALSE
to TRUE
and click the "Apply Chromatogram Parameters" button. Figure 15 shows the loading notification popup during base calling and chromatogram plotting.

Figure 15. SangerContig page - loading notification popup during replotting chromatogram.¶
After replotting the chromatogram, we can see that trimmed region is showed in red striped region. Figure 16 shows part of the the chromatogram (1 bp ~ 240 bp). Moreover, chromatogram will be replotted when trimmed positions or chromatogram parameters are updated.

Figure 16. SangerContig page - chromatogram with trimmed region showed.¶
To let users browse the trimmed primary/secondary sequences without finding “Trimming Start Point” and “Trimming End Point” by themselves, we provide the final trimmed primary/secondary sequences that will be used for reads alignment with quality scores in table format in Figure 17. Frameshift amino acid sequences are also provided.

Figure 17. SangerContig page - trimmed primary/secondary sequences and Phred quality score in table format.¶
We have updated the trimming and chromatogram parameters for each read. Now, we need to click “Re-calculate contig” button to do alignment again. Last but not least, we can save all data into a new ‘SangerContig’ S4 instance by clicking “Save S4 Instance button”. New S4 instance will be saved in Rda format. Users can run readRDS
function to load it into current R environment. Figure 18 shows some hints in the save notification popup.

Figure 18. SangerContig page - saving notification popup.¶
Writing SangerContig FASTA files (AB1)¶
Users can write the SangerContig instance to FASTA files. There are four options for users to choose from in selection
parameter.
reads_unalignment
: Writing reads into a single FASTA file (only trimmed without alignment).reads_alignment
: Writing reads alignment and contig read to a single FASTA file.contig
: Writing the contig to a single FASTA file.all
: Writing reads, reads alignment, and the contig into three different files.
Below is the one-line function that users need to run. This function mainly depends on writeXStringSet
function in Biostrings R package. Users can set the compression level through writeFasta
function.
writeFasta(newSangerContig,
outputDir = tempdir(),
compress = FALSE,
compression_level = NA,
selection = "all")
Users can download the output FASTA file of this example through the following three links:
Generating SangerContig report (AB1)¶
Last but not least, users can save SangerContig instance into a report after the analysis. The report will be generated in HTML by knitting Rmd files.
Users can set includeSangerRead
parameter to decide to which level the SangerContig report will go. Moreover, after the reports are generated,
users can easily navigate through reports in different levels within the HTML file.
One thing to pay attention to is that if users have many reads, it will take quite a long time to write out all reports. If users only want to generate the contig result, remember to set includeSangerRead
to FALSE
in order to save time.
generateReport(newSangerContig,
outputDir = tempdir(),
includeSangerRead = TRUE)
Users can access to 'Basic Information', 'SangerContig Input Parameters', 'Contig Sequence' and 'Contig Results' sections inside the generated SangerContig html report of this example. Furthermore, users can also navigate through html reports of all forward and reverse SangerRead in this SangerContig report.