On 7/12/07, Marc Hoeppner <marc.hoeppner / molbio.su.se> wrote:
>
> Let's say I have a text file with a number of rows (it's a molecular
> sequence alignment, so each row = one sequence).
> I am only interested in those columns in which a certain character
> appears - no matter whether in all row or only one. The whole column
> should then be puts'ed.
>
> After thinking about it for a moment, my idea was to store each row in
> an array, check each array position for the presence of that particular
> character and, if it is, found, to puts this array field [n] and the
> corresponding field from all other arrays. Now, there are a couple of
> potential problems such as hitting the same column multiple times
> because I search multiple arrays... But anyways, since I am rather new
> to programming and ruby in particular, that will take me a while - so I
> was wondering if there is a more elegant/efficient approach to this,
> before I waste my time on this only to find out it doesnt work or could
> be done more efficiently (wasted quite some time on another program the
> other day only to find out that it can be done with grep...yuck).
>
> /Marc
>
Does this do what you want?

arr = [[1,7,3,4],[5,6,7,8],[9,7,3,4]]
new_arr = arr.transpose

p new_arr.select {|x| x.include?(7)}

Harry


-- 
A Look into Japanese Ruby List in English
http://www.kakueki.com/