#!/usr/bin/perl
use Parallel::ForkManager;
# inicializa el paralelizador a 8 procesos
my $pm = new Parallel::ForkManager(8);

#1j2xA00 1wq2B00 1.10.10.10 1.10.10.10 d1j2xa_ d1wq2b1 a.4.5.30 a.4.5.45
#1j2xA00 2aduA02 1.10.10.10 1.10.10.10 d1j2xa_ d2adua1 a.4.5.30 a.4.5.25

open(LIST,$ARGV[0]);
@x=<LIST>;
close(LIST);
$size=$#x+1;

for ($i=0;$i<$size;$i++) {
   @names=split(/\s/,$x[$i]);
   $prot1=$names[4];
    $dir1 = substr($prot1,2,2);

   $prot2=$names[5];
    $dir2 = substr($prot2,2,2);

    # inicializa cada proceso a paralelizar
    $pm -> start and next;
  $X=`../TMalign/TMalign /mnt/disk/public/SCOP1.7/pdbstyle-1.73/$dir1/$prot1.ent /mnt/disk/public/SCOP1.7/pdbstyle-1.73/$dir2/$prot2.ent -o $prot1-$prot2.tm0 | fgrep RMSD`;
   @line=split(/[\s=,]+/,$X);

 system("perl ../TMalign/GetAlignment.pl $prot1-$prot2.tm0 > $prot1-$prot2.tm");
  $Y=`./ProtDeform P -A ../ScoreTest/bssp/$prot1.bssp -B ../ScoreTest/bssp/$prot2.bssp -O - -ia $prot1-$prot2.tm | tail -1`;
   @lineY=split(/[\s=,]+/,$Y);
  system("echo $prot1 $prot2 $line[6] $lineY[3] >> ../TMalign/RESPlos/GSTMresPD");

  system("/bin/rm $prot1-$prot2.*");
    # finaliza cada proceso a finalizar
    $pm -> finish;
}

# espera a que hayan acabado todos
$pm -> wait_all_children; 


