<p>No, STAR isn't using the KMP algorithm or a modification of it.  The KMP algorithm is an online exact pattern matching algorithm.  It does (linear time) pre-processing on the <em>query</em> and then finds all exact occurrences of the query in the string (as you may be alluding, you can also modify KMP to report maximal exactly matching prefixes of the query).  This process takes time of order N+M where N is the length of the reference and M the length of the query.</p>
<p>On the other hand, STAR pre-computes a <a href="https://courses.cs.washington.edu/courses/cse590q/00au/papers/manber-myers_soda90.pdf" rel="nofollow noreferrer">suffix array</a> on the <em>reference</em>, and then uses this to answer exact prefix match queries across <em>many</em> different queries.  This is a very different approach.  Building the suffix array takes time linear in the reference, and storing the suffix array requires space linear in the reference (though the constant factor is pretty big).  However, it allows enumerating all occurrences of a query <em>Q</em> in the reference <em>R</em> in time <span class="math-container">$O(k + lg(\left|R\right|)+ \left|Q\right|)$</span> where <span class="math-container">$k$</span> is the number of occurences of <em>Q</em> in <em>R</em>.  This holds not just for the whole pattern, but for any maximal prefix as well.  Also, in practice, STAR does this much faster by building a lookup table that maps small prefixes (say, all length 12 prefixes) to the contiguous suffix array interval where they occur.  In practice, this gives very fast lookup of queries.  Again, a <em>key</em> difference between this kind of approach and KMP is that the suffix array pre-processes the <em>reference</em> and therefore builds an index that works for many different queries (the sequencing reads), while KMP pre-processes the query to find all of its occurrences on the reference.  Another <em>key</em> difference is that, while the KMP algorithm is always linear in the length of the reference to return all matches in the worst case, the suffix array can be considerably faster.</p>
<p>In the original STAR publication, this is mentioned in the supplementary material in section 1.2 &quot;Pre-indexing of suffix arrays&quot;.  This idea (along with others) is also covered in quite some depth in <a href="https://arxiv.org/pdf/1607.08176.pdf" rel="nofollow noreferrer">this</a> paper.  Basically, the look up table has been a folk technique for a long time, but it's not clear there is an &quot;original&quot; source for it.</p>

CC BY-SA 4.0
2022-01-23T09:32:25.893Z
a sequel in case you are interested in answering it: https://bioinformatics.stackexchange.com/questions/18388/how-should-i-imagin-the-pre-indexing-of-suffix-arrays-in-the-star-rna-seq-aligne
ilam engl
CC BY-SA 4.0
2022-01-21T21:24:44.627Z
2022-01-24T18:56:45.723Z
2022-01-24T18:56:45.723Z
nomad
<p>I don't know if I'm in the right SE, if not let me know and I'll delete it.</p>
<p>I am reading the <a href="https://academic.oup.com/bioinformatics/article/29/1/15/272537" rel="noreferrer">original publication of the STAR RNA-Sequence aligner</a>.</p>
<p>Given the quoted text below I wonder if the algorithm for the seed search is actually an implementation of th Knut-Morris-Pratt algorithm?</p>
<blockquote>
<p>The central idea of the STAR seed finding phase is the sequential search for a Maximal Mappable Prefix (MMP). MMP is similar to the Maximal Exact (Unique) Match concept used by the large-scale genome alignment tools Mummer (Delcher et al., 1999, 2002; Kurtz et al.) and MAUVE (Darling et al., 2004, 2010). Given a read sequence R, read location i and a reference genome sequence G, the MMP(R,i,G) is defined as the longest substring (Ri, Ri+1, … , Ri+MML−1) that matches exactly one or more substrings of G, where MML is the maximum mappable length. We will explain this concept using a simple example of a read that contains a single splice junction and no mismatches (Fig. 1a). In the first step, the algorithm finds the MMP starting from the first base of the read. Because the read in this example comprises a splice junction, it cannot be mapped contiguously to the genome, and thus the first seed will be mapped to a donor splice site. Next, the MMP search is repeated for the unmapped portion of the read, which, in this case, will be mapped to an acceptor splice site. Note that this <strong>sequential application of MMP search only to the unmapped portions of the read</strong> makes the STAR algorithm extremely fast and distinguishes it from Mummer and MAUVE, which find all possible Maximal Exact Matches.</p>
</blockquote>
<p>It is not cited in the references but it might be considered 'common knowledge' by now which is why the citation is omitted...</p>

