Biopolete has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I' m trying to convert a column to a csv file.
My data looks like:
##INFO=<ID=AA,
##INFO=<ID=AB,
##INFO=<ID=AC,
Num Data
1 AA=1;AB=2;AC=3
2 AA=2;AB=2
3 AA=5;AB=1;AC=1
And I want a csv like this:
AC AB AC
1 2 3
2 2 NA
5 1 1
First of all I do a hash obtaining the keys from the metadata (##)
open(I1,$ARGV[0]); my %info; while (my $line = <I1>) { if ($line =~ /##INFO=<ID=/) { my ($first,$second) = (split(/\,/, $line)); my ($firstsecond,$secondsecond) = (split(/ID=/, $first)); $info{$secondsecond}=(); } }
Now I have my hash info with my keys (AA, AB, AC)
Then I want to introduce the values.
I start with:
while (my $line = <I1>) { if ($line !~ /#/) { my ($numbers,$data) = (split(/\t/, $line)); foreach my $dat ($data){ my ($string, $int) = (split(/\;/, $dat));
That is because I want to eliminate \t and ;
But I don't know how to introduce the missing values (NA)
I want something like this:
AA => 1,2,5
AB => 2,2,1
AC => 3,NA,1
Anyone knows how to introduce the NA string in its correct position?? (my real file is much bigger with a lot of NA)
Thank you very much.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Adding missing values into a hash
by Laurent_R (Canon) on Jun 18, 2014 at 20:07 UTC | |
by Biopolete (Initiate) on Jun 19, 2014 at 14:36 UTC | |
Re: Adding missing values into a hash
by McA (Priest) on Jun 18, 2014 at 19:58 UTC | |
by Biopolete (Initiate) on Jun 19, 2014 at 14:33 UTC | |
by Anonymous Monk on Jun 20, 2014 at 07:22 UTC | |
by Biopolete (Initiate) on Jun 20, 2014 at 12:22 UTC | |
Re: Adding missing values into a hash
by poj (Abbot) on Jun 18, 2014 at 19:57 UTC | |
by Biopolete (Initiate) on Jun 19, 2014 at 14:32 UTC | |
by poj (Abbot) on Jun 19, 2014 at 15:00 UTC | |
by Biopolete (Initiate) on Jun 20, 2014 at 08:16 UTC | |
by poj (Abbot) on Jun 20, 2014 at 08:48 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |