#!/usr/bin/perl -w

# usage : perl sm_samtools_merge.pl <output TXT file> <BAM file 1> <BAM file 2> 
use strict;
use File::Basename;

my $output_all_bam = $ARGV[0];
my $inputs = @ARGV[1..$#ARGV];
my $SAMTOOLS = '/usr/local/bioinfo/bin/samtools';
my $cmd = '';
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $ALLbam = $mday."-".($mon+1)."_".$hour."h".$min."mn".$sec."sec_accepted_hits_all.bam";



#commande : perl sm_samtools_merge.pl tests/accepted_hits_all.bam tests/accepted_hits_ERR022488_refchr22.bam tests/accepted_hits_ERR022486_refchr22.bam  
#Samtools merge accepted_hits_all.bam accepted_hits_ERR022486.bam accepted_hits_ERR022488.bam
#Samtools merge accepted_hits_all.bam accepted_hits_ERR022488_refchr22.bam accepted_hits_ERR022486_refchr22.bam
$cmd = "($SAMTOOLS merge $ALLbam @ARGV[1..$#ARGV] ) >& ./samtoolsmerge.log 2>&1";
#Info pour les biologistes
print STDOUT "Samtools merge : \n\n $cmd \n\n ";
system $cmd;


if (! -e "$ALLbam")
{
print STDERR "all bam file not found. \n";
}
else
{
`cp -a $ALLbam $output_all_bam`;
}


