Captainrave
Technical User
My code is below...it reads in two files, it compares the values in these files and outputs a new file where the new values are stored. However everytime I need it i have to change the file name each time, so basically I read in
INPUT 1 - EN638_CDS_LOCATION.xls (stays the same each time)
Input 2 - EN638_REPEAT_LOCATION5x.csv
EN638_REPEAT_LOCATION6x.csv
EN638_REPEAT_LOCATION7x.csv
EN638_REPEAT_LOCATION8x.csv all the way to 20x
Each corresponding output also has to be changed in the same way, 5x to 20x. Is there a way to automate this process rather than me changing the names EVERYtime?
INPUT 1 - EN638_CDS_LOCATION.xls (stays the same each time)
Input 2 - EN638_REPEAT_LOCATION5x.csv
EN638_REPEAT_LOCATION6x.csv
EN638_REPEAT_LOCATION7x.csv
EN638_REPEAT_LOCATION8x.csv all the way to 20x
Each corresponding output also has to be changed in the same way, 5x to 20x. Is there a way to automate this process rather than me changing the names EVERYtime?
Code:
use strict;
use warnings;
open(OUTPUT,"+>EN638_REPEAT_DISTRIBUTION20x.csv");
open BIG, 'D:\Genome Sequence Output\EN638\EN638_CDS_LOCATION.xls' or die "$!";
my @big = map {[split/\s+/]} <BIG>;
close BIG;
open SMA, 'D:\Genome Sequence Output\EN638\EN638_REPEAT_LOCATION20x.csv' or die "$!";
LOOP: while (<SMA>) {
my ($s,$e) = split(/\,/);
foreach my $array (@big) {
if ($s >= $array->[0] && $e <= $array->[1]) {
calculate($s,$e,$array->[0],$array->[1],$.);
next LOOP;
}
}
}
close SMA;
close OUTPUT;
exit;
sub calculate {
my ($small_start, $small_end, $big_start, $big_end, $line_num) = @_;
my $calculation = ( ( ($big_start/$big_end) / ($small_start/$small_end) ) * 100 );
print OUTPUT "small_start,$small_end,$big_start,$big_end,$calculation,/n";
}