Showing posts with label phylip. Show all posts
Showing posts with label phylip. Show all posts

Tuesday, March 29, 2011

Merging sequences within trees

Once I found Dendropy it became pretty easy to parse and determine which sequences can be merged. Something akin to this code works well:

tree = Tree.get_from_string(tree_str, schema = 'newick')
done = set()
groups = []
for t in tree.level_order_node_iter():
  if t.edge.length >= 90:
  lens = [x.edge.length >= 90 for x in t.level_order_iter() if not x.is_leaf()]
  if all(lens) or not any(lens) or t.is_leaf():
    leafs = set([str(x.taxon) for x in t.leaf_nodes()])
    groups.append(leafs-done)
    done |= leafs
groups = [x for x in groups if x]


This will produce a list of sets in which all members of the set are either all descendants have a bootstrap value of >90 or none of the values are below >90.

In my HIV data its 557 groups out of 707. The largest group is 6 sequences. Below is the tree:
I'm not really great with the evolutionary biology so I'm not sure if this a warning sign ... I'll send a message to JB to see if he sees any red flags.

I've already started this on the HCV genomes as well.

Monday, March 28, 2011

Phylip command-line

Phylip is a a pain in the ass when you're running it from a command line. You need to create a file which has all interactive prompts and then feed that along.

phylip proml < input > screenout

However, this is ANNOYING to do with python's subprocess module. It can't deal with the redirections so you have to use the subprocess input/output:

        if capture_output:
            out = open('screenout', 'w')
        else:
            out = open(os.devnull, 'w')
        inbuf = open('input','w')
        args = shlex.split(cmd)
        call(args, stdin = inbuf, stdout = out)

This is already in the code, just posting it here for reference

Thursday, March 24, 2011

HIV sequence tree

As per JB's suggestions I have created a concatenated alignment of all columns which have no gaps (from all proteins). This results in an alignment of ~1289 columns and 624 sequences (since I need to make sure all proteins are present).

Now I'm using phylip to create a tree out of these sequences ... however, this seems very slow going. Its been ~50 minutes and its only loaded 1/3rd of the sequences of the FIRST of 100 trees. I'll let it go for most of the day but this might be a little too extreme.