Exemple #1
0
function Neighbors($Pattern, $d)
{
    /*
    *  Neighbors(Pattern, d)
    			if d = 0
    				return {Pattern}
    			if |Pattern| = 1
    				return {A, C, G, T}
    			Neighborhood ← an empty set
    			SuffixNeighbors ← Neighbors(Suffix(Pattern), d)
    			for each string Text from SuffixNeighbors
    				if HammingDistance(Suffix(Pattern), Text) < d
    					for each nucleotide x
    						add x • Text to Neighborhood
    				else
    					add FirstSymbol(Pattern) • Text to Neighborhood
    			return Neighborhood
    */
    if ($d == 0) {
        return $Pattern;
    }
    $nucleotides = array('A' => 'A', 'C' => 'C', 'G' => 'G', 'T' => 'T');
    if (strlen($Pattern) == 1) {
        return $nucleotides;
    }
    $Neighborhood = array();
    $Suffix = substr($Pattern, 1);
    $Prefix = substr($Pattern, 0, 1);
    $SuffixNeighbors = Neighbors($Suffix, $d);
    foreach ($SuffixNeighbors as $Text) {
        if (HammingDistance($Suffix, $Text) < $d) {
            foreach ($nucleotides as $x) {
                $Neighborhood[] = $x . $Text;
            }
        } else {
            $Neighborhood[] = $Prefix . $Text;
        }
    }
    return $Neighborhood;
}
<?php

require __DIR__ . '/../../_common.php';
echo HammingDistance('CTACAGCAATACGATCATATGCGGATCCGCAGTGGCCGGTAGACACACGT', 'CTACCCCGCTGCTCAATGACCGGGACTAAAGAGGCGAAGATTATGGTGTG');