Hi everyone,
I forgot to mention that I did open the output files earlier in the
program, ie CHR1, CHR3 ... CHR5.
Here is the whole thing:
#!usr/bin/perl -w
use strict;
my ($input,$output,$k,$v,$gene, $input_string,
$output1,$output2,$output3,$output4,$output5,
$file, $junk,$i,
@temp_list,
%all_genes);
#open a new text file
$output1 = ">../perl_output/AtChr1.txt";
open (CHR1, "$output1") or die "Could not open $output1.$!";
$output2 = ">../perl_output/AtChr2.txt";
open (CHR2, "$output2") or die "Could not open $output2.$!";
$output3 = ">../perl_output/AtChr3.txt";
open (CHR3, "$output3") or die "Could not open $output3.$!";
$output4 = ">../perl_output/AtChr4.txt";
open (CHR4, "$output4") or die "Could not open $output4.$!";
$output5 = ">../perl_output/AtChr5.txt";
open (CHR5, "$output5") or die "Could not open $output5.$!";
#open "AtIntergenicTable.txt"
$input = "<../perl_output/AtIntergenicTable.txt";
open (INPUT, "$input") or die "Could not open $input.$!";
#read it into memory
while (<INPUT>) {
next if (/>/);
$input_string .= $_}
close (INPUT);
#split it into a hash, geting the TAIR anotation as keys and the next
line as the value
@temp_list = split (/#/, $input_string);
map (chomp, @temp_list);
foreach $gene (@temp_list){
($k, $v) = split (/:/, $gene);
$all_genes {$k} = $v;
}
#Sort the hash and write to a new file
foreach $k (sort keys (%all_genes)) {
for (1..5){
if ($k =~ /[$_]g/){
$file = "CHR$_";
print $file ">$k\t$all_genes{$k}\n";
last;
}
}
}