Code Monkey home page Code Monkey logo

baltic's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

baltic's Issues

Write basic unit tests

  • Make demo tree structure in newick, nexus and json formats w/ and w/o absoluteTime and attributes
  • Test that all three formats can be read
  • Test that tree structure is as expected
  • Test that each leaf is parsed correctly
  • Test that each node is parsed correctly
  • Test that all attributes are assigned correctly

No way of adding text to circular tree.

If I understand correctly, currently there's no way of adding text to a circular tree. Am I missing something or should I write my own implementation of addCircularText() ?

Unable to extract assigned color, clade id, and leaf id into tsv/dataframe

I successfully used the documentation to make this plot:
AZ20_panaroo-datetree_muller

However, now what I want to do is assign a clade/grouping-id to each color, so that I can match the id to the color for labeling and further experimental study. I also want all of the leaf tips (isolate ids) for all the groupings. That way, I can randomly select isolates from each of the grouping for additional follow-up analysis and experiments.

My guess on how to do that was:

collapse_target=lambda k: k.is_node() and 'type' in k.parent.traits and k.traits['type']!=k.parent.traits['type']

for idx,k in enumerate(ll.getBranches(collapse_target)): 
    clade_id = f'Clade {idx+1}'
    for elem in K:
        if element.is_leaf():
            print(f'{elem.id}\t{clade_id}')

But I get error: Exception: No branches satisfying function were found amongst branches

How do I extract that information into a tsv or other dataframe?

Export back to NextStrain JSON

I am working on a project where I am trying to add some additional information to the leaves of a Nextstrain JSON tree. Your package is amazing for parsing that format, but I am having a hard time understanding how to get the export back to JSON format from baltic.baltic.tree object format. Is there a function or method for that?

AttributeError: 'NoneType' object has no attribute 'traverse_tree'

I'm trying to use the ".traverse_tree" option on an imported .json file. When I use traverse_tree, I get an error saying, "AttributeError: 'NoneType' object has no attribute 'traverse_tree'."

A colleague of mine doesn't get this error using the same code, but they use version 0.1.0. I have gotten it with version 0.1.1 and 0.1.2. When I tried to revert to version 0.1.0, I get the following error: "FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'".

You can see a copy of the code I'm running here.

Adding extra elements on tree plots

Hey, thank you for setting baltic up as a python package: the installation was much easier now. I installed it days ago, and since them I've been playing with its functionalities. I have a question about plotting extra elements on trees. I'm trying to achieve a result similar to this baltic figure.

The extra elements I want to plot are:

  1. Node markers indicating posterior probabilities
  2. tMRCA violin plots at internal nodes
  3. Date ticks in months
  4. A subtree, pruned from the imput tree

Concerning 1, I was wondering how I can achieve that using a function similar to plotPoints, but for nodes, not leaves.

Concerning 4, I tried to apply the function subtree, however, instead of getting a tree rooted at the selected commonAncestor tMRCA (2012.58), baltic is keeping the root of the original tree (1970.55). As a result, when using the cmap 'hsv', instead of having a gradient from blue to red, in the final plot I only see red/magenta hues (indicating the misplacement of the root decades before the expected).

Since I couldn't find specific instructions on austhecia or curonia, I was wondering if you have any examples on how to plot these elements.

Thank you.

Cheers

Take singleton as a baltic tree object

Hi,

I'm trying to find a way to make baltic treat singletons along polytomies as tree objects (number of leaves = 1), so that I can show those in a exploded layout. This seems to be not possible to perform in baltic 0.1.5, since the subtree.getInternal() step fails, and I can't get the subtree.root.absoluteTime. In fact, perhaps due to some default option, only actual clades (number of leaves >= 2) can be shown in the final exploded tree plot.

Example: how do I get this singleton Iceland genome to be shown in an exploded layout, to show an introduction into that country?
https://nextstrain.org/community/grubaughlab/CT-SARS-CoV-2/update2?branchLabel=aa&c=country&s=Iceland/91/2020

