#!/usr/local/bin/perl #use strict; use warnings; use Errno; use lib " /RemotePerl"; use lib " /System/Library/Perl/5.8.6"; use lib " /Library/Perl/5.8.6"; use Bio::Perl; use Bio::SeqIO; use IO::String; use Bio::SearchIO; if (@ARGV < 2) { die "usage: compare.pl \n"; } $file1 = $ARGV[0]; $file2 = $ARGV[1]; #Read in first fasta file $FastaFile1 = Bio::SeqIO->new(-file => $ARGV[0], -format => 'fasta'); print "File name of the first fasta file is: ".$file1."\n"; #Create array of the fasta sequences from file 1 my @fasta_objs =(); #Add sequences of file1 to array called fasta_objs while (my $seqFile1 = $FastaFile1->next_seq() ) { push @fasta_objs,$seqFile1->seq; } #Read in second fasta file $FastaFile2 = Bio::SeqIO->new(-file => $ARGV[1], -format => 'fasta'); print "File name of the first fasta file is: ".$file2."\n"; #Setup output file: sequences from File2 which match sequences of File1 my $fasta = Bio::SeqIO->new(-file => ">EQUAL_HITS.fasta", -format => "fasta", -flush => 0); # write matching sequences of file2 to the output file # Note that if several matches to one sequence exist, ALL matches are output to the file while(my $seqFile2 = $FastaFile2->next_seq() ) { $fasta->write_seq($seqFile2) if (grep {$_ eq $seqFile2->seq} @fasta_objs); } print "Comparison is complete! \n";