Skip to content

Commit

Permalink
Add tn93 distance
Browse files Browse the repository at this point in the history
  • Loading branch information
aghozlane committed Nov 26, 2024
1 parent 41e17f1 commit 2893028
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
8 changes: 8 additions & 0 deletions meteor/meteor.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,12 @@ def get_arguments() -> Namespace: # pragma: no cover
required=True,
help="Path to output directory.",
)
tree_parser.add_argument(
"-r",
dest="gtr",
action='store_true',
help="Compute GTR genetic distance (slow).",
)
tree_parser.add_argument(
"--tmp",
dest="tmp_path",
Expand Down Expand Up @@ -781,6 +787,7 @@ def main() -> None: # pragma: no cover
args.width,
args.height,
args.format,
args.gtr
)
trees.execute()
# Run download catalogues
Expand Down Expand Up @@ -864,6 +871,7 @@ def main() -> None: # pragma: no cover
800,
600,
None,
False
)
trees.execute()
# Close logging
Expand Down
10 changes: 7 additions & 3 deletions meteor/phylogeny.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Phylogeny(Session):
msp_file_list: list[Path]
max_gap: float
min_info_sites: int
gtr: bool
tree_files: list[Path] = field(default_factory=list)

def compute_site_info(self, sequences: Iterable[str]) -> list[float]:
Expand Down Expand Up @@ -170,11 +171,14 @@ def process_msp_file(
)
# cleaned_alignment = load_aligned_seqs(ali_file, moltype="dna")
# d = EstimateDistances(cleaned_alignment, submodel=GTR())
d = EstimateDistances(aligned_seqs, submodel=GTR())
d.run(show_progress=False)
if self.gtr:
dists = EstimateDistances(aligned_seqs, submodel=GTR())
dists.run(show_progress=False)
else:
dists = aligned_seqs.distance_matrix(calc="tn93", show_progress=False)

# Create UPGMA Tree
mycluster = upgma(d.get_pairwise_distances())
mycluster = upgma(dists.get_pairwise_distances())
mycluster = mycluster.unrooted_deepcopy()

with tree_file.open("w") as f:
Expand Down
2 changes: 1 addition & 1 deletion meteor/tests/test_phylogeny.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def phylogeny_builder(datadir: Path, tmp_path: Path) -> Phylogeny:
meteor.tree_dir.mkdir()
meteor.threads = 1
meteor.DEFAULT_GAP_CHAR = "?"
return Phylogeny(meteor, [Path(datadir / "msp_0864.fasta")], 0.5, 4)
return Phylogeny(meteor, [Path(datadir / "msp_0864.fasta")], 0.5, 4, True)


def test_compute_site_info(phylogeny_builder: Phylogeny):
Expand Down
2 changes: 1 addition & 1 deletion meteor/tests/test_treebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def treebuilder_builder(datadir: Path, tmp_path: Path) -> TreeBuilder:
meteor.tree_dir.mkdir()
meteor.threads = 1
meteor.strain_dir = datadir / "strain"
return TreeBuilder(meteor, 0.5, 4, 500, 500, None)
return TreeBuilder(meteor, 0.5, 4, 500, 500, None, False)


def test_concatenate(treebuilder_builder: TreeBuilder, datadir: Path):
Expand Down
3 changes: 2 additions & 1 deletion meteor/treebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TreeBuilder(Session):
width: int
height: int
format: str | None
gtr: bool

def __post_init__(self) -> None:
if self.format not in TreeBuilder.OUTPUT_FORMATS:
Expand Down Expand Up @@ -103,7 +104,7 @@ def execute(self) -> None:
msp_file_list = self.concatenate(msp_file_dict)
# Compute phylogenies
phylogeny_process = Phylogeny(
self.meteor, msp_file_list, self.max_gap, self.min_info_sites
self.meteor, msp_file_list, self.max_gap, self.min_info_sites, self.gtr
)
phylogeny_process.execute()
# Analyze tree data
Expand Down

0 comments on commit 2893028

Please sign in to comment.