Skip to content

Add tree pruning method #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add tree pruning method #37

wants to merge 1 commit into from

Conversation

Zsailer
Copy link
Owner

@Zsailer Zsailer commented Oct 3, 2019

Adds a .phylo.prune() method.

The function takes a simple kwarg. The key is the column name in the DataFrame and the value is row's value at that column.

Example:

In the example below, prune a node "3" by passing in id='3'. id is the column name. '3' is the value.

Before:

df.phylo.display()

Screen Shot 2019-10-03 at 1 54 10 PM

After:

df.phylo.prune(id='3')
df.phylo.display

Screen Shot 2019-10-03 at 1 54 18 PM

@Zsailer
Copy link
Owner Author

Zsailer commented Oct 3, 2019

@harmsm and @jharman25

Comment on lines +39 to +46
node = tree.find_node_with_label(val)

# Get all descendant nodes
descendants = list(node.postorder_iter())

# Remove them from dataframe
nodes_to_rm = [d.label for d in descendants]
return df.loc[~df[col].isin(nodes_to_rm)]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harmsm Here's the magic.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postorder_iter is a generator that loops over descendant nodes from any other node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant