I can't tell because I don't know what the lines you are dealing with look like. I can only help with overall structure and technique. On the face of it the handling looks OK, but it does depend very much on the content of the first two fields on each line. Can the letter case of the contents be different or can numeric representation be different between the fields for example?

I've applied the changes I suggested in my reply along with a few others to give:

#!/usr/bin/perl use strict; use warnings; sub iterblast { # settings my $myblast = "blastall -p blastn -m 8"; my $starterseq = "/share/home/tjuh/Thema12-2011/Project/testblast/matchedhits.f +asta"; my $blastdb = "/share/home/tjuh/Thema12-2011/Project/databases/termite_hindg +ut/hindgut_db"; my $outputroot = "/share/home/tjuh/Thema12-2011/Project/testblast/ +test1"; my $evalue = 0.01; my $wordsize = 11; my $roundlimit = 4; # output files: my $seq_db_fasta = $outputroot . ".tmp"; my $seq_db_all = $outputroot . ".all"; my $logfile = $outputroot . ".log"; # remove existing files unlink $seq_db_fasta; unlink $seq_db_all; unlink $logfile; open my $log, '>', $logfile or die "Can't open $logfile: $!\n"; print $log <<LOGMSG; Configurations: Input file : $starterseq Output files : $outputroot\- Blast Engine : $myblast Target database : $blastdb E-value cut-off : $evalue Blast word size : $wordsize Blast round limit: $roundlimit Runs: LOGMSG # hits hash my %hits; my %queryids; # Start the iterative blastn rounds for my $round (1 .. $roundlimit) { my $saveblst = $outputroot . ".txt"; unlink $saveblst; # print $log info my $curtime = localtime(); my $infile = $round == 1 ? $starterseq : $seq_db_fasta; print $log "$curtime - Blast seq: $infile\n"; print $log "$curtime - Blast db : $blastdb\n"; # run blast system( "$myblast -i $infile -d $blastdb -o $saveblst -e $evalue - +W $wordsize" ); open my $parse, '<', $saveblst or die "Can't open $saveblst: $ +!\n"; open my $fasta, '>', $seq_db_fasta or die "Can't create $seq_db_fasta: $!\n"; # parse blast output (tab form) and add matched id's in hits h +ash while (defined (my $line = <$parse>)) { chomp $line; my @fields = split(/\t/, $line); ++$queryids{$fields[0]}; ++$hits{$fields[1]}; } # get header and sequence with 'fastacmd' and write to new fas +ta file my $hitcount; while (my $key = each %hits) { next if exists $queryids{$key}; # only write uniq ids to file system("fastacmd -d $blastdb -s 'lcl|$key' >> $seq_db_fast +a"); $hitcount++; } close $fasta; close $parse; if ($hitcount) { print $log "Round $round has $hitcount unique hits\n\n"; next; } print $log "No hits in Round $round ==> STOP\n"; last; } print "Total uniq hits found in all rounds: ", scalar keys %hits, +"\n"; close($log); }

Note that I've eliminated system calls to delete files and get the date and replaced them with the equivalent Perl functions! So far as I can see there are no changes in the logic of the code, but to my mind it is somewhat cleaner.

True laziness is hard work

In reply to Re^3: Iterative BLAST(N) program by GrandFather
in thread Iterative BLAST(N) program by Tjuh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.