Skip to content

Commit

Permalink
Add SNP.info property and call it from Tree.query_snp_path (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpoznik authored Feb 23, 2024
1 parent 62e60bb commit 9aa74a2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

No unreleased changes

[Unreleased]: https://github.com/23andMe/yhaplo/compare/2.1.6..HEAD
[Unreleased]: https://github.com/23andMe/yhaplo/compare/2.1.7..HEAD


## [2.1.7] - 2024-02-23

### Added
- `SNP.info` property, called from `Tree.query_snp_path`

[2.1.7]: https://github.com/23andMe/yhaplo/compare/2.1.6..2.1.7


## [2.1.6] - 2024-02-07
Expand Down Expand Up @@ -73,7 +81,7 @@ and faster processing of most input types.
- BCF support
- Automated tests
- Optional dependencies
- `Sample` subclasses: `TextSample`, `VCFSample`, `AblockSample`
- `Sample` subclasses: `TextSample`, `VCFSample`
- `CHANGELOG.md`

### Changed
Expand Down
7 changes: 4 additions & 3 deletions yhaplo/api/command_line_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def get_command_line_args(set_defaults: bool = False) -> argparse.Namespace:
action="store_true",
help="Generate all auxiliary output.\n"
"Equivalent to these seven options:\n"
"--ancDerCounts --haplogroupPaths --haplogroupPathsDetail\n"
"--derSNPs --derSNPsDetail --ancSNPs --ancSNPsDetail",
"--anc_der_counts --haplogroup_paths --haplogroup_paths_detail\n"
"--der_snps --der_snps_detail --anc_snps --anc_snps_detail",
)
group.add_argument(
"-c",
Expand Down Expand Up @@ -204,7 +204,8 @@ def get_command_line_args(set_defaults: bool = False) -> argparse.Namespace:
"--snp_query",
dest="query_snp_names",
metavar="snp_names",
help="List phylogenetic path for each SNP in comma-separated list",
help="For each SNP in comma-separated list, output properties\n"
"and the phylogenetic path to the haplogroup it is associated with",
)
group.add_argument(
"-pt",
Expand Down
1 change: 0 additions & 1 deletion yhaplo/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Sample
* TextSample
* VCFSample
* AblockSample
"""

Expand Down
19 changes: 17 additions & 2 deletions yhaplo/snp.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ def __str__(self) -> str:
f"{self.ancestral}->{self.derived}"
)

@property
def info(self) -> str:
"""Return multiline summary of SNP."""

names = [name for name in self.name_list if name != self.label]
aliases_str = ", ".join(names) if names else "None"
info = (
f"Name: {self.label}\n"
f"YCC haplogroup: {self.node.label}\n"
f"GRCh37 position: {self.position:,}\n"
f"Mutation: {self.ancestral}->{self.derived}\n"
f"Aliases: {aliases_str}"
)
return info

@property
def str_with_all_names(self) -> str:
"""Return long string representation.
Expand All @@ -133,8 +148,8 @@ def str_with_all_names(self) -> str:
plus a comma-separated list of names.
"""
names = ",".join(self.name_list)
str_with_all_names = f"{str(self)} {names}"
names_str = ",".join(self.name_list)
str_with_all_names = f"{str(self)} {names_str}"
return str_with_all_names

@property
Expand Down
1 change: 1 addition & 0 deletions yhaplo/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def query_snp_path(self, query_snp_name: str) -> None:
snp = self.snp_dict.get(query_snp_name)

if snp:
logger.info(f"{snp.info}\n")
for node in snp.back_trace_path():
logger.info(node.str_simple)

Expand Down

0 comments on commit 9aa74a2

Please sign in to comment.