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; 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 = "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++) { if (($dat[2] >= $startSite[$i]) && ($dat[2] <= $stopSite[$i])){ print OUT "$tmp[0]\t$tmp[1]\t$tmp[2]\t$tmp[3]\t$genename[$i]\n"; last; } elsif (($dat[2] > $stopSite[$i]) && ($dat[2]< $startSite[$i+1])){ print OUT "$tmp[0]\t$tmp[1]\t$tmp[2]\t$tmp[3]\t'intergenicRegion'\n"; last; } } } close FST; close ANNO; close OUT; But I got errors as follows: ./searchAndPrint.pl: line 6: use: command not found ./searchAndPrint.pl: line 7: use: command not found ./searchAndPrint.pl: line 9: my: command not found ./searchAndPrint.pl: line 10: my: command not found The files /FST,, Cannot open '' because: do not exist. The files /ANNO Cannot open '' because: do not exist. ./searchAndPrint.pl: line 16: my: command not found The files /OUT Cannot open '' because: do not exist. ./searchAndPrint.pl: line 18: print: command not found ./searchAndPrint.pl: line 20: my: command not found ./searchAndPrint.pl: line 21: my: command not found ./searchAndPrint.pl: line 22: my: command not found ./searchAndPrint.pl: line 24: syntax error near unexpected token `)' ./searchAndPrint.pl: line 24: `while(<ANNO>) {' It seems it doesnot recognize Perl. I feel very confused. I got some help for the previously posted questions on the list and it helps me improve a lot! Thank you guys! All the best Li -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/