#!/usr/bin/perl use strict; use warnings; chdir "c:/perl/sam" or die "can't chdir to c:/perl/sam: $!"; # get the user-specified sequence file, library file # and cut-off percentage my ( $seqfile, $libfile, $cutoff ) = @ARGV; die "Usage: $0 seq.file lib.file cutoff\n" unless ( @ARGV == 3 and -f $seqfile and -f $libfile and $cutoff =~ /^\d+\.?\d*$/ ); # run fasta34.exe with the sequence file and library file my $main = "main.fasta"; my $result = system("fasta34.exe -O $main -Q $seqfile $library"); if ($result >> 8) { warn "fasta34.exe ended with non-zero exit status \n"; } # open the file that was output by fasta34 open(FASTA,"$main") or die "cant open fasta34 output file: $!"; $/ = '>>'; # set INPUT_RECORD_SEPARATOR to ">>" while () { chomp; # this removes ">>" from the end of the string next if ( /^\s*$/ ); # skip the first read (update: decided not to test length()) ($per) = /(\d+\.\d+)% identity/; push @org, ">>$_"; push @input, ">>$_" if ($per > $cutoff); } close FASTA; # if you want to save @input and/or @org to a file and run fasta34 again: open OUT, ">nextinput.fasta" or die $!; print OUT join '', @input; close OUT; # and likewise for @org