Permalink
Switch branches/tags
tag-ensembl-stable-061 start snapshot-at-head-of-07-branch release-ensembl-06 release-06 release-06-2 release-1_01 release-1-7-2 release-1-7-1 release-1-7-0 release-1-7-0-RC6 release-1-7-0-RC5 release-1-7-0-RC4 release-1-6-zenodo release-1-6-924 release-1-6-923 release-1-6-922 release-1-6-921 release-1-6-920 release-1-6-910 release-0-9-3 release-0-9-2 release-0-9-0 release-0-7-2 release-0-7-1 release-0-7-0 release-0-05 release-0-05-1 release-0-04-4 release-0-04-3 release-0-04-2 release-0-04-1 prerelease-06 ontology-overhaul-start ontology-overhaul-end ontology-fix1 lightweight_feature join-0-04-to-0-05 gbrowse_1_65 for_gmod_0_003 bioperl-run-release-1-2-0 bioperl-release-1-6 bioperl-release-1-6-901 bioperl-release-1-6-9 bioperl-release-1-6-1 bioperl-release-1-5-2 bioperl-release-1-5-2-patch2 bioperl-release-1-5-2-patch1 bioperl-release-1-5-1 bioperl-release-1-5-1-rc4 bioperl-release-1-5-0 bioperl-release-1-5-0-rc2 bioperl-release-1-5-0-rc1 bioperl-release-1-4-0 bioperl-release-1-2-3 bioperl-release-1-2-2 bioperl-release-1-2-1 bioperl-release-1-2-0 bioperl-release-1-1-0 bioperl-release-1-0-2 bioperl-release-1-0-1 bioperl-release-1-0-0 bioperl-devel-1-3-04 bioperl-devel-1-3-03 bioperl-devel-1-3-02 bioperl-devel-1-3-01 bioperl-devel-1-1-1 bioperl-061-pre1 bioperl-06-1 bioperl-1-6-RC4 bioperl-1-6-RC3_15392 bioperl-1-6-RC3 bioperl-1-6-RC2_15306 bioperl-1-6-RC2 bioperl-1-6-RC1 bioperl-1-6-0_006 bioperl-1-6-0_005 bioperl-1-6-0_004 bioperl-1-6-0_003 bioperl-1-6-0_002 bioperl-1-6-0_001 bioperl-1-2-1-rc1 bioperl-1-0-alpha2-rc bioperl-1-0-alpha bioperl-1-0-0 before-05-to-06-trunk before-05-to-06-merge after004 after-05-06-merge after-05-06-merge-2
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
227 lines (191 sloc) 6.66 KB
#! /usr/bin/perl
#####################################################
# Fasta
# |
# Align
#
# By
# Antony Vincent
# (a.vincent.0312@gmail.com)
#
# FastAlign is a perl script which uses the heuristic method
# of tfasty36 for find similarity between a query sequence
# in amino acids and a sequence in nucleotides. It provides
# a more intuitive output to find exon-intron junctions.
# The query string is in amino acids and the hit string is
# in nucleotides. There are extra nucleotides at the end of
# the hit string (option -diff and by default = 10), that
# allow to verify if the intron start with common rules
# (5'-GTGCGA-... for group II intron and after an exonic T
# for group I intron).
#
# The FASTA version can be changed by the user by changing
# the line with tfasty36 for tfastyXX.
#
# If you have Emboss, you can genarate a graphic with option
# -graph 1.
#
# For complete help: type perl fastalign.pl -help
# Last Update: 01/06/13
#######################################################
=head1
Copyright (C) 2013 Antony Vincent
Licence:
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, either version 3 of the License, or
(at your option) any later version.
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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=cut
use strict;
use Bio::SearchIO;
use Bio::SeqIO;
use Getopt::Long;
use Bio::SeqUtils;
## Set the default variables
my $identity = 75;
my $length = 50;
my $diff = 10;
my $out = 'output';
my $graphic = 10;
my $query;
my $library;
my $help;
GetOptions(
'seq=s' => \$query,
'db=s' => \$library,
'graph=s' => \$graphic,
'i=i' => \$identity,
'l=i' => \$length,
'diff=s' => \$diff,
'out=s' => \$out,
'help!' => \$help,
)
or die "Incorrect usage! Try perl fastalign.pl -help for an exhaustif help.\n";
###
if( $help )
{ # if start
print "\n";
print "Two options are required:\n";
print " -seq: Your sequence in amino acids\n";
print " -db: The sequence in nucleotides (Could be a whole genome or a partial sequence...)\n";
print "\n";
print "There are few miscellaneous options:\n";
print " -i: Minimum identity percentage (default = 75)\n";
print " -l: Minimum match length (default = 50)\n";
print " -diff: Difference between the hit string and the alignement (default = 10)\n";
print " -out: Name of the output file (default = output.txt)\n";
print " -graph: If this option = 1, a graph will be generated (default = no)\n";
} # if help
else
{ # else start
my $date = `date`;
open (WRITE, ">>$out.txt"); ## Open the output file
print WRITE " Fasta\n";
print WRITE " |\n";
print WRITE " Align\n\n";
print WRITE "Date:", $date, "\n";
print WRITE "PARAMETERS\n";
print WRITE "Minimum identity =", $identity, "\n";
print WRITE "Minimum length =", $length, "\n";
print WRITE "Diff =", $diff, "\n\n";
if ( $graphic == 1 )
{
open (WRITE, ">>$out.txt"); ## Open the output file
open (WRITE2, ">>lindna.lnp"); ## Open the lindna config file
## start the lindna header
print WRITE2 "start";
print WRITE2 "\t";
print WRITE2 "1";
print WRITE2 "\n";
print WRITE2 "End";
print WRITE2 "\t";
my $seqio_obj = Bio::SeqIO->new(-file => "$library", -format => "fasta" );
my $seq_obj = $seqio_obj->next_seq;
my $count_obj = $seq_obj->length;
print WRITE2 "$count_obj";
print WRITE2 "\n\n";
print WRITE2 "group";
print WRITE2 "\n";
}
else
{
print "No graphic generated \n";
}
## run tfasty36
my $fh;
my $fasta = "tfasty36"; # <------ You can change this line for newest fasta algorithm
my $command = "$fasta $query $library";
open $fh,"$command |" || die("cannot run fasta cmd of $command: $!\n");
my $searchio = Bio::SearchIO->new(-format => 'fasta', -fh => $fh);
print WRITE "Fasta algorithm:", $fasta, "\n\n";
## start the parsing part of the script
while( my $result = $searchio->next_result ) {
## $result is a Bio::Search::Result::ResultI compliant object
while( my $hit = $result->next_hit ) {
## $hit is a Bio::Search::Hit::HitI compliant object
while( my $hsp = $hit->next_hsp ) {
## $hsp is a Bio::Search::HSP::HSPI compliant object
if( $hsp->length('total') > $length ) {
if ( $hsp->percent_identity >= $identity ) {
## Generals informations
print WRITE "Rank=", $hsp->rank, "\n",
"Query=", $result->query_name, "\n",
"Hit=", $hit->name, "\n" ,
"Length=", $hsp->length('total'), "\n",
"Percent_id=", $hsp->percent_identity, "\n",
"Strand=", $hsp->strand('hit'), "\n";
print WRITE "\n";
## Search for nucleotide sequences
print WRITE "\n";
my $start_hit = $hsp->start('hit'), "\n";
my $end_hit = $hsp->end('hit') , "\n";
my $in = Bio::SeqIO->new(-file => "$library" , '-format' => 'fasta');
while ( my $seq = $in->next_seq() ) {#1
## looking for query position
my $start_query = $hsp->start('query'), "\n";
my $end_query = $hsp->end('query') , "\n";
## aa_to_3aa
my $seqobj = Bio::PrimarySeq->new ( -seq => $hsp->query_string);
my $polypeptide_3char = Bio::SeqUtils->seq3($seqobj);
## modify the homology string
my $homo = $hsp->homology_string;
$homo =~ s/:/|||/g;
$homo =~ s/\./***/g;
$homo =~ s/ /XXX/g;
## HSP
print WRITE "Query($start_query,$end_query)\n";
print WRITE "Hit($start_hit,$end_hit)\n\n";
print WRITE $polypeptide_3char, "\n";
print WRITE $homo, "\n";
print WRITE $seq->subseq($start_hit,$end_hit+$diff), "\n";
if ( $graphic == 1)
{ ## if start
## write in lindna file
print WRITE2 "label", "\n", "Block", "\t", "$start_hit", "\t",
"$end_hit", "\t", "3", "\t", "H", "\n";
print WRITE2 "Exon", $hsp->rank, "\n";
print WRITE2 "endlabel";
print WRITE2 "\n\n";
} ## if end
else
{print "No lindna file generated\n";}
} #1
print WRITE "\n";
}
}
}
}
}
if ( $graphic == 1)
{ ## if start
print WRITE2 "endgroup";
system ("lindna -infile lindna.lnp -ruler y -blocktype filled -graphout svg");
system ("rm *.lnp");
} ## if end
} # else end