Sequence match

1

Starting code

This is the PHP code used by this example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
  * 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
        ]
    );
}
2

Result

Result returned by BioPHP for the demonstration data.

Submatrix :
  • 0 :
    • 0 : D
    • 1 : E
  • 1 :
    • 0 : K
    • 1 : R
    • 2 : H
  • 2 :
    • 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 :
56
Matching results :
......C..C..AG.CC.G..C..........C.......CC....C.C...G...G.C....C.C.....G....A...G..CTGG..GC.....G...

The code above is the one actually executed by this page. Find the other examples in the left-hand column, or the tools in BioTools.