Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > axis reverse

Reply
Thread Tools

axis reverse

 
 
Nina
Guest
Posts: n/a
 
      09-20-2005
First format:
A| 4 10 5 7 4 6
C| 2 0 0 0 0 1
T| 3 0 3 1 3 1
G| 2 0 2 2 3 2

Second format:
#pos A C T G
-3 4 2 3 2
-2 10 0 0 0
-1 5 0 3 2
1 7 0 1 2
2 4 0 3 3
3 6 1 1 2

Can I ask, how can I make the script to change the first format file to
second one? It's like
axis reverse.
Thanks a lot!

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      09-20-2005
"Nina" <(E-Mail Removed)> wrote:
> First format:
> A| 4 10 5 7 4 6
> C| 2 0 0 0 0 1
> T| 3 0 3 1 3 1
> G| 2 0 2 2 3 2
>
> Second format:
> #pos A C T G
> -3 4 2 3 2
> -2 10 0 0 0
> -1 5 0 3 2
> 1 7 0 1 2
> 2 4 0 3 3
> 3 6 1 1 2
>
> Can I ask, how can I make the script to change the first format file to
> second one? It's like
> axis reverse.


I can't do that exactly, because it is not clear where the first column
in the result comes from. But maybe this will help you get started.

transpose.pl:

