Earlier, in post #6, I mentioned the following:
I still believe that what you expect to see is misleading you of what it really is.
$out[45] = "VUS";
At this point, "VUS"
is still, the 46th element of array out
.
print OF join("\t",@out),"\n";
At that point, array out
has been flatten out as an string separated with tabs.
You have lost your ability to know what element it would be in a string that now contains new tab separated elements.
In fact, since $out[45]
is the last part, it would, actually, become $out[64]
if you were to split again by tab.
You have introduced new parts that have tabs as well.
You want to test it?
Here's your original code, with some prints to show some details. Run it with just the two lines of input you posted.
#!/bin/perl
use strict;
my %nms=("NM_004004.5"=>"AR","NM_004992.3"=>"XLD","NM_003924.3"=>"AD");
my $input_file = $ARGV[0];
my $output_file = $ARGV[1];
my @left = (
"Index",
"Chromosome Position",
"Gene",
"Inheritance",
"RNA Accession",
"Chr",
"Coverage",
"Score",
"A(#F,#R)",
"C(#F,#R)",
"G(#F,#R)",
"T(#F,#R)",
"Ins(#F,#R)",
"Del(#F,#R)",
"SNP db_xref",
"Mutation Call",
"Mutant Allele Frequency",
"Amino Acid Change"
);
my @right = (
"HP",
"SPLICE",
"Pseudogene",
"Classification",
"HGMD",
"Disease",
"Sanger",
"References"
);
my $final_header;
open (FH, "<", $input_file) or die "Can't open $input_file: $!";
chomp(my $hdr=<FH>);
$final_header = sprintf("%s\t%s\t%s\n", join("\t", @left), $hdr, join("\t",@right));
open (OF, ">", $output_file) or die "Can't open $output_file: $!";
print OF "$final_header";
my @colsleft = map "Null",(1..$#left);
print "\@colsleft = ", scalar @colsleft, ": @colsleft\n";
my @colsright = map "Null",(0..$#right);
print "\@colsright = ", scalar @colsright, ": @colsright\n";
while(<FH>) {
chomp;
my @vals = split/\t/;
my @mutations=split/,/,$vals[9];
my ($gene,$transcript,$exon,$coding,$aa);
for (@mutations)
{
$_ or next;
($gene,$transcript,$exon,$coding,$aa) = split/\:/; # this takes col AB and splits it at colons
grep {$transcript eq $_} keys %nms or next;
}
my @out=($.,@colsleft,$_,@colsright);
print "\n";
print 'After this evaluation: my @out=($.,@colsleft,$_,@colsright);', "\n";
print "\@out = ", scalar @out, ": @out\n\n";
$out[2]=$gene;
$out[3]=$nms{$transcript};
$out[4]=$transcript;
$out[15]=$coding;
$out[17]=$aa;
$out[45] = "VUS";
print 'After this evaluation: $out[45] = "VUS";', "\n";
print "\@out = ", scalar @out, ": @out\n\n";
print OF join("\t",@out),"\n";
my @after = split( "\t", join("\t", @out) );
print "\@after = ", scalar @after, ": @after\n";
}
Run as:
perl debug.pl input.file /dev/null
Output:
@colsleft = 17: Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null
@colsright = 8: Null Null Null Null Null Null Null Null
After this evaluation: my @out=($.,@colsleft,$_,@colsright);
@out = 27: 2 Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null Null 4 41748130 41748130 G C exonic PHOX2B synonymous SNV PHOX2B:NM_003924.3:exon3:c.C639G:p.G213G 0.0007 . . . . . 0.0005 0.0002 0.0007 . Null Null Null Null Null Null Null Null
After this evaluation: $out[45] = "VUS";
@out = 46: 2 Null PHOX2B AD NM_003924.3 Null Null Null Null Null Null Null Null Null Null c.C639G Null p.G213G 4 41748130 41748130 G C exonic PHOX2B synonymous SNV PHOX2B:NM_003924.3:exon3:c.C639G:p.G213G 0.0007 . . . . . 0.0005 0.0002 0.0007 . Null Null Null Null Null Null Null Null VUS
@after = 65: 2 Null PHOX2B AD NM_003924.3 Null Null Null Null Null Null Null Null Null Null c.C639G Null p.G213G 4 41748130 41748130 G C exonic PHOX2B synonymous SNV PHOX2B:NM_003924.3:exon3:c.C639G:p.G213G 0.0007 . . . . . 0.0005 0.0002 0.0007 . Null Null Null Null Null Null Null Null VUS
Please, scroll all the way to the right to see VUS
highlighted.
Again, knowing what the code does... it is not a problem; knowing what you expect is the hard part.
If you were to post an example of how those 2 lines are supposed to look after the process, that might help.