Hi Wang, Li,

Please, check my comments below.

On 8/29/12, Wang, Li <li.w...@ttu.edu> wrote:
> Dear All
>
> I have two input files. I want to search an element of File1 in File 2. If
> the condition matched, print out something.
> File1:
> scaffold_1_541600     0.856102487445412       0.295040551475357       
> 0.795878312070658       312
>
> The element used to search is 541600,
>
> File2:
> scaffold_1    phytozome8_0    gene    540839  544291  .       -
> ID=POPTR_0001s00630;Name=POPTR_0001s00630
>
> If 541600 is between the four and five elements of File2 (between 540839 and
> 544291), print out the line in File 1 and followed by genename (the last
> element of file 2).
>
> My script is as follows. And usage is: ./myscript.pl FstFile.txt
> annotationFile.txt
>
> # USAGE:
> # unix command line:
> # ./searchAndPrint.pl FstFile.name annotationFile.name
>
> #!/usr/bin/perl -w
> use strict;
> use warnings;

 Since you have "use warnings", there is not need for the "-w" at the
first line.

>
> my $FstFile = shift @ARGV;    # read file names from terminal input
> my $annotationFile = shift @ARGV;

  The above could better be written like so:

    my($FstFile,$annotationFile) = @ARGV;

>
> open FST, '<', $FstFile or die "Cannot open '$FstFile' because: $!";
> open ANNO, '<', $annotationFile or die "Cannot open '$annotationFile'
> because: $!";
>
> my $outfile = "criticalFstChr1WithGeneName.txt";
> open OUT, '>', $outfile or die "Cannot open '$outfile' because: $!";
> print OUT "pos\tFit\tFst\tFis\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;
> if (($tmpo[0] eq 'scaffold_1') && ($tmpo[2] eq 'gene')){
> push(@genename, $tmpo[8]);
> push(@startSite, $tmpo[3]);
> push(@stopSite, $tmpo[4]);
> }
> }
>
> while(<FST>) {
> next if /^Fit/;
> chomp;
> my @tmp=split("\t",$_);
> $tmp[0]=~s/\_/>/g;
> my @dat=split(">",$tmp[0]);

> for(my $i=0; $i <= length(@startSite)-1; $i++) {

  The above could be:
    for(my $i=0; $i <= scalar (@startSite); $i++) {
      ...

Hope this helps
-- 
Tim

-- 
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