# Giant Virus Finder, a software package to find giant viruses in metagenomes.
# Copyright (C) 2015, Csaba Kerepesi

# This file is part of Giant Virus Finder.

# Giant Virus Finder is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details: <http://www.gnu.org/licenses/>.

# For any other inquiries send an Email to Csaba Kerepesi: kerepesi@caesar.elte.hu
# Giant Virus Finder website: http://pitgroup.org/giant-virus-finder

# $ARGV[0]: target dir
# -in: single sequence input
# -out: out dir
# Run: perl Phase2Blast.pl -out Giants-in-16Soil-megablast-2

my %args=();
my @mgmList=();
for ($i=0; $i<@ARGV; $i+=2) {
    $args{$ARGV[$i]} = $ARGV[$i+1];
}
if (exists $args{'-in'}) {
    push @mgmList,$args{'-in'};
}else {
    open (IN, "mgm.list") || die "Can't open mgm.list";
    while (<IN>) {
        chomp;
        push @mgmList,$_;
    }
    close IN;
}
foreach my $keymgm (@mgmList) {
    $time=localtime();
    print "$time, start: $args{'-out'}/phase2-results/reblast-$keymgm.blast\n"; 
    system("~/ncbi-blast-2.2.30+/bin/blastn -task blastn -word_size 7 -evalue 0.01 -query $args{'-out'}/phase1-results/Candidates-in-$keymgm -db ~/ncbi-blast-2.2.30+/db/nt -out $args{'-out'}/phase2-results/reblast-$keymgm.blast");
    $time=localtime();
    print "$time, end: $args{'-out'}/phase2-results/reblast-$keymgm.blast\n";
}
