For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2006 > Print header if motif match?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Print header if motif match?
BD

2006-05-01, 6:58 pm

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

AAAAAAAAAAABBBBBBBBBBCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDEEEEEEEFFFFFFFFFFFFFFF[c
olor=darkred]
>seq2[/color]
KKKKKKKKLLLLLLLLLMMMMMMMMMMMMNNNNNNNOOOO
OOOOOOOOOOPPPPPPPPPPPPPPRRRRRSSSSSS
and second Inputfile like
>seq1

KKKKKKKKLLLLLLLLLMMMMMMMMMMMMNNNNNNNOOOO
OOOOOOOOOOPPPPPPPPPPPPPPRRRRRSSSSSS
now I wrote a script which take data from second Input file and match
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 $filename ='file1';
open FILE1,$filename or die "Cannot open file $filename \n $!";
my @data = <FILE1>;
my $Data = join('',@data);
$Data =~ s/\s//g;
my $Input='file2';
open FILE2,$Input or die "Cannot open file $Input \n $!";
<FILE2>;
my @motif = <FILE2>;
my $Motif= join('',@motif);
$Motif =~ s/\s//g;
if ($Data =~ /$Motif/ ){
print "$&\n";
}
How I can print the header ,where motif match ?

BD

2006-05-02, 6:58 pm


BD wrote:
> I am trying to make program that has First Input file like
> AAAAAAAAAAABBBBBBBBBBCCCCCCCCCCCCCCCCCCC
DDDDDDDD

DDDDDDDDEEEEEEEFFFFFFFFFFFFFFF
> KKKKKKKKLLLLLLLLLMMMMMMMMMMMMNNNNNNNOOOO
OOOOOOOOO

OPPPPPPPPPPPPPPRRRRRSSSSSS
> and second Inputfile like
> KKKKKKKKLLLLLLLLLMMMMMMMMMMMMNNNNNNNOOOO
OOOOOOOOOO

PPPPPPPPPPPPPPRRRRRSSSSSS

> now I wrote a script which take data from second Input file and match
> 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 $filename ='file1';
> open FILE1,$filename or die "Cannot open file $filename \n $!";
> my @data = <FILE1>;
> my $Data = join('',@data);
> $Data =~ s/\s//g;
> my $Input='file2';
> open FILE2,$Input or die "Cannot open file $Input \n $!";
> <FILE2>;
> my @motif = <FILE2>;
> my $Motif= join('',@motif);
> $Motif =~ s/\s//g;
> if ($Data =~ /$Motif/ ){
> print "$&\n";
> }
> How I can print the header ,where motif match ?



All right I tried following script-
But it is giving me output that "I couldnt find it."
though I am trying to get Seq2

use warnings;
use strict;
my $filename ='file1.txt';
open FILE1,$filename or die "Cannot open file $filename \n $!";
my @seq=<FILE1>;
my $header=' ';
my $Seq=' ' ;
my $i=0;
my (@Header,@Sequence);
foreach my $line (@seq){
chomp $line;
if ($line =~ /^>/){
$i++;
$Header[$i]=$header.$line;
}else{
$Sequence[$i]=$Seq.$line;
}
}
my $Input='file2.txt';
open FILE2,$Input or die "Cannot open file $Input \n $!";
<FILE2>;
my $motif = <FILE2>;
if ($Sequence[$i] =~ /$motif/ ){
print "$Header[$i] I Found it!\n";
}
else{
print "I couldnot found it.\n";
print $i,"\n";
}

Is anybody can help me to get Output or debugging my Code?
I will really appreciate.
Thanks.

BD

2006-05-02, 6:59 pm


should I use flag for header?
Thanks

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com