[Biopython] Maintaining partition order in concatenated nexus

David Winter djwinter at asu.edu
Tue Jun 9 21:19:09 UTC 2015


In that last message the class definition should be

class OrderedNexus(Nexus.Nexus):
    """ Subclass of Bio.Nexus.Nexus used to maintain partition order """

    def __init__(self, **kwargs):
        Nexus.Nexus.__init__(self, **kwargs)
        self.charpartitions = OrderedDict()

(i.e. with the parentheses after OrderedDict..... you always see them the
second you hit "send" :)

David

On Tue, Jun 9, 2015 at 2:17 PM, David Winter <djwinter at asu.edu> wrote:

> Hi Michael,
>
> I think this is a result of  "charpartitions" in the Nexus object being a
> dictionary. In python dictionaries are "unordered", so you don't usually
> get objects back out in the order they went in.
>
> One possible workaround it to make you own class that inherits everything
> else from Nexus but instead uses an ordered  dictionary (from collections),
> something like
>
>
> from collections import OrderedDict
> from Bio.Nexus import Nexus
>
> class OrderedNexus(Nexus.Nexus):
>     """ Subclass of Bio.Nexus.Nexus used to maintain partition order """
>
>     def __init__(self, **kwargs):
>         Nexus.Nexus.__init__(self, **kwargs)
>         self.charpartitions = OrderedDict
>
>
>
> o = OrderedNexus()
> n = Nexus.Nexus()
>  o.charpartitions
> #OrderedDict()
> n.charpartitions
> #{}
> dir(o) # (all the stuff you expect to see in a Nexus object)
>
> I haven't had a chance to test this on the example, but hope it's some
> help to you.
>
> David
>
>
> On Tue, Jun 9, 2015 at 6:37 AM, Michael Gruenstaeudl <
> mi.gruenstaeudl at gmail.com> wrote:
>
>> Hi all,
>> like many others, I have been using the excellent example on the
>> Biopython wiki to concatenate multiple alignments into one nexus-file using
>> Biopython's Nexus.combine() function. However, what if I wish to maintain
>> the order of the nexus-partitions specified in 'file_list'. While the tuple
>> 'nexi' is still ordered according to 'file_list',
>> 'combined.charsets.items()' is not. Moreover, sorting the charsets is not
>> possible:
>>
>> >>> combined.charsets.items()[0]
>> ('partition0038_rps4_CDS.nex', [36567, 36568])
>>
>> >>> combined.charsets.items()[1]
>> ('partition0004_trnK_CDS.nex', [36569, 36573])
>>
>> >>> for i in range(0,len(combined.charsets.items())):
>> ...     combined.charsets.items()[i] = sorted_items[i]
>> ...
>> >>> combined.charsets.items()[0]
>> ('partition0038_rps4_CDS.nex', [36567, 36568])
>>
>> What procedure would you recommend to maintain the input order of
>> 'file_list' in the output file 'combined.nex'?
>>
>> Thank you, Michael
>>
>> --
>> Michael Gruenstaeudl (Grünstäudl), PhD
>> E-mail: mi.gruenstaeudl at gmail.com
>> Website: http://blogs.fu-berlin.de/gruenstaeudl/
>> <http://u.osu.edu/gruenstaeudl/>
>>
>> _______________________________________________
>> Biopython mailing list  -  Biopython at mailman.open-bio.org
>> http://mailman.open-bio.org/mailman/listinfo/biopython
>>
>
>
>
> --
> David Winter
> Postdoctoral Research Associate
> Center for Evolutionary Medicine and Informatics
> The Biodesign Institute
> Arizona State University
>
> ph: +1 480 519 5113
> w: www.david-winter.info
> lab: http://cartwrig.ht/lab/
> blog: sciblogs.co.nz/the-atavism
>



-- 
David Winter
Postdoctoral Research Associate
Center for Evolutionary Medicine and Informatics
The Biodesign Institute
Arizona State University

ph: +1 480 519 5113
w: www.david-winter.info
lab: http://cartwrig.ht/lab/
blog: sciblogs.co.nz/the-atavism
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20150609/657717b0/attachment-0001.html>


More information about the Biopython mailing list