/* In silico PCR amplification This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. In silico PCR amplification version 1.0, Copyright (C) 2003 Joseba Bikandi */ // GET DATA // All non-word characters (\W) and digits(\d) are remove from primers and from sequence file // primer 1 $primer1=strtoupper ($_POST["primer1"]); $primer1=preg_replace("/\W|\d/","",$primer1); // primer 2 $primer2=strtoupper ($_POST["primer2"]); $primer2=preg_replace("/\W|\d/","",$primer2); // sequence $sequence= strtoupper ($_POST["sequence"]); $sequence=preg_replace("/\W|\d/","",$sequence); // maximum length of amplicons $maxlength=$_POST["length"]; // SET PATTERNS FROM PRIMERS // Change N to point in primers $pattern1=str_replace("N", ".", $primer1); $pattern2=str_replace("N", ".", $primer2); // If one missmatch is allowed, create new pattern // example: pattern="ACGT"; to allow one missmatch pattern=".CGT|A.GT|AC.T|ACG." if ($_POST["allowmissmatch"]==1){ $pattern1=includeN($primer1); $pattern2=includeN($primer2); } // SET PATTERN $start_pattern="$pattern1|$pattern2"; $end_pattern=RevComp($start_pattern); // CALL Amplify FUNCTION $results_array=Amplify($start_pattern,$end_pattern,$sequence,$maxlength); // PRINT RESULTS print "
Primer 1: $primer1\n"; print "Primer 2: $primer2\n\n"; if (sizeof($results_array)>0){ print "List of amplicons: position in sequence, length and sequence\n\n"; foreach($results_array as $key => $val){ print "$key $val ".substr($sequence,$key,$val)."\n"; } }else{ print "No amplification\n\n"; } // ############################################################## // FUNCTIONS // ############################################################## function Amplify ($start_pattern,$end_pattern,$sequence,$maxlength){ // SPLIT SEQUENCE BASED IN $start_pattern (start positions of amplicons) $fragments = preg_split("/($start_pattern)/", $sequence,-1,PREG_SPLIT_DELIM_CAPTURE); $maxfragments=sizeof($fragments); $position=strlen($fragments[0]); $mn=0; for ($m=1;$m<$maxfragments; $m+=2){ $subfragment_to_maximum=substr($fragments[$m+1],0,$maxlength); $fragments2 = preg_split("/($end_pattern)/", $subfragment_to_maximum,-1,PREG_SPLIT_DELIM_CAPTURE); if (sizeof($fragments2)>1){ $lenfragment=strlen($fragments[$m].$fragments2[0].$fragments2[1]); $results_array[$position]=$lenfragment; } $position+=strlen($fragments[$m])+strlen($fragments[$m+1]); } return($results_array); } // #################### function RevComp($p2){ $p2=strrev($p2); $p2=str_replace("A", "t", $p2); $p2=str_replace("T", "a", $p2); $p2=str_replace("G", "c", $p2); $p2=str_replace("C", "g", $p2); $p2 = strtoupper ($p2); return $p2; } // #################### function includeN($pattern) { if (strlen($pattern)>2){ $new_pattern=".".substr($pattern,1); $pos=1; while ($pos