#!/usr/bin/perl
#change the line above on Unix OS usually to: #!usr/bin/perl or wherever perl.exe lies
print "Content-type: text/html\n\n";
# ---------------------------------- Dependancies and Compatibilities --------------------------------------------------
# The program was written in Perl and tested on Apache HTTP server 2.0.53 on a Windows XP-pro-SP2 OS having
# ActiveState Perl 5.6 installed with Bioperl 1.4 modules. However it is expected that it works on
# Apache on Unix too. In Unix, it may be needed to open each file of the program with a text editor such as pico or nano 
# and save it again in Unix. This may be needed because the program was developed in Windows platforma and 
# some new line characters or some other characters may be meaningless to Unix system.


# The directory "usr_images" and "usr_uploads" where images of RFLP Gel and sequence files are stored respectively 
#for a short time should have WRITE permission
# It is recommended that you put the application folder in  htdocs folder on Apache and permit 
# CGI and Perl script execution by for example an htaccess file or by configuring your server.

# Notice: This script uses Bio::Restriction::EnzymeCollection module of Bioperl. So this module must be installed 
# for this script to work.

# The program was tested from a Windows XP-pro-SP2 platform using Internet Explorer 6 and Netscape Navigator 4.
# Best display feature are expected on Internet Explorer 4.0 or higher.
# However, it is expected that it works well with newer versions of most other web browsers. 


# Apache is available from http://www.apache.org
# A stable version of Perl can be downloaded from http://www.activestate.com
# Bioperl modules can be downloaded from http://www.bioperl.org 

# -------------------------------------------- DistinctiEnz Summary -------------------------------------------------

# DistinctiEnz is a web tool for performing an in-silico RFLP with a set of restriction enzymes on a set of DNA sequences.
# It is used to get an estimate of  DISTINCTION (resolution) power of a set of enzymes for a set of sequences. In other words, it 
# helps the user to learn with what enzyme or set of enzymes, he or she can best DISTINGUISH between a set of sequences
# using RFLP.
# DistinctiEnz performs a restriction analysis on each sequence and examines all fragments to see how unique the
# cut fragments from each sequence are when compared to all other fragment sets produced from other sequences
# in the uploaded set. Finally a Resolution Power (Ratio) is calculated by simply dividing the number of unique-fragment sets
# by the number of the submitted sequences. If Resolution power is 100%, it means that that set of enzymes can fully 
# perform a DISTINCTION analysis among the submitted sequences.
# The name DistinctiEnz comes from DISTINCTION. The name was coined by me (Mohammadreza Rezailashkajani) and at least 
# a Google search returned no similar names on the web.
# The program allows the user to:
# 1) Upload a set of sequences in FASTA format all in ONE FASTA file;
# 2) choose one or more restriction enzymes out of a list of enzymes produced from the default collection
#  of Bioperl 
# 3) Choose a dilation factor for the RFLP Gel. The more this factor the better the sequences are seperated 
#    on the gel though it is not the rule with too long sequences. 
# 4) perfrm an RFLP and get a Resolution Power value in addition to graphic RFLP Gel view.

# Alternatively, DistinctiEnz can be used with uploading a file with one sequence just to simply see the 
# in-silico RFLP Gel view of any sequence.



# Contact developer: 
#     docreza@yahoo.com     and          Rezailashkajani.Mohammadreza@postgrad.manchester.ac.uk


# ----------------------------------------- Acknowledgements -------------------------------------------------------------


# DistinctiEnz was first developed by Mohammadreza Rezailashkajani in 
# an online module in bioinformatics in School of Life Sciences, University of Manchester, UK and then 
# was completed in Research Center for Gastroenterology and Liver Diseases (RCGLD), Shaheed Beheshti
# University of Medical Sciences, Tehran, Iran
#It is available freely at http://www.biorcgld.org , the website of Bioinformatics Unit of RCGLD.

#Special acknowledgements goes to the kind financial support of INSF Iran (http://www.INSF.org). 

# I also wish to thank valuable comments from my classmates in Biocomputing Module
# in University of Manchester. 
# My special thanks goes to Caroline Reiff my classmate in Biocomputing Module who was the first one
# to suggest the idea of making such an appication.


#------------------

# Bioperl modules from http://www.bioperl.org was used to:
# 1) make a reference list of restriction enzymes;
# 2) perform restriction enzyme analyses; and
# 3) make a sequence object model from file or directly from strings.

