Sequence match


Sample code :


/**
  * Here is some samples of how to use the functions
  * @param   SequenceMatchInterface $sequenceMatchManager
  * @param   SequenceAlignmentInterface $sequenceAlignmentManager
  * @param   SequenceInterface $sequenceManager
  * @return  Response
  * @throws  \Exception
  */
public function sequencematch(
    SequenceMatchInterface $sequenceMatchManager,
    SequenceAlignmentInterface $sequenceAlignmentManager,
    SequenceInterface $sequenceManager
){
    $sequenceAlignmentManager->setFilename("data/fasta-2.txt");
    $sequenceAlignmentManager->setFormat("FASTA");
    $sequenceAlignmentManager->parseFile();
    $oSequence = $sequenceAlignmentManager->getSeqSet()->offsetGet(0);
    $oSequence->setMolType("DNA");
    $sequenceManager->setSequence($oSequence);
 
    // Setting the matrix
    $oSubMatrix = new SubMatrix();
    $oSubMatrix->addrule('D', 'E');
    $oSubMatrix->addrule('K', 'R', 'H');
    $oSubMatrix->addrule('X');
    $sequenceMatchManager->setSubMatrix($oSubMatrix);
 
    // Setting the 2 sequences
    $sSeq1 = $sequenceManager->subSeq(2,100);
    $sSeq2 = $sequenceManager->subSeq(100,100);
 
    // Computes the Hamming Distance between two sequences
    $iDistance = $sequenceMatchManager->hamdist($sSeq1, $sSeq2);
 
    // Compares two letters $let1 and $let2 and returns another letter
    // indicating if the two were exact matches, partial matches, or non-matches
    $sCompare1 = $sequenceMatchManager->compareLetter('A', 'T');
    $sCompare2 = $sequenceMatchManager->compareLetter('A', 'A');
 
    // Computes the Levenshtein Distance between two sequences with equal/unequal lengths
    $iLevdist = $sequenceMatchManager->levdist($sSeq1, $sSeq2);
 
    // Extended version of levdist() which accepts strings with length greater than 255 but not to exceed 1024
    $iXLevdist = $sequenceMatchManager->xlevdist($sSeq1, $sSeq2);
 
    // Matching results
    $sMatch = $sequenceMatchManager->match($sSeq1, $sSeq2);
 
 
    return $this->render('default/sequencematch.html.twig',
        [
            'submatrix' => $oSubMatrix,
            'sequence1' => $sSeq1,
            'sequence2' => $sSeq2,
            'distance' => $iDistance,
            'compare1' => $sCompare1,
            'compare2' => $sCompare2,
            'levdist' => $iLevdist,
            'xlevdist' => $iXLevdist,
            'match' => $sMatch
        ]
    );
}

Result :

Submatrix :

Amelaye\BioPHP\Domain\Sequence\Entity\SubMatrix {#658
  -rules: array:3 [
    0 => array:2 [
      0 => "D"
      1 => "E"
    ]
    1 => array:3 [
      0 => "K"
      1 => "R"
      2 => "H"
    ]
    2 => array:1 [
      0 => "X"
    ]
  ]
}

Sequence 1 :

"CAGATTCCCCCTAGACCCGCCCGCACCATGGTCAGGCATGCCCCTCCTCATCGCTGGGCACAGCCCAGAGGGTATAAACAGTGCTGGAGGCTGGCGGGGC"

Sequence 2 :

"GCAGGCCAGCTGAGTCCTGAGCAGCAGCCCAGCGCAGCCACCGAGACACCATGAGAGCCCTCACACTCCTCGCCCTATTGGCCCTGGCCGCACTTTGCAT"

Computes the Hamming Distance between two sequences

72

Compares two letters $let1 and $let2 and returns another letter indicating if the two were exact matches, partial matches, or non-matches.
Not matching (A & T) :

"."

Matching (A & A) :

"A"

Computes the Levenshtein Distance between two sequences with equal/unequal lengths :

56

Extended version of levdist() which accepts strings with length greater than 255 but not to exceed 1024 :

49

Matching results :

"......C..C..AG.CC.G..C..........C.......CC....C.C...G...G.C....C.C.....G....A...G..CTGG..GC.....G..."