Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > match sequence

Reply
Thread Tools

match sequence

 
 
BD
Guest
Posts: n/a
 
      05-09-2006
Hi All, I allredy asked this type of question in some thread before but
I am trying that same Program in another way, But I am not getting
output what I want...

I am trying to make program that has First Input file like
>seq1

AAAAAAAAAAABBBBBBBBBBCCCCCCC
CCCCCCCCCCCCDDDDDDDD
DDDDDDDDEEEEEEEFFFFFFFFFFFFFFF
>seq2

KKKKKKKKLLLLLLLLLMMMMMM
MMMMMMNNNNNNNOOOOOOOOOOOOO
OPPPPPPPPPPPPPPRRRRRSSSSSS
>seq3

DDDDDFGDSDSDRTGDGDGDGDH
SHFFHGLFHDFHBVVBBVJGFJGDKG
HDSFHLIHFL
and second Inputfile like
>seq1

KKKKKKKKLLLLLLLLLMMMMMMMMMMMMNNNNNNNOOOOOOOOOOOOOO
PPPPPPPPPPPPPPRRRRRSSSSSS
now I wrote a script which take data from second Input file and match

motif with First Input file and where it match print that header
Like here it match at second Sequence so in Output it should print
seq2
here is my code :

use warnings;
use strict;
my $header;
my $seq;

my $filename ='file1.txt' ;
open my $file1,'<',$filename or die "Cannot open file $filename \n $!";
$/='>';
$,="\t",$\="\n";
while(<$file1>){
chomp;
next unless length $_;
($header,$seq)=split"\n",$_,2;
$seq =~s/\n//g;
print $header,$seq;
}
close $file1;
my $Input='file2.txt ' ;
open my $file2,'<',$Input or die "Cannot open file $Input \n $!";
<$file2>;
my $motif = <$file2>;
chomp $motif;
print "Motif- $motif";
if ($seq=$motif){
print "\nI Found It ! $header\n\n";
}
close $file2;
I am getting output frome this script that

I Found It ! >seq3

whatever will be last Header,it will print ,though I want that in
which sequence it will found motif,it should print that header.
help will be appriciate.
Thanks

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      05-09-2006
"BD" <> wrote:

> use warnings;
> use strict;
> my $header;
> my $seq;
>
> my $filename ='file1.txt' ;
> open my $file1,'<',$filename or die "Cannot open file $filename \n $!";
> $/='>';
> $,="\t",$\="\n";
> while(<$file1>){
> chomp;
> next unless length $_;
> ($header,$seq)=split"\n",$_,2;
> $seq =~s/\n//g;
> print $header,$seq;
> }


You are not saving any values other than the last one, so how could
you expect anything other than those last values to be printed.
In the loop, you need to do something like this:
$hash{$seq}=$header;


> close $file1;
> my $Input='file2.txt ' ;
> open my $file2,'<',$Input or die "Cannot open file $Input \n $!";
> <$file2>;
> my $motif = <$file2>;
> chomp $motif;
> print "Motif- $motif";


You need to split and s/// the motif the same way you do the file1.txt

> if ($seq=$motif){


That is not a test, that is an assignment. It will be true as long
as $motif holds a true value, regardless of what $seq (used to) have.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
BD
Guest
Posts: n/a
 
      05-09-2006
All right,I changed my script but it is giving me some warnings,and I
check that too ,everything is fine so should I Ignore that warnings?
use warnings;
use strict;
my $header;
my $header1;
my $seq;
my $seq1;
my %hash;
$/='>';
$,="\t",$\="\n";
my $filename ='file1.txt';
open my $file1,'<',$filename or die "Cannot open file $filename \n $!";
while(<$file1>){
chomp;
next unless length $_;
($header,$seq)=split"\n",$_,2;
$seq =~s/\n//g;
#print $header,$seq;
$hash{$seq}=$header;
}
close $file1;
my $Input='file2.txt';
open my $file2,'<',$Input or die "Cannot open file $Input \n $!";
while( <$file2>){
chomp ;
($header1,$seq1)=split"\n",$_,2;
$seq1 =~s/\n//g;
#print $header1,$seq1;
print $hash{$seq1};
}
close $file2;

Warnings are
Use of uninitialized value in substitution (s///) at file1.pl line 26,
<$file2> chunk 1.
Use of uninitialized value in hash element at file1.pl line 28,
<$file2> chunk 1.
Use of uninitialized value in print at file1.pl line 28, <$file2> chunk
1.

Here it is considering that $seq1 has no value ,but it is giving output
too.
and Is there any way that along the output I can print the header no.
too in this case it will print 2.
Thanks

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      05-09-2006
"BD" <> wrote:
> All right,I changed my script but it is giving me some warnings,and I
> check that too ,everything is fine so should I Ignore that warnings?


No, don't ignore the warnings.

> while( <$file2>){
> chomp ;
> ($header1,$seq1)=split"\n",$_,2;
> $seq1 =~s/\n//g;
> #print $header1,$seq1;
> print $hash{$seq1};
> }
> close $file2;


Please indent your code for readability. Also, you should
declare $header1 and $seq1 here, rather than up top.

>
> Warnings are
> Use of uninitialized value in substitution (s///) at file1.pl line 26,
> <$file2> chunk 1.
> Use of uninitialized value in hash element at file1.pl line 28,
> <$file2> chunk 1.
> Use of uninitialized value in print at file1.pl line 28, <$file2> chunk
> 1.
>
> Here it is considering that $seq1 has no value ,but it is giving output
> too.


You are in a loop. One time though the loop it is undefined. Another
time through the loop it does have a value. Note that your first loop
has a "next unless length $_;" which your second loop doesn't have.

When trying to warnings from inside loops, it is often useful to add a
'warn "Starting loop";' at the start and a 'warn "Ending loop";' at the
end. Then you will know which iteration is producing which warning.

> and Is there any way that along the output I can print the header no.
> too in this case it will print 2.


Since the header number is already embedded in the header, I fail to see
the point of that. But it is easy to do, in a variety of ways.

$hash{$seq}=(1+keys %hash) . ": $header";

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
BD
Guest
Posts: n/a
 
      05-09-2006
> Since the header number is already embedded in the header, I fail to see
> the point of that. But it is easy to do, in a variety of ways.
>
> $hash{$seq}=(1+keys %hash) . ": $header";


How this line works ?

Actually what I am trying to do with this programm .
I am matching the sequences of two files .one file has 1 or more than 1
sequence and second file has only one sequence so wherever it will
match ,I am trying to make sequence Id according to that .
in this case sequence Id was 01011 but than it will be 01011-2.
so i want some variable which has header no. so i can put like
$seqid.'-'.$header_no

Thanks

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to iterate over sequence and non-sequence ? stef mientki Python 13 10-20-2007 10:21 AM
Match First Sequence in Regular Expression? Roger L. Cauvin Python 43 01-28-2006 03:39 PM
Regular expression don't match sequence of characters Big Tony Perl Misc 2 09-27-2004 01:43 PM
Java regex can't match lengthy match? hiwa Java 0 01-29-2004 10:09 AM
BOOT SEQUENCE (how to change boot sequence) bird Computer Support 13 12-24-2003 02:20 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57