Mixing tab delimeters with space delimited data is a really bad idea, and if you have any choice in the matter, you should change it.
On the basis that you don't have the choice, the following should work, but realise that the tabs I've embedded in the data will likely have been corrupted in the process of upload and download, and the wrapping etc, that PM does to code:
#! perl -slw
use strict;
use Data::Dump qw[ pp ];
my %data;
while( <DATA> ) {
my( $str, @values ) = map{ s[^\s+|\s+$][]g; $_ } split "\t";
$data{ $str } = [ map [ split ' ' ], @values ];
}
pp %data;
my @output;
while( my( $key, $valueRef ) = each %data ) {
my @required;
for my $c ( 0 .. length( $key ) - 1 ) {
push @required, $valueRef->[ $c ][ index "ACGT", substr $key, $c,
+1 ];
}
push @output, \@required;
}
pp \@output;
__DATA__
AGAC 9 -29 -39 -37 27 -28 -39 -37 26 -27 -39 -37 2
+7 -27 -39 12
ACGT 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -1
+6
Output: c:\test>junk6
(
"AGAC",
[
[9, -29, -39, -37],
[27, -28, -39, -37],
[26, -27, -39, -37],
[27, -27, -39, 12],
],
"ACGT",
[
[1, -2, 3, -4],
[5, -6, 7, -8],
[9, -10, 11, -12],
[13, -14, 15, -16],
],
)
[[9, -39, 26, -27], [1, -6, 11, -16]]
This is the same, but I've substituted the text '<TAB>' for the tab character which shoudl make it easier to try:
Like I say, if you have any influence over the file format, change the tab delimiters to something visible that does not match "\s".
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|