<algorithms><star>
Is the algorithm of the STAR RNA Seq-Aligner similar to the Knuth-Morris-Pratt string matching algorithm?
# Is the algorithm of the STAR RNA Seq-Aligner similar to the Knuth-Morris-Pratt string matching algorithm?

(Asked by: username_0 on 2022-01-21)

I don't know if I'm in the right SE, if not let me know and I'll delete it.

I am reading the [original publication of the STAR RNA-Sequence aligner](https://academic.oup.com/bioinformatics/article/29/1/15/272537).

Given the quoted text below I wonder if the algorithm for the seed search is actually an implementation of th Knut-Morris-Pratt algorithm?

> The central idea of the STAR seed finding phase is the sequential search for a Maximal Mappable Prefix (MMP). MMP is similar to the Maximal Exact (Unique) Match concept used by the large-scale genome alignment tools Mummer (Delcher et al., 1999, 2002; Kurtz et al.) and MAUVE (Darling et al., 2004, 2010). Given a read sequence R, read location i and a reference genome sequence G, the MMP(R,i,G) is defined as the longest substring (Ri, Ri+1, … , Ri+MML−1) that matches exactly one or more substrings of G, where MML is the maximum mappable length. We will explain this concept using a simple example of a read that contains a single splice junction and no mismatches (Fig. 1a). In the first step, the algorithm finds the MMP starting from the first base of the read. Because the read in this example comprises a splice junction, it cannot be mapped contiguously to the genome, and thus the first seed will be mapped to a donor splice site. Next, the MMP search is repeated for the unmapped portion of the read, which, in this case, will be mapped to an acceptor splice site. Note that this **sequential application of MMP search only to the unmapped portions of the read** makes the STAR algorithm extremely fast and distinguishes it from Mummer and MAUVE, which find all possible Maximal Exact Matches.

It is not cited in the references but it might be considered 'common knowledge' by now which is why the citation is omitted...

**Tags:** algorithms, star

---

## 1 answers

### Answer by username_1 on 2022-01-21. Score: 5 | Accepted answer

No, STAR isn't using the KMP algorithm or a modification of it. The KMP algorithm is an online exact pattern matching algorithm. It does (linear time) pre-processing on the *query* and then finds all exact occurrences of the query in the string (as you may be alluding, you can also modify KMP to report maximal exactly matching prefixes of the query). This process takes time of order N+M where N is the length of the reference and M the length of the query.

On the other hand, STAR pre-computes a [suffix array](https://courses.cs.washington.edu/courses/cse590q/00au/papers/manber-myers_soda90.pdf) on the *reference*, and then uses this to answer exact prefix match queries across *many* different queries. This is a very different approach. Building the suffix array takes time linear in the reference, and storing the suffix array requires space linear in the reference (though the constant factor is pretty big). However, it allows enumerating all occurrences of a query *Q* in the reference *R* in time $O(k + lg(\left|R\right|)+ \left|Q\right|)$ where $k$ is the number of occurences of *Q* in *R*. This holds not just for the whole pattern, but for any maximal prefix as well. Also, in practice, STAR does this much faster by building a lookup table that maps small prefixes (say, all length 12 prefixes) to the contiguous suffix array interval where they occur. In practice, this gives very fast lookup of queries. Again, a *key* difference between this kind of approach and KMP is that the suffix array pre-processes the *reference* and therefore builds an index that works for many different queries (the sequencing reads), while KMP pre-processes the query to find all of its occurrences on the reference. Another *key* difference is that, while the KMP algorithm is always linear in the length of the reference to return all matches in the worst case, the suffix array can be considerably faster.

In the original STAR publication, this is mentioned in the supplementary material in section 1.2 "Pre-indexing of suffix arrays". This idea (along with others) is also covered in quite some depth in [this](https://arxiv.org/pdf/1607.08176.pdf) paper. Basically, the look up table has been a folk technique for a long time, but it's not clear there is an "original" source for it.

> **Comments:**
> **username_0**: a sequel in case you are interested in answering it: https://bioinformatics.stackexchange.com/questions/18388/how-should-i-imagin-the-pre-indexing-of-suffix-arrays-in-the-star-rna-seq-aligne  

---

