Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a $test array which contains strings. I also have two functions, replaceOverlap that merges two overlapped strings and findNested that finds if one of the two strings is a substring from the other. The code is in PHP

What I would like to do is to iterate over the $test array and take each element ($epitope) and compare it with the rest of the $epitopes in the array one at a time, as there are some more rules in the algorithm. The issue is that if I only want to print the biggest overlapped-nested string found across the rest of the $test array, and then delete from the array those string that have been merged. This is the code I have so far. Any help will be very appreciated.

$test=array(AVNIVGYSNAQGVDY,DIKYTWNVPKI,DIKYTWNVPKIA,DIKYTWNVPKIAPKSEN,GCHGSEPCIIHRGK,IDGLEVDVPGIDPNAC,IGIKDLRAFQHYDGRTI,IIHRGKPFQLEAV,IKYTWNVPKIAPKSEN,KPFQLEAVFEANQNT,LRQMRTVTPIRMQGG,NFLESLKYVEANKGAIN,PCIIHRGKPFQLEAV,PLVKGQQYDIKYTWNVP,QQYDIKYTWNVPKI,QQYDIKYTWNVPKIA,QQYDIKYTWNVPKIAP,QQYDIKYTWNVPKIAPK,QQYDIKYTWNVPKIAPKS,QQYDIKYTWNVPKIAPKSE,QQYDIKYTWNVPKIAPKSEN,QYDIKYTWNVPK,QYDIKYTWNVPKI,QYDIKYTWNVPKIAPKS,QYDIKYTWNVPKIAPKSEN,RFGISNYCQIYPPNV,SAYLAHRNQSLDLAEQELVDCAS,TAIAVIIGIKDLRAFQH,TWNVPKIAPKSENVVVT,YAYVAREQSCR,YDIKYTWNVPK,YDIKYTWNVPKI,YDIKYTWNVPKIA,YDIKYTWNVPKIAPKSEN);

$i=0;
foreach ($test as $epitope){
    $str1=$epitope;
    for ($j = $i; $j < count($test); ++$j) {
        $str2=$test[$j];
        $value1 = replaceOverlap($str1,$str2);
        $value2 = replaceOverlap($str2,$str1);
        $value3 = findNested($str1,$str2);
        if (replaceOverlap($str1,$str2)!=false){
            array_splice($test[$j]);
            print $value1;echo"</br>";
        }
        elseif (replaceOverlap($str2,$str1)!=false){
            array_splice($test[$j]);
            print $value2;echo"</br>";
        }
        elseif (findNested($str1,$str2)!=false){
            array_splice($test[$j]);
            print $value3;echo"</br>";
        }
    }
    $i=$i+1;
}
share|improve this question
    
Why do you have random constant names in an array? Does this php feature still exist, that it converts non existing constants to string? I thought it died out years ago. Where did you learned this? –  inf3rno 12 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.