[Baypiggies] nested list question

Vikram K kpguy1975 at gmail.com
Tue Jun 28 17:43:46 CEST 2011


Thanks Jason. Could you (or someone else) suggest some approach for the
following:

>>> x
[['19600894', '1', 'chr15_76136768', 'MISSENSE'], ['19600894', '2',
'chr15_76136768', 'MISSENSE'], ['18467762', '1', 'chr14_23354066',
'MISSENSE']]


How do i obtain from nested list x (given above), the following nested list
z:

>>> z
[[19600894','1/2','chr15_76136768', 'MISSENSE', 'homozygous'], ['18467762',
'1','chr14_23354066', 'MISSENSE', 'heterozygous']]

In list x, the first element is loci, second element is allele, third
element is chromosome_positionofchange, fourth is type of change. Based on
the value of the second and third element a new element has to be created
--'homozygous' if both allele 1 and allele 2 have the change and
'heterozygous' if only one allele has the change.



On Mon, Jun 27, 2011 at 6:29 PM, Jason Culverhouse <jason at mischievous.org>wrote:

> On Jun 27, 2011, at 2:06 PM, Vikram K wrote:
>
> Suppose i have the following nested list:
>
> >>> x
> [['19600894', '1', 'chr15_76136768', 'MISSENSE'], ['19600894', '2',
> 'chr15_76136768', 'MISSENSE'], ['18467762', '1', 'chr14_23354066',
> 'MISSENSE']]
>
>
> How do i obtain from nested list x (given above), the following nested list
> z:
>
> >>> z
> [['chr15_76136768', 'MISSENSE'], ['chr14_23354066', 'MISSENSE']]
>
>
> How about:
>
> list(unique_everseen((y[2:4] for y in x), operator.itemgetter(0)))
>
> or the whole nested list with just
>
> list(unique_everseen(x, operator.itemgetter(2)))
>
>  where :
>
> unique_everseen is from
> http://docs.python.org/library/itertools.html
>
> If you data is already sorted by the key then
> unique_justseen
>
> might be more efficient?
>
> Jason
>
> ------
> In other words, if the third element of an element of x is the same, then i
> wish to combine it into a single element.
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20110628/a7983f60/attachment.html>


More information about the Baypiggies mailing list