#!/usr/bin/perl
use strict;
use warnings;
open( FILE1, '<', 'File1' );
open( FILE2, '<', 'File2' );
open( OUTPUT, '>>', 'Output' );
my %hash1;
my %hash2;
my %hash3;
while ( my $line1 = <FILE1> ) # Recorro el primer archivo
{
chomp $line1;
my @linea = split( /\t/, $line1 );
my $PC15 = $linea[0];
my $PC9 = $linea[1];
my $seqPC15 = $linea[2];
my $seqPC9 = $linea[3];
my $scaffoldPC15 = $linea[6];
my $startPC15 = $linea[7];
my $endPC15 = $linea[8];
my $sensePC15 = $linea[9];
my $scaffoldPC9 = $linea[11];
my $startPC9 = $linea[12];
my $endPC9 = $linea[13];
my $sensePC9 = $linea[14];
my @array = (
$PC9, $seqPC15, $seqPC9, $scaffoldPC15, $startPC15, $endPC15,
$sensePC15, $scaffoldPC9, $startPC9, $endPC9, $sensePC9
);
$hash1{$PC15} = [@array]; # y creo mi primer hash
}
while ( my $line2 = <FILE2> ) # Recorro el segundo archivo
{
chomp $line2;
my @linea2 = split( /\t/, $line2 );
my $lect = $linea2[0];
my $scaffoldlect = $linea2[2];
my $poslect = $linea2[3];
my $cigar = $linea2[5];
my $seqlect = $linea2[9];
my @array2 = ( $lect, $scaffoldlect, $poslect, $cigar, $seqlect );
$hash2{$lect} = [@array2]; # Creo el segundo hash
}
while ( ( my $IDPC15, my $valor ) = each %hash1 ) # Recorro el primer hash
{
my $PC9 = $hash1{$IDPC15}[0];
my $seqPC15 = $hash1{$IDPC15}[1];
my $seqPC9 = $hash1{$IDPC15}[2];
my $scaffoldPC15 = $hash1{$IDPC15}[3];
my $startPC15 = $hash1{$IDPC15}[4];
my $endPC15 = $hash1{$IDPC15}[5];
my $sensePC15 = $hash1{$IDPC15}[6];
my $scaffoldPC9 = $hash1{$IDPC15}[7];
my $startPC9 = $hash1{$IDPC15}[8];
my $endPC9 = $hash1{$IDPC15}[9];
my $sensePC9 = $hash1{$IDPC15}[10];
my $vecesPC15 = 0;
my $vecesPC9 = 0;
while ( ( my $llave, my $valor2 ) = each %hash2 ) # Doble bucle sobre el segundo hash
{
my $lect = $hash2{$llave}[0];
my $scaffoldlect = $hash2{$llave}[1];
my $poslect = $hash2{$llave}[2];
my $cigar = $hash2{$llave}[3];
my $seqlect = $hash2{$llave}[4];
if ( ( $scaffoldPC15 eq $scaffoldlect )
and ( $startPC15 < $poslect )
and ( $endPC15 > ( $poslect + 50 ) )
and ( $seqPC15 =~ $seqlect )
and ( $seqPC9 !~ $seqlect ) ) {
$vecesPC15++;
my @nuevoarray3 = (
$PC9, $seqPC15, $seqPC9, $scaffoldPC15, $startPC15, $endPC15, $sensePC15,
$scaffoldPC9, $startPC9, $endPC9, $sensePC9, $vecesPC15, $vecesPC9
);
delete $hash3{$IDPC15};
$hash3{$IDPC15} = [@nuevoarray3];
}
elsif ( ( $scaffoldPC15 eq $scaffoldlect )
and ( $startPC15 < $poslect )
and ( $endPC15 > ( $poslect + 50 ) )
and ( $seqPC9 =~ $seqlect )
and ( $seqPC15 !~ $seqlect ) ) {
$vecesPC9++;
my @nuevoarray3 = (
$PC9, $seqPC15, $seqPC9, $scaffoldPC15, $startPC15, $endPC15, $sensePC15,
$scaffoldPC9, $startPC9, $endPC9, $sensePC9, $vecesPC15, $vecesPC9
);
delete $hash3{$IDPC15};
$hash3{$IDPC15} = [@nuevoarray3];
}
else {
my @nuevoarray3 = (
$PC9, $seqPC15, $seqPC9, $scaffoldPC15, $startPC15, $endPC15, $sensePC15,
$scaffoldPC9, $startPC9, $endPC9, $sensePC9, $vecesPC15, $vecesPC9
);
delete $hash3{$IDPC15};
$hash3{$IDPC15} = [@nuevoarray3];
}
}
}
while ( ( my $IDPC15, my $valor ) = each %hash3 ) {
print OUTPUT
"$IDPC15\t$hash3{$IDPC15}[0]\t$hash3{$IDPC15}[1]\t$hash3{$IDPC15}[2]\t$hash3{$IDPC15}[3]\t$hash3{$IDPC15}[4]\t$hash3{$IDPC15}[5]\t$hash3{$IDPC15}[6]\t$hash3{$IDPC15}[7]\t$hash3{$IDPC15}[8]\t$hash3{$IDPC15}[9]\t$hash3{$IDPC15}[10]\t$hash3{$IDPC15}[11]\t$hash3{$IDPC15}[12]\n";
}
close(FILE1);
close(FILE2);
close(OUTPUT);
END;