Cheers

TypeError: unsupported operand type(s) for -: 'function' and 'int'

Hello,

I'm trying to plot a tree using this line of code loc_tree.plotPoints(ax, x_attr=x_attr, y_attr=y_attr, size=s_func, colour=c_func, zorder=z_func) where everything is defined. The code is one 187 of this script using this input tree. I get this error as a response:

Traceback (most recent call last):
File "C:/Users/28Cha/sarscvo2/scripts/baltic_explodeJSON.py", line 187, in
loc_tree.plotPoints(ax, x_attr=x_attr, y_attr=y_attr, size=s_func, colour=c_func, zorder=z_func)
File "C:\Users\28Cha\Documents\Python\venv\lib\site-packages\baltic\baltic.py", line 780, in plotPoints
ax.scatter(outline_xs,outline_ys,s=outline_sizes,facecolor=outline_colours,edgecolor='none',zorder=zorder-1,**kwargs) ## put a circle at each tip
TypeError: unsupported operand type(s) for -: 'function' and 'int'

If I comment out line 187 and try to use the outline points, I get the same error.

I was wondering if anyone had any suggestions. If it makes a difference, I am using version 0.1.2.

Tree regex tricky to use

The tree regex has a hard coded ".lower" (line 1274) so it makes it difficult to customise the treestring_regex for case sensitive stuff.

Eg dendropy will write a nexus file starting with "TREE 1", so the treestring regex needs customising, but to get baltic to find the tree string, you have to give a regex of "tree [0-9]" because of that hard-coded lower. It's not the end of the world, but it does lead to some frustration when a custom regex fails for no discernible reason.

I don't know what the solution is tbh, but thought I should flag it as a user interface thing

commonAncestor returns wrong node when MRCA is root of tree

If the MRCA of a set of tips given to the commonAncestor function is the root of the tree, then Baltic will sometimes return the node that is the parent of the root instead of the root itself, because both the root and the parent of the root have height 0, so the sorting functionality in the commonAncestor function is insufficient. This causes issue if you want to get some statistics, such as the tMRCA, which is not defined at the parent of the tree root. I think this can be fixed by replacing the current function with the following, which stops the iterating at the root of the tree instead of going all the way to the root parent (there's probably a better way to do this). This function does assume that there is a parent node of the MRCA of all tips in the tree, but I think that is guaranteed by the way Baltic reads in trees.

def commonAncestor(self,descendants,strict=False):
        """
        Find the most recent node object that gave rise to a given list of descendant branches.
        """
        assert len(descendants)>1,'Not enough descendants to find common ancestor: %d'%(len(descendants))
        paths_to_root={k.index: set() for k in descendants} ## for every descendant create an empty set
        for k in descendants: ## iterate through every descendant
            cur_node=k ## start descent from descendant
            while cur_node.parent: ## while not at root
                paths_to_root[k.index].add(cur_node) ## remember every node visited along the way
                cur_node=cur_node.parent ## descend

        return sorted(reduce(set.intersection,paths_to_root.values()),key=lambda k: k.height)[-1] ## return the most recent branch that is shared across all paths to root

Ascending branch sort?

I made the controversial decision to try to sort my tree in ascending order, and in doing so I noticed that changing the descending flag of the sortBranches function didn't change my tree at all, as it was always in descending order.
A little digging led me to this line

mod=-1 if descending else -1

which seems like it should be modified to

mod=-1 if descending else 1

Making the change locally did the trick after running the line ll.sortBranches(descending=False) (screenshot below):
Apologies for not submitting this as a PR, my on-save formatter made a disaster of baltic.py so this seemed like a better way to submit this.

image

Unicode Errors

When using loadJSON from an auspice tree, Unicode errors are often raised. Could different encodings be tried before raising an error in future versions?

Add exports

Hello!

I believe you shared with me some code for exporting a baltic tree as a Nextstrain JSON. I expect it would be widely useful at this point.

exportJSON perhaps?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.