# For a multiple-digest, I used some code examples taught by Robert Edwards [redwards@pub.open-bio.org] in 
# [ http://bioperl.org/pipermail/bioperl-guts-l/2003-December/015775.html ] in addition to documentation 
# for Bio::Restriction::Analysis.

# --------------------------------------------------------------------------------------------------


# Mohammadreza Rezailashkajani, MD
# May 2006
# Bioinformatics Unit, RCGLD, SBUMS, Tehran, Iran
# http://www.biorcgld.org
# http://www.rcgld.org

# ---------------------------------------- Input Form Description --------------------------------------

# Here an input form is created with the following features:
# 	1) A file object (fileSeq) to allow user to upload a file containing multiple sequences in FASTA format
#  	 Sequences can be arranged as the following set in a text file saved in any name with .FASTA extention 
# 	 (any_name.FASTA). Example:

#  			>Sequence_a
#  			ATCGGGGCCAGGGGGGGGATTACTGACCTAGCGATCATCGGGGCCAGGGGGGGGATTACTGACCTAGCGATCATCGGGGCC
#			ATCGGGGCCAGGGGGGGGATTACTGACCTAGCGATCATCGGGGCCAGGGGGGGGATTACTGACCTAGCGATC

#  			>Sequence_b
#  			ATCGACACACATGACCTAGCGATCATCGGTTTTTTTTTTTTTACTGACCTAGCGATCATCGGGGCC
#			ATCGGGGCCAGGGGGGGGATTACTGACCTAGCGATCA

#  			>Sequence_c
#  			ATTTTTTTTTTTTTTTTTCGGGGCCAGGGGGGGGATTACTGACCTAGCGATCATCGGGGCCAGGGGGGGGATTACTGACCTA
#           GCGATCATCGGGGCCAAAAAAAAAAAAAACCTAGCGATCATCGGGGCCAGGGGGGGGATTACTGACCTAGCGATC
#			ATCGGGGCCAGGGGGGGGATTACTGACCTAGCGATCATCGGGGC


# 	2) A checkbox (ckCleaner) to allow user to turn on PowerCleaner which will clean all non-atcg characters
# 	3) A list (cboEnzymes) which is populated from a colection of enzymes and allows user to choose more than one
# 	  enzyme by ctrl+click. At least one enzyme must be selected.
# 	4) A list (cboDilate) which allows user to choose a dilation factor for RFLP Gel. The more this factor the better 
# 	  the sequences are seperated on the gel though it is not the rule with too long sequences.

# The form data will be submitted to rflp_analyzer.pl in the same directory as this form where 
# main processing and analysis will happen and an HTML ouput will be sent to the user.


# ----------------------------------------- Main Script -------------------------------------------------------------------------------
# use print<< command for out-printing multiline strings in Perl.

print <<EOF;
<!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">
<HEAD>
<TITLE>DistinctiEnz :: in-silico RFLP tool </TITLE>

</HEAD>
<body style="font-family:Arial; font-size:13px" bgcolor="#FFFFFF" link="#0033CC" vlink="#990099" alink="#CC3300" leftmargin="3" topmargin="0" marginwidth="4" marginheight="0">
<!-- ================= A simple navigation bar to browse around the web application ===================== -->
<table width="100%"  style="font-family:Tahoma, Arial; font-size:14px; font-weight:bold" border="0" cellpadding="2" cellspacing="0" bordercolor="#CC9999" bgcolor="#FFFFFF">
  <tr>
    <td valign='middle' bgcolor="#FFFFFF"><img src="../../rest_html/images/logo_distinctienz.gif" width="133" height="45"> </td>
  </tr>
  <tr>
    <td bgcolor="#000099"> <font color="#FFFFFF"><a href="../../rest_html/home.htm"><font color="#FFFFFF" size="2">Home</font> </a><font size="2"> | <a href="DistinctiEnz.pl"><font color="#FFFFFF">New
        RFLP Analysis</font> </a> | <a href="../../rest_html/help_DistinctiEnz.htm"><font color="#FFFFFF">Help</font></a> </font> </font></td>
  </tr>
</table>
 <!--  ==================================== End navigation bar ===============================  -->
 
 
 <!--  ==================================== Start input form production ======================= -->
<form action="rflp_analyzer.pl" method="post" enctype="multipart/form-data" name="frmRestrict" id="frmRestrict">
 
