Extracting equivalent nodes

63 прегледа
Пређи на прву непрочитану поруку

April Wright

непрочитано,
5. 2. 2015. 14:33:415.2.15.
– dendrop...@googlegroups.com
Hi Jeet-

I'd like to compare support for equivalent splits across multiple trees. It seems the way to find the equivalent splits is to use treesplit.encode_splits. Is there a way to map the objects in treesplit back to get the node.labels to which they correspond?

Thanks!

Jeet Sukumaran

непрочитано,
5. 2. 2015. 15:09:385.2.15.
– dendrop...@googlegroups.com
Hi April,

Very easily. In fact, it is one of the fundamental components of
DendroPy's architecture that allows trees to be decomposed into splits
that are comparableacross different trees, as long as they share the
same taxon namespace.

Unfortunately, the whole splits mechanism was very much an
"under-the-hood" thing in DendroPy 3. In other words, undocumented.
Which limited what users could do with it without some code inspection
or guidance.

In DendroPy 4, however, splits are very much part of publicly-exposed
datamodel, through the `Bipartition` class:


https://github.com/jeetsukumaran/DendroPy/blob/DendroPy4/doc/source/tutorial/bipartitions.rst

Basically, for what you want to do, once you run ``encode_splits``, the
tree should have a attribute ``split_edges``, which is a dictionary of
the splits in the tree mapped to edges on the tree. So you can just
dereference the node using ``tree.split_edges[split].head_node``. In
DendroPy 4, the previous *should* still work, but with lots of
deprecation warnings, and the preferred approach is
``tree.bipartition_edge_map[b].head_node``.

So, for example, the following code will create a dictionary with keys
being a particular split, and the values being the list of support
values as indicated by node labels from across all trees (CODE IS
UNTESTED --- might have some typos/bugs):

~~~
import collections
import dendropy

trees = dendropy.TreeList.get_from_path(
"trees_with_support_as_labels.nex",
"nexus")
bipartition_labels = collections.defaultdict(list)
for tree in trees:
tree.encode_bipartitions()
for bp in tree.bipartition_edge_map:
node = tree.bipartition_edge_map[bp].head_node
if node.label:
bipartition_labels[bp].append(float(node.label))

