#!/usr/bin/perl use strict; use warnings; use diagnostics; my $InputFile1 = "edited_archaea_master_list.txt"; open FILE1, $InputFile1 or die "Can't read source file: $InputFile1\n"; my $InputFile2 = "testprefix172_single_line_nostrains_aligned_gaps_test.meg"; open FILE2, $InputFile2 or die "Can't read second source file: $InputFile2\n"; my $OutputFile3 = "rearrangement_out_test.txt"; open FILE3, ">$OutputFile3" or die "Can't open output file: $OutputFile3\n"; print FILE3 "Input #1: $InputFile1\n"; print FILE3 "Input #2: $InputFile2\n\n"; my @species = ; #take file 1 and make into an array my @align = ; #samsies print "array @align\n"; my $limit = @align; #Number of lines read in the array my $species; #used in the foreach loop through @species array ... my $i; my $j; my $FoundFlag; #variable used to store names not found and print out at the end my @notFound; #used to remember species that are not found in order to print at the end ... #loop through master list ... foreach $species(@species) { chomp($species); #deletes the enter character at the end the species, so rather than looking for "species\n", it can just find "species" #print "$species\n"; $FoundFlag = 0; #Scan second file for a match ... for ($i=0; $i<$limit; $i++) #$i is the line number, set to start at zero, $limit is the total number of lines in file, $i++ continues to every consecutive line { chomp($align[$i]); if ($align[$i] =~ /$species/) #if the line in align array matches the line in the species file, then print, and will print to output file { #print "Found ....\n"; print $align[$i]; $j = $i; #$j equals to the species found in the mega file, do then prints the align of $j plus all the lines that follow, until the next # sign. do { print FILE3 "$align[$j]"; $j = $j + 1; } while (($j < $limit) && !($align[$j] =~ /^#/)); #align of j will continue to print until the $limit, which is the end of the file, AND until the next pound sign. $FoundFlag = 1; #if the species is found, then foundflag equals one, meaning its true. last; #quit FOR loop ... and look for the next species } } if ($FoundFlag == 0) { print "I did not find $species\n"; #print FILE3 "I did not find $species\n"; push @notFound, $species; } #print "Next one ...\n"; } #Write not found species ... foreach my $item(@notFound) { print FILE3 "I did not find $item\n"; } close FILE3; print "Done!\n"; exit;