# Core Assignment

## Constructing A Core Library

The process aims to construct a library of non-overlapping universal expressed sequence regions. A set of reference assemblies is used to identify these elements and define the expected mutation rate for the species used by the filter step.

<table data-header-hidden><thead><tr><th width="242">Species Name</th><th width="127">References Genomes</th><th width="112">Core Size</th><th width="130">Core Nt Size</th><th>PID Threshold</th></tr></thead><tbody><tr><td>Species Name</td><td>References Genomes</td><td>Core Size</td><td>Core Nt Size</td><td>PID Threshold</td></tr><tr><td><em>Klebsiella pneumoniae</em></td><td>13</td><td>1972</td><td>2172367</td><td>90.0</td></tr><tr><td><em>Klebsiella quasipneumoniae</em></td><td>56</td><td>1810</td><td>1974880</td><td></td></tr><tr><td><em>Klebsiella variicola</em></td><td>41</td><td>1783</td><td>1942295</td><td></td></tr><tr><td><em>Staphylococcus aureus</em></td><td>20</td><td>1625</td><td>1742498</td><td>80.0</td></tr><tr><td><em>Salmonella</em> Typhi</td><td>19</td><td>3284</td><td>3594178</td><td>90.0</td></tr><tr><td><em>Neisseria gonorrhoeae</em></td><td>14</td><td>1542</td><td>1470119</td><td>80.0</td></tr><tr><td><em>Vibrio cholerae</em></td><td>17</td><td>2736</td><td>3075173</td><td></td></tr><tr><td>Zika virus</td><td>1</td><td>10</td><td>10215</td><td>80.0</td></tr><tr><td><em>Streptococcus equi</em></td><td>1</td><td>1286</td><td>1441721</td><td>80.0</td></tr><tr><td><em>Renibacterium salmoninarum</em></td><td>5</td><td>2500</td><td>2667272</td><td>80.0</td></tr><tr><td><em>Candida auris</em></td><td>5</td><td>4173</td><td>6249130</td><td>70.0</td></tr></tbody></table>

### Generating An Initial Start Set

For each targeted species a core was either:

* Provided by a collaborator and BLAST matches are extracted from each reference genome and aligned using MAFFT
* Built in-house using [ROARY](https://sanger-pathogens.github.io/Roary/) and the alignments used directly.

### Processing the Alignments

1. All families with matching starts and ends (flat edges to the alignment, “perfect rectangles”) were used without alteration. This is the case for the vast majority of core families identified.
2. The remaining families were aligned with MAFFT and processed to produce straight edges.&#x20;
   * For the majority of these families, variation in the gene boundaries were due to different potential start sites being used, while a much smaller number were due to alternative stop codons. In general a consensus-based approach was used to determine the likely start or stop site.
   * If there was uncertainty that a region was found in all genes, a representative sequence was searched against the original assemblies to confirm that it was present in all of them.&#x20;
3. A representative from each family is selected by identifying the sequence with the most number of nucleotides in agreement with the consensus according the alignment.
4. These are searched against each reference genome using BLAST (60% identity threshold, E-value 1e-35, 80% gene coverage) and the location of each match extracted.&#x20;
   1. Families with multiple matches are removed at this stage.
   2. Overlapping complete matches (on either strand) are fused into a single segment that covers both genes. This is done in each reference genome and the resulting multi-gene segments searched against each and the cross-hits resolved. Segments with partial matches in other genomes are also removed at this stage.
5. A database is constructed using the fused gene set and searched using BLAST as before against the reference genomes again. Any segments that don't meet the following criteria are excluded:
   1. A complete copy is found in every reference genome
   2. There are no extra partial matches above the gathering thresholds.
6. This merged and reduced set of DNA segments define the core sequence database used in Pathogenwatch.&#x20;

{% hint style="info" %}
Any candidate core segments with potential paralogs or pseudogene copies are identified and removed. Such regions can often fail to assemble well and produce artificial variance in genome comparisons.
{% endhint %}

### Profiling A New Assembly

1. The query assembly is searched against the species' BLAST database using _blastn_ with species specific parameters. By default these are `-evalue 1e-35 -perc_identity [gathering threshold]`_._
2. Hits below 80% of the core gene length are removed as fragments.
3. For each allele, the SHA-1 checksum and variants relative to the representative sequence are determined. Variants are segregated into substitutions, insertions and deletions, with adjacent variants of the same type merged into a single mutation.



