-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from js51/develop
add lots of new stuff
- Loading branch information
Showing
8 changed files
with
194 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
numpy == 1.16.4 | ||
pandas == 0.24.2 | ||
networkx == 2.4 | ||
scipy == 1.4.1 | ||
numpy == 1.19.2 | ||
pandas == 1.1.2 | ||
networkx == 2.5 | ||
scipy == 1.5.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from enum import Enum, auto | ||
|
||
class Model(Enum): | ||
def _generate_next_value_(name, start, count, last_values): | ||
return name | ||
JC = auto() | ||
K2ST = auto() | ||
|
||
class Method(Enum): | ||
def _generate_next_value_(name, start, count, last_values): | ||
return name | ||
flattenings = auto() | ||
subflattenings = auto() | ||
distance = auto() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" A collection of tree reconstruction methods. | ||
Each one of these methods accepts a sequence alignment in the form of a dictionary, | ||
and returns a collection of splits which have been chosen as `most likely' to be true. | ||
Some methods will return additional information. Not all methods guarantee that the splits returned will be compatible. | ||
""" | ||
|
||
import splitp as sp | ||
from splitp import tree_helper_functions as hf | ||
import numpy as np | ||
|
||
def erickson_SVD(): | ||
pass | ||
|
||
def all_split_scores(): | ||
pass | ||
|
||
def split_tree_parsimony(alignment, splits=None): | ||
if type(alignment) is dict: | ||
alignment_dict = alignment | ||
else: | ||
alignment_dict = {} | ||
for table_pattern, value in alignment.itertuples(index=False, name=None): | ||
alignment_dict[table_pattern] = value | ||
num_taxa = len(list(alignment_dict.keys())[0]) # Length of first pattern | ||
all_splits = list(hf.all_splits(num_taxa)) if splits==None else splits | ||
scores = {split : 0 for split in all_splits} | ||
for split in all_splits: | ||
newick_string = [] | ||
for part in split.split('|'): | ||
newick_string.append(f'({",".join(c for c in part)})') | ||
newick_string = f"({newick_string[0]},{newick_string[1]});" | ||
split_tree = sp.NXTree(newick_string, taxa_ordering='sorted') | ||
for pattern, value in alignment_dict.items(): | ||
scores[split] += value * (split_tree.hartigan_algorithm(pattern)/(num_taxa-1)) | ||
return scores | ||
|
||
def euclidean_split_distance(alignment, splits): | ||
print("assuming sorted taxa") | ||
states = ('A', 'G', 'C', 'T') | ||
alignment_dict = {} | ||
for table_pattern, value in alignment.itertuples(index=False, name=None): | ||
alignment_dict[table_pattern] = value | ||
num_taxa = len(list(alignment_dict.keys())[0]) # Length of first pattern | ||
all_splits = list(hf.all_splits(num_taxa)) if splits==None else splits | ||
scores = {split : 0 for split in all_splits} | ||
for split in all_splits: | ||
split_list = split.split('|') | ||
for pattern, value in alignment_dict.items(): | ||
part_a = "".join(pattern[int(s, base=num_taxa+1)] for s in split_list[0]) | ||
part_b = "".join(pattern[int(s, base=num_taxa+1)] for s in split_list[1]) | ||
vec_a = np.array([ part_a.count(state) for state in states ]) | ||
vec_b = np.array([ part_b.count(state) for state in states ]) | ||
vec_a = vec_a / np.linalg.norm(vec_a) | ||
vec_b = vec_b / np.linalg.norm(vec_b) | ||
scores[split] += value * (2-np.linalg.norm(vec_a - vec_b))/2 | ||
return scores |