<p>Browse to upload a FASTA file containing ALL your sequences in FASTA format. <a target='_blank' href='../../rest_html/help_DistinctiEnz.htm#input'>[?]</a><br>
    <input name="fileSeq" type="file" size="50" id="fileSeq" />
 <br><input type="checkbox"  value="isCircular" name="ckCircular">All uploaded sequences are <b>circular</b>. <a target='_blank' href='../../rest_html/help_DistinctiEnz.htm#seqoptions'>[?]</a>
    <br><input type="checkbox"  value="doClean" checked='checked' name="ckCleaner"><b>Turn on <i>PowerCleaner!</i> </b>(Cleans all non-atcg characters from the uploaded sequences.) <a target='_blank' href='../../rest_html/help_DistinctiEnz.htm#seqoptions'>[?]</a>
 </p>
  <p>Select one or more enzymes (ctrl + click): <a target='_blank' href='../../rest_html/help_DistinctiEnz.htm#enzselection'>[?]</a><br>
   <select name="cboEnzymes" size="10"  multiple="multiple">
EOF


# Define an enzyme collection using Bio::Restriction::EnzymeCollection module of Bioperl. 
# This collection usually contains around 500 type II enzymes.
# Instead, you can define your enzyme collection using Bio::Restriction::IO module of Bioperl and 
# an enzyme file from REBASE at http://rebase.neb.com/rebase
use Bio::Restriction::EnzymeCollection;
my $enzCollection=Bio::Restriction::EnzymeCollection->new();

# Populate the list with enzyme names.
foreach $enz($enzCollection->available_list){
	print "<option value=\"$enz\">$enz</option>";
}
print <<FINI;  
         
     </select>
<br><br><input type='checkbox' onClick="javascript:if (this.checked){document.all.nonBatch.style.visibility='hidden';}else{document.all.nonBatch.style.visibility='visible';}" value='batch' name='ckBatch'><b>Test each enzyme</b> (produces no graphical output). <a target='_blank' href='../../rest_html/help_DistinctiEnz.htm#dilationfact'>[?]</a>
<div id='nonBatch'>     
<br>Select RFLP gel dilation factor: 
<!--  ==================================== A list to select Gel dilation factor ======================= -->
    <select name="cboDilate">
<!-- <option value='10'>10</option>
    <option value='15'>15</option>
    <option value='20'>20</option>
    <option value='25'>25</option>
    <option value='30'>30</option>
    <option value='35'>35</option>
    <option value='40'>40</option>
    <option value='45'>45</option> -->
	    
    <option value='50'>50</option>
    <option value='70' selected>70</option>
    <option value='100'>100</option>

    </select>
    
<!--  ==================================== End list ======================= -->

<a target='_blank' href='../../rest_html/help_DistinctiEnz.htm#dilationfact'>[?]</a><br><br>
Select a ladder for RFLP. <select name="cboLadder">
    <option value="100-250-500-1000-2000">EasyLadder I: 100-250-500-1000-2000</option>
    <option value="500-1000-2000-3000-5000">EasyLadder II: 500-1000-2000-3000-5000</option>
    <option value="200-400-600-800-1000-1500-2000-2500-3000-4000-5000-6000-8000-10000">HyperLadder
    I: 200-400-600-800-1000-1500-2000-2500-3000-4000-5000-6000-8000-10000</option>
    <option value="50-100-200-300-400-500-600-700-800-1000-1200-1400-1600-1800-2000">HyperLadder
    II: 50-100-200-300-400-500-600-700-800-1000-1200-1400-1600-1800-2000</option>
    <option value="500-700-1000-1500-2000-2500-3000-3500-4000-4500-5000">HyperLadder
    III: 500-700-1000-1500-2000-2500-3000-3500-4000-4500-5000</option>
    <option value="100-200-300-400-500-600-700-800-1000">HyperLadder IV: 100-200-300-400-500-600-700-800-1000</option>
    <option value="25-50-75-100-125-150-175-200-250-300-400-500" selected>HyperLadder
    V: 25-50-75-100-125-150-175-200-250-300-400-500</option>
  </select>
<a target='_blank' href='../../rest_html/help_DistinctiEnz.htm#dilationfact'>[?]</a> 
</div>
  <p>
    <input type="submit" name="Submit" value="Do RFLP and Calculate Resolution power" />
</p>
</form></BODY>

<p align='center'>This web tool is best viewed by Internet Explorer 4.0, Netscape Navigator 4.0, or higher-version browsers</p>
</HTML>
FINI

