# perl /media/xiangyang/Acinetobacter_baumannii/filter.pl

use strict;
use warnings;

my $tsv = "/media/xiangyang/Acinetobacter_baumannii/kaptive_results_low.tsv";
open(CSV, $tsv);

my $ntsv = "/media/xiangyang/Acinetobacter_baumannii/kaptive_results_low_filtered.tsv";
open(NCSV, ">$ntsv");


my $glist = "/media/xiangyang/Acinetobacter_baumannii/low_genome_folder.record.seq";

my %glist;
open(G, $glist);
while(<G>){
    chomp;
    next unless $_ !~ /^#/;
    $glist{$_} = $_;
}
close G;

my %n;
while(<CSV>){
    chomp;
    my @a = split /\t/, $_;
    next unless $a[0] !~ /WARNING/;
    print NCSV "$_\n";
    $n{$a[0]}++;
}
close CSV;
close NCSV;

print scalar keys %n, "\n";
print scalar keys %glist, "\n";
mkdir "/media/xiangyang/Acinetobacter_baumannii/lsup";
foreach(keys %glist){
    system("cp /media/xiangyang/Acinetobacter_baumannii/G_SEQ/$_.fasta -t /media/xiangyang/Acinetobacter_baumannii/lsup") if !defined $n{$_};
}
