#!/usr/bin/perl

use strict;
use warnings;

# check for arguments and explain usage
if ($#ARGV !=1) {
	print "usage: copy_sqltables_subset.pl species_list_file output_dir\n";
	exit;
}

my $speciesfile = $ARGV[0];
my $outdir = $ARGV[1];

my @speciesarray;
open (SPECIESFILE, $speciesfile);
while(<SPECIESFILE>) {
		my $line = $_;
		chomp $line;
		
		push (@speciesarray, $line);
}
close(SPECIESFILE);

# Get list of files in input dir
my @file_list = glob("sqltable*");

for (my $i = 0; $i < scalar @speciesarray; $i++) {
		for (my $j = $i + 1; $j < scalar @speciesarray; $j++) {
				foreach my $file (@file_list) {
						if($file =~ m/$speciesarray[$i]/ && $file =~ m/$speciesarray[$j]/ ) {
								system("cp $file $outdir/$file");
						}
				}
		}
}
