Skip to content

Commit

Permalink
More doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Feb 1, 2025
1 parent 75278d0 commit 790e736
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
18 changes: 15 additions & 3 deletions yclade/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_node_match_info(
def get_all_nodes_match_info(
tree: YTreeData, snps: SnpResults
) -> dict[CladeName, CladeMatchInfo]:
"""Find the nodes in the tree that have overlap with postive or negative SNPs."""
"""Get the match info for all nodes in the tree."""
node_info = {}
for clade, clade_snps in tree.clade_snps.items():
if len(clade_snps) == 0:
Expand All @@ -53,7 +53,16 @@ def get_node_path_scores(
snps: SnpResults,
scoring_function: Callable[[CladeMatchInfo], float],
) -> dict[CladeName, float]:
"""Get the score for a single node."""
"""Get the score for a single node's path (from the root to the node).
Args:
tree: The YTreeData object.
node: The ID of the node to score.
snps: The SnpResults to use for scoring.
scoring_function: The scoring function to use.
The scoring function should take a CladeMatchInfo object and return a number.
"""
scores = {}
for ancestor_node in nx.ancestors(tree.graph, node):
match_info = get_node_match_info(tree=tree, node=ancestor_node, snps=snps)
Expand All @@ -69,7 +78,10 @@ def simple_scoring_function(match_info: CladeMatchInfo) -> float:


def get_ordered_clade_details(tree: YTreeData, snps: SnpResults) -> list[CladeInfo]:
"""Get an ordered list of clades with their match info."""
"""Get an ordered list of clades with their match info.
The first clade in the list is the best match.
"""
candidates = find_nodes_with_positive_matches(tree=tree, snps=snps)
candidate_scores = {}
for node in candidates:
Expand Down
10 changes: 9 additions & 1 deletion yclade/snps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@


def parse_snp_results(snp_string: str) -> SnpResults:
"""Parse a string of comma separate SNPs into SnpResults."""
"""Parse a string of comma separated SNPs into SnpResults.
Args:
snp_string: A string of comma separated SNPs.
The SNPs can be separated by commas and, optionally, spaces.
All SNPs must have the form snp+ (for a positively tested SNP)
or snp- (for a negatively tested SNP), otherwise they are ignored.
"""
snps = [snp.strip() for snp in snp_string.split(",")]
positive_snps = {snp.rstrip("+") for snp in snps if snp.endswith("+")}
negative_snps = {snp.rstrip("-") for snp in snps if snp.endswith("-")}
Expand Down

0 comments on commit 790e736

Please sign in to comment.