Hi, John 

With the modified script, I got it work, but get some warnings when running 
through one file. 

Use of uninitialized value in numeric ge (>=) at searchAndPrint.pl line 50, 
<FST> line 3417.
Use of uninitialized value in numeric gt (>) at searchAndPrint.pl line 54, 
<FST> line 3417.
Use of uninitialized value in numeric ge (>=) at searchAndPrint.pl line 50, 
<FST> line 3417.
Use of uninitialized value in numeric gt (>) at searchAndPrint.pl line 54, 
<FST> line 3417.
Use of uninitialized value in numeric ge (>=) at searchAndPrint.pl line 50, 
<FST> line 3417.
Use of uninitialized value in numeric gt (>) at searchAndPrint.pl line 54, 
<FST> line 3417.
------ a lot of repetition

Even with the warning, the output file is right, it gives me what I want. 

Could anyone suggest to remove the warnings? The FST file in total has 3416 
line. I donot know why the line 3417 comes from. 

For convenience of debug, my code is as follows:
#!/usr/bin/perl
# USAGE:
# unix command line:
# ./searchAndPrint.pl FstFile.name annotationFile.name 
use strict;
use warnings;

my $FstFile = shift @ARGV;    # read file names from terminal input
my $annotationFile = shift @ARGV; 
open FST, '<', $FstFile or die "Cannot open '$FstFile' because: $!";
open ANNO, '<', $annotationFile or die "Cannot open '$annotationFile' because: 
$!";

my $outfile = "Chr1WithGeneName.txt";
open OUT, '>', $outfile or die "Cannot open '$outfile' because: $!";
print OUT "pos\tObs_Het_BP\tObs_FST\tFST_P_value\tObs_FCT\tFCT_P_value\tgene\n";

my @genename;
my @startSite;
my @stopSite;

while(<ANNO>) {
chomp;
next if /^#/;
my @tmpo=split("\t",$_);
#@tmpo = grep $tmpo[0] eq 'scaffold_1', @tmpo;
#@tmpo = grep $tmpo[2] eq 'gene', @tmpo;
my @data=split(";", $tmpo[8]);
if (($tmpo[0] eq 'scaffold_1') && ($tmpo[2] eq 'gene')){
push(@genename, $data[1]);
push(@startSite, $tmpo[3]);
push(@stopSite, $tmpo[4]);
}
}
#print "@genename\n";
#my $j = $#startSite; # $#arrayname returns the index of the last scalar in the 
array.
#print "$j\n";
#print "$#stopSite\n";
#print "$#genename\n";
#my $k = scalar (@startSite); scalar(@array) returns the total number of 
scalars in that array
#print "$k\n";

while(<FST>) {
next if /^pos/;
chomp;
my @tmp=split("\t",$_);
$tmp[0]=~s/\_/>/g;
my @dat=split(">",$tmp[0]);

for my $i (0..$#startSite) {
if (($dat[2] >= $startSite[$i]) && ($dat[2] <= $stopSite[$i])){
print OUT "$_\t$genename[$i]\n";
last;
}
elsif (($dat[2] > $stopSite[$i]) && ($dat[2]< $startSite[$i+1])){
print OUT "$_\tintergenicRegion\n";
last;
}

}
}

close FST;
close ANNO;
close OUT;


Best regards
Li
________________________________________
From: John W. Krahn [jwkr...@shaw.ca]
Sent: Wednesday, August 29, 2012 4:18 PM
To: Perl Beginners
Subject: Re: how to handle two input files

timothy adigun wrote:
> Hi,

Hello,

> On 8/29/12, timothy adigun<2teezp...@gmail.com>  wrote:
>
>>> for(my $i=0; $i<= length(@startSite)-1; $i++) {
>>
>>    The above could be:
>>      for(my $i=0; $i<= scalar (@startSite); $i++) {
>>        ...
>
> for(my $i=0; $i<= scalar (@startSite); $i++) {  ## Oops
>
> for(my $i=0; $i<= scalar (@startSite)-1; $i++) {  ## working

First, length(@startSite) is WRONG so s/could/should/ and second, that
is usually written as:

for my $i ( 0.. $#startSite ) {




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to