for bp, labels in bipartition_labels.items():
print("{:20}:
{}".format(bp.leafset_as_newick_string(trees.taxon_namespace), labels))
~~~

The above code is for DendroPy4 (which I highly recommend you switch
to!), but to you can get the number crunching part to work in DendroPy3
by changing out `encode_bipartitions` for `encode_splits` and
`bipartiton_edge_map` for `split_edges`. Getting the splits represented
as nifty NEWICK strings in DendroPy 3 is also possible, by going through
the TaxonSet function.

Let me know if this works out, or if you have any questions!

-- jeet
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
> <mailto:dendropy-user...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--



--------------------------------------
Jeet Sukumaran
--------------------------------------
jeetsu...@gmail.com
--------------------------------------
Blog/Personal Pages:
http://jeetworks.org/
GitHub Repositories:
http://github.com/jeetsukumaran
Photographs (as stream):
http://www.flickr.com/photos/jeetsukumaran/
Photographs (by galleries):
http://www.flickr.com/photos/jeetsukumaran/sets/
--------------------------------------

t.py

April Wright

непрочитано,
8. 2. 2015. 12:40:008.2.15.
– dendrop...@googlegroups.com
Awesome, thanks Jeet. I'm installing 4.0 now. I used pip installation from git via:

pip install https://github.com/jeetsukumaran/DendroPy/archive/DendroPy4.zip

But I'm getting an error when I import dendropy:

No module named dataio.nexusprocessing.

I can see the module in the source. Is pip ready to go, or should I use setuptools?

April Wright

непрочитано,
8. 2. 2015. 12:41:598.2.15.
– dendrop...@googlegroups.com
Edit: installing via setuptools gives me the same issue.

Mark Holder

непрочитано,
8. 2. 2015. 12:55:548.2.15.
– dendrop...@googlegroups.com
Hi April,

I'm not sure, but this is probably an issue in the setup.py.

I'm confident that Jeet will have a fix. 

I got the same behavior when I tried with the pip command that you used.  A workaround is:

    unzip DendroPy4.zip
    cd DendroPy-DendroPy4
    python setup.py develop

(although you might want to just check out the branch via get rather than using a snapshot).

cheers,
Mark

To unsubscribe from this group and stop receiving emails from it, send an email to dendropy-user...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Mark Holder


==============================================
Department of Ecology and Evolutionary Biology
University of Kansas
6031 Haworth Hall
1200 Sunnyside Avenue
Lawrence, Kansas 66045

lab phone:  785.864.5789
fax (shared): 785.864.5860
==============================================

Jeet Sukumaran

непрочитано,
8. 2. 2015. 13:03:178.2.15.
– dendrop...@googlegroups.com
Hi April,

This is caused by the old DendroPy still being on your path. You can
verify this by:

$ python -c "import dendropy; print(dendropy.description())"

Once DendroPy 4 goes public in PyPI, the upgrade process should be
handled by Pip easier.

Right now, though the only way is a clean removal of DendroPy 3
followed by installation of DendroPy 4.

# Clean Removal of DendroPy 3

Hopefully, the following should work:

$ pip uninstall dendropy

Verify that it has worked by ensuring that the following raises an
`ImportError`:

$ python -c "import dendrody"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named dendrody

If there is no `ImportError` raised, then you need to do it manually:

1. Go to your site packages directory:

cd $(python -c "import site; print(site.getsitepackages())[0]")

If the above fails, see

[here](http://stackoverflow.com/questions/122327/how-do-i-find-the-location-of-my-python-site-packages-directory)
for more options.

2. Edit the file "easy-install.pth", and remove all references to DendroPy:

$ vim easy-install.pth
:g /\cdendropy/d

3. Delete all DendroPy references in the site-packages directory:

$ rm -rf DendroPy*
$ rm -rf dendropy*

# Install DendroPy in Developer Mode

$ cd $WHEREVER_YOU_WANT_TO_HOST_DENDROPY
$ git clone https://github.com/jeetsukumaran/DendroPy.git
$ cd DendroPy
$ git checkout -t -b DendroPy4 /origin/DendroPy4
$ python setup.py build
$ sudo python setup.py develop

Let me know if this works.

-- jeet
> > an email to dendropy-user...@googlegroups.com <javascript:>
> > <mailto:dendropy-user...@googlegroups.com <javascript:>>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
>
>
>
> --------------------------------------
> Jeet Sukumaran
> --------------------------------------
> jeetsu...@gmail.com <javascript:>
> --------------------------------------
> Blog/Personal Pages:
> http://jeetworks.org/
> GitHub Repositories:
> http://github.com/jeetsukumaran <http://github.com/jeetsukumaran>
> <http://www.flickr.com/photos/jeetsukumaran/sets/>
> --------------------------------------
>
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
> <mailto:dendropy-user...@googlegroups.com>.

April Wright

непрочитано,
8. 2. 2015. 13:43:138.2.15.
– dendrop...@googlegroups.com
There we go! I think when I originally checked out the repo, my checkout to 4 failed, I didn't notice, and I ended up reinstalling 3.12.

All right; I'm going to monkey around in 4.
>      > <mailto:dendropy-users+unsub...@googlegroups.com <javascript:>>.
>      > For more options, visit https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>.
>
>     --
>
>
>
>     --------------------------------------
>     Jeet Sukumaran
>     --------------------------------------
>     jeetsu...@gmail.com <javascript:>
>     --------------------------------------
>     Blog/Personal Pages:
>     http://jeetworks.org/
>     GitHub Repositories:
>     http://github.com/jeetsukumaran <http://github.com/jeetsukumaran>
>     Photographs (as stream):
>     http://www.flickr.com/photos/jeetsukumaran/
>     <http://www.flickr.com/photos/jeetsukumaran/>
>     Photographs (by galleries):
>     http://www.flickr.com/photos/jeetsukumaran/sets/
>     <http://www.flickr.com/photos/jeetsukumaran/sets/>
>     --------------------------------------
>
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
Одговори свима
Одговори аутору
Проследи
0 нових порука