<?php
# sequences.php : Programa de deteccion de motivos en sequences genéticas reguladoras
# Derechos Reservados (c) 2004 Francisco Javier Carlos Rivera <javier@nediam.com.mx>
# Copyright (c) 2004 Francisco Javier Carlos Rivera <javier@nediam.com.mx>
# Este codigo es Open Source, esta bajo los terminos de la licencia MIT Licence
# ultima fecha de modificacion: 2004-11-07
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Regular expressions example</title>
<script type="text/javascript">
<!--
        function abrir_ventana(url, titulo, ancho, alto)
        { 
            var wintop = (screen.height - alto) / 2;
            var winleft = (screen.width - ancho) / 2;
            var winattribs = 'width=' + ancho + ',height=' + alto + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes,resizable=no';
            var ventana=window.open(url,titulo,winattribs);
            if (parseInt(navigator.appVersion) >= 4)
            {
                ventana.window.focus();
            }
        }
-->
</script>
<style type="text/css">
body { background-color : #FFFFFF; }

.indented { padding-right: 10pt; }

h1
{
    color : #369;
    font-family: Arial, sans-serif;
    font-size: 15pt;
    text-align: center;
}

h2
{
    color : #369;
    font-family: Arial, sans-serif;
    font-size: 13pt;
    text-align: center;
}

h3
{
    color : #369;
    font-family: Arial, sans-serif;
    font-size: 10pt;
    text-align: center;
    font-weight: normal;
}

p    
{
    color : #369;
    margin-left: 1em;
    margin-right: 1em;
    text-align: justify;
    font-family: Arial, sans-serif;
    font-size: 11pt;
    font-weight: normal;
}

caption
{
    color : #369;
    font-family: Arial, sans-serif;
    font-size: 10pt;
    text-align: center;
    font-weight: normal;
}

.tb_h
{
    background-color: #369;
    color: #FFFFFF;
    font-family: Arial, sans-serif;
    font-size: 10pt;
    text-align: center;
    font-weight: normal;
}

.tb_r
{
    background-color: #FFFFFF;
    color: #1F3C77;
    font-family: Arial, sans-serif;
    font-size: 10pt;
    text-align: center;
    font-weight: normal;
}

.tb_r2
{
    background-color: #E6E6E6;
    color: #1F3C77;
    font-family: Arial, sans-serif;
    font-size: 10pt;
    text-align: center;
    font-weight: normal;
}

a:link, a:visited {color: #369; text-decoration : none;}
a:hover {color: #77899C}

.boton
{
    font-family : Arial;
    font-size: 10pt;  
    BORDER-RIGHT: 1px solid; 
    BORDER-TOP: 1px solid; 
    BORDER-LEFT: 1px solid; 
    BORDER-BOTTOM: 1px solid; 
    BACKGROUND-COLOR: #369; 
    COLOR: #FFF;
}

    </style>
</head>
<body>
    <h1>Regular expressions example</h1>
    <h3><b>Author: Fco. Javier Carlos Rivera &lt;<a href="mailto:javier@nediam.com.mx">javier@nediam.com.mx</a>&gt;</b></h3>

<p align="justify"><br />
The source code is available <a style="text-decoration:underline" href='./sequences.phps' target='blank'>here</a>.
<br /><br />
<b>How to use</b>: 
Click on one of the following sequences examples links and copy and paste some of them. Then write a pattern you want to search and click on the Search button.
<br /><br />
<b>Example sequences:</b> 
<a href='#' onclick="abrir_ventana('./sequences_100','sequences_100','650','300'); return false;">Length: 100</a>
&nbsp;|&nbsp;
<a href='#' onclick="abrir_ventana('./sequences_500','sequences_500','650','300'); return false;">Length: 500</a>
&nbsp;|&nbsp;
<a href='#' onclick="abrir_ventana('./sequences_1000','sequences_1000','650','300'); return false;">Length: 1000</a>
&nbsp;|&nbsp;
<a href='#' onclick="abrir_ventana('./sequences_2500','sequences_2500','650','300'); return false;">Length: 2500</a>
</p>

    
<form action='./sequences.php' method='post'><br />
<table border='0' align='center'>
    <caption><b>Sequences</b></caption>
    <tr><td>            
        <textarea name='secuencia' rows='15' cols='100'><?php if(trim($_POST[secuencia])) echo $_POST[secuencia];?></textarea>
    </td></tr>
    <tr><td>
    <h3>Sequences length:
    <?php if(!$_POST[longitud]) $_POST[longitud] = 100?>
        <input type='radio' name='longitud' value='100' <?php if($_POST[longitud] == 100) echo 'checked="checked"';?> />100 &nbsp;
        <input type='radio' name='longitud' value='500' <?php if($_POST[longitud] == 500) echo 'checked="checked"';?> />500 &nbsp;
        <input type='radio' name='longitud' value='1000' <?php if($_POST[longitud] == 1000) echo 'checked="checked"';?> />1000 &nbsp;
        <input type='radio' name='longitud' value='2500' <?php if($_POST[longitud] == 2500) echo 'checked="checked"';?> />2500
    </h3></td></tr>
    <tr><td>
        <br /><h3>Pattern:
        <input type='text' name='patron' <?php if(trim($_POST[patron])) echo "value='" trim($_POST[patron]) . "'";?>maxlength='25' size='20' />
        <input type='submit' value='Search' class='boton' /></h3>
    </td></tr>
</table>

</form>

<?php
$secuencia 
$_POST[secuencia];
$patron trim($_POST[patron]);
if(
$secuencia && $patron)
{
    
//primero desgloso las sequences
    
if($_POST[longitud] == 100)
        
preg_match_all('/(>[\S]+).*\r\n((([A-Z]{80}\r\n){1})[A-Z]{20}\r\n)/'$secuencia$array);
    else if(
$_POST[longitud] == 500)
        
preg_match_all('/(>[\S]+).*\r\n((([A-Z]{80}\r\n){6})[A-Z]{20})\r\n/'$secuencia$array);
    else if(
$_POST[longitud] == 1000)
        
preg_match_all('/(>[\S]+).*\r\n((([A-Z]{80}\r\n){12})[A-Z]{40})\r\n/'$secuencia$array);
    else if(
$_POST[longitud] == 2500)
        
preg_match_all('/(>[\S]+).*\r\n((([A-Z]{80}\r\n){31})[A-Z]{20})\r\n/'$secuencia$array);
    
?>
    <br /><h2>Results</h2>
    <table border='1' cellpadding='4'  align='center'>
        <caption><b>Motivo: <?php echo $patron;?></b></caption>
        <tr class='tb_h'>
            <td>SEQUENCE</td><td>ROW</td><td>POSITION</td>
        </tr>
        
    <?php
    $len_patron 
strlen($patron);
    
$x 1;
    
$y 1;
    
    
//recorro cada secuencia para buscar si se encuentra el patron buscado
    
for($i=0$i<count($array[1]); $i++)
    {
        
$key $array[1][$i];
            
$value $array[2][$i];
        
        
$rows explode("\n"$value);
        if(
$x==1)
        {
            
            if(
$y)
                
$class='tb_r';
            else
                
$class='tb_r2';
            
$y = !$y;
        }
        
$x 0;
        
//recorro cada renglon de la secuencia para buscar el patron buscado
        
for($j=0$j<count($rows); $j++)
        {
            
preg_match_all('/(.*)' $patron '/U'$rows[$j], $matchesPREG_SET_ORDER);
            
$cont 0;
            for(
$k=0$k<count($matches); $k++)
            {
                
$x 1;
                
$cont += strlen($matches[$k][1]);
                echo 
"<tr class='" $class "'><td>$key</td><td>$j</td><td>" $cont "</td></tr>\n";
                
$cont += $len_patron;
            }
        }
    }
    echo 
"</table>\n";
}
?>
<br />
<a href="http://validator.w3.org/check?uri=referer" target="_blank">
<img style="border:0px; width:88px; height:31px" src="../../../images/valid-xhtml10.png" alt="Valid XHTML 1.0!" /></a><br />

<a href="http://jigsaw.w3.org/css-validator/check/referer" target="_blank">
<img style="border:0px; width:88px; height:31px" src="../../../images/valid-css.png" alt="Valid CSS!" /></a>

</body>
</html>