match sequence

B

BD

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
KKKKKKKKLLLLLLLLLMMMMMM
MMMMMMNNNNNNNOOOOOOOOOOOOO
OPPPPPPPPPPPPPPRRRRRSSSSSS
seq3
DDDDDFGDSDSDRTGDGDGDGDH
SHFFHGLFHDFHBVVBBVJGFJGDKG
HDSFHLIHFL
and second Inputfile like
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
 
X

xhoster

BD said:
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
 
B

BD

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
 
X

xhoster

BD said:
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
 
B

BD

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top