my @data;
while (<STDIN>) {
chomp;
my @x=split;
push @{$data[$_]}, $x[$_] foreach (0..$#x) ;
};
print join ("\t", @$_), "\n" foreach @data ;


Notice that everything is stored in memory at once. There is no easy
alternative to that.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
Matija Papec
Guest
Posts: n/a
 
      09-20-2005
X-Ftn-To: Nina

"Nina" <(E-Mail Removed)> wrote:
>First format:
>A| 4 10 5 7 4 6
>C| 2 0 0 0 0 1
>T| 3 0 3 1 3 1
>G| 2 0 2 2 3 2
>
>Second format:
>#pos A C T G
>-3 4 2 3 2
>-2 10 0 0 0
>-1 5 0 3 2
>1 7 0 1 2
>2 4 0 3 3
>3 6 1 1 2
>
>Can I ask, how can I make the script to change the first format file to
>second one? It's like
>axis reverse.


Assuming that all lines in first format have equal number of elements,

my @arr1 = (
[qw/A 4 10 5 7 4 6/],
[qw/C 2 0 0 0 0 1/],
[qw/T 3 0 3 1 3 1/],
[qw/G 2 0 2 2 3 2/],
);

my @arr2 =
map {
my $i = $_;
[ map $arr1[$_][$i], 0 .. $#arr1 ];
}
0 .. $#{ $arr1[0] };

use Data:umper;
print Dumper \@arr2;


Perhaps I'm wrong, but I have strong filing that this could be your homework
so you're on your own for the #pos column.


--
Matija
 
Reply With Quote
 
William James
Guest
Posts: n/a
 
      09-21-2005
Nina wrote:
> First format:
> A| 4 10 5 7 4 6
> C| 2 0 0 0 0 1
> T| 3 0 3 1 3 1
> G| 2 0 2 2 3 2
>
> Second format:
> #pos A C T G
> -3 4 2 3 2
> -2 10 0 0 0
> -1 5 0 3 2
> 1 7 0 1 2
> 2 4 0 3 3
> 3 6 1 1 2
>
> Can I ask, how can I make the script to change the first format file to
> second one? It's like
> axis reverse.
> Thanks a lot!


I really think that you would find it more enjoyable to use Ruby.
Try this:

# Read file and create transposed array.
a = ARGF.read.split("\n").map{|line| line.split(/\|?\s+/)}.transpose
half = a.size / 2
# Create "#pos" column.
pos = ['#pos'] + (-half .. half).reject{|n| n==0}
# Combine and print.
puts pos.zip(a).map{|x| x.flatten.join("\t")}


Output:

#pos A C T G
-3 4 2 3 2
-2 10 0 0 0
-1 5 0 3 2
1 7 0 1 2
2 4 0 3 3
3 6 1 1 2

 
Reply With Quote
 
Damian James
Guest
Posts: n/a
 
      09-21-2005
On Tue, 20 Sep 2005 18:10:23 +0200, Matija Papec said:
> "Nina" <(E-Mail Removed)> wrote:
>>Can I ask, how can I make the script to change the first format file to
>>second one? It's like
>>axis reverse.

>
> Assuming that all lines in first format have equal number of elements,


I'd actually suggest looking at Math::Matrix, since chances are
the OP will eventually want more of its features than just
transposition.

--Damian
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      09-21-2005
Nina <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> First format:
> A| 4 10 5 7 4 6
> C| 2 0 0 0 0 1
> T| 3 0 3 1 3 1
> G| 2 0 2 2 3 2
>
> Second format:
> #pos A C T G
> -3 4 2 3 2
> -2 10 0 0 0
> -1 5 0 3 2
> 1 7 0 1 2
> 2 4 0 3 3
> 3 6 1 1 2
>
> Can I ask, how can I make the script to change the first format file to
> second one? It's like
> axis reverse.


Ah, transposition. Last time it came up (it's been a while, more than a
year I think) someone suggested Text::Table, but at the time it couldn't
do it. In the meantime Text::Table has learned a new trick: it accepts
multiline strings as data elements where each partial line goes into the
same table column. Feeding a table an array of multiline strings, each
of which contains the data for a whole would-be column does the trick:

use Text::Table;
print Text::Table->new->add( map join( "\n", split), <DATA>);

__DATA__
A| 4 10 5 7 4 6
C| 2 0 0 0 0 1
T| 3 0 3 1 3 1
G| 2 0 2 2 3 2

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
Matija Papec
Guest
Posts: n/a
 
      09-21-2005
X-Ftn-To: Damian James

Damian James <(E-Mail Removed)> wrote:
>>>second one? It's like
>>>axis reverse.

>>
>> Assuming that all lines in first format have equal number of elements,

>
>I'd actually suggest looking at Math::Matrix, since chances are
>the OP will eventually want more of its features than just
>transposition.


Tnx, the module looks very nice.


--
Matija
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      09-21-2005
http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Anno Siegel) wrote in
news:dgrobi$t1c$(E-Mail Removed)-Berlin.DE:

> Ah, transposition. Last time it came up (it's been a while, more than
> a year I think) someone suggested Text::Table, but at the time it
> couldn't do it. In the meantime Text::Table has learned a new trick:
> it accepts multiline strings as data elements where each partial line
> goes into the same table column. Feeding a table an array of
> multiline strings, each of which contains the data for a whole
> would-be column does the trick:
>
> use Text::Table;
> print Text::Table->new->add( map join( "\n", split), <DATA>);


Nice! Thank you for pointing this out.

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
Nina
Guest
Posts: n/a
 
      09-23-2005
Thanks Anno,

PS: your README file
http://search.cpan.org/src/ANNO/Text-Table-1.107/README
is repeatly presented.



Anno Siegel wrote:
> Nina <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> > First format:
> > A| 4 10 5 7 4 6
> > C| 2 0 0 0 0 1
> > T| 3 0 3 1 3 1
> > G| 2 0 2 2 3 2
> >
> > Second format:
> > #pos A C T G
> > -3 4 2 3 2
> > -2 10 0 0 0
> > -1 5 0 3 2
> > 1 7 0 1 2
> > 2 4 0 3 3
> > 3 6 1 1 2
> >
> > Can I ask, how can I make the script to change the first format file to
> > second one? It's like
> > axis reverse.

>
> Ah, transposition. Last time it came up (it's been a while, more than a
> year I think) someone suggested Text::Table, but at the time it couldn't
> do it. In the meantime Text::Table has learned a new trick: it accepts
> multiline strings as data elements where each partial line goes into the
> same table column. Feeding a table an array of multiline strings, each
> of which contains the data for a whole would-be column does the trick:
>
> use Text::Table;
> print Text::Table->new->add( map join( "\n", split), <DATA>);
>
> __DATA__
> A| 4 10 5 7 4 6
> C| 2 0 0 0 0 1
> T| 3 0 3 1 3 1
> G| 2 0 2 2 3 2
>
> Anno
> --
> If you want to post a followup via groups.google.com, don't use
> the broken "Reply" link at the bottom of the article. Click on
> "show options" at the top of the article, then click on the
> "Reply" at the bottom of the article headers.


 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      09-23-2005
Nina <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Thanks Anno,
>
> PS: your README file
> http://search.cpan.org/src/ANNO/Text-Table-1.107/README
> is repeatly presented.


Thanks for noticing. It's going in the Todo list.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Axis question: what is the correct way to use Axis? ed Java 2 12-08-2006 07:31 PM
Calling a Web Service using Axis, from within an Axis Web Service running under Tomcat hocho888 Java 1 04-29-2005 08:26 PM
AXIS jars org.apache.axis.wsi.* and org.apache.axis.transport.jms.* unkwb@web.de Java 0 02-23-2005 04:02 PM
Axis 1.1 don't delete attachments in the axis attachment cache Stefan Java 0 05-06-2004 08:00 PM
axis.jar does not contain org.apache.axis.client.ServiceClient? Joey Vendetta Java 0 04-01-2004 05:51 PM



Advertisments