#!/usr/bin/perl -w
# Combine Illumina lanes by adding up read depth at each base position

use strict;

print ("This script will add together the number of insert sites present at each base\n");

print ("Please enter the first .plot file to be processed:\n");
my $infile = <STDIN>;
chomp $infile;

print ("Please enter the second .plot file to be processed:\n");
my $infile2 = <STDIN>;
chomp $infile2;

print ("Please enter a prefix for the output file:\n");
my $tag = <STDIN>;
chomp $tag;

open (INFILE, "<$infile") or die ("Couldn't open $infile:$!\n");
my @array = <INFILE>;
close INFILE;

my $outfile = "$tag\.plot";
open (OUTFILE, ">$outfile") or die ("Couldn't open $outfile:$!\n");

my $i = 0;

open (INFILETWO, "<$infile2") or die ("Couldn't open $infile2:$!\n");
while (<INFILETWO>){
chomp;

	my $total = $_ + $array[$i]; #print ("$_ + $array[$i]"); <STDIN>;
   print (OUTFILE "$total\n"); #<STDIN>;
   
   $i++;
}
close INFILETWO;close OUTFILE;

print ("Finished combining files. Saved as $outfile\n");
