Skip to content

Commit 9aa74a2

Browse files
authored
Add SNP.info property and call it from Tree.query_snp_path (#28)
1 parent 62e60bb commit 9aa74a2

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

CHANGELOG.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
77

88
No unreleased changes
99

10-
[Unreleased]: https://github.com/23andMe/yhaplo/compare/2.1.6..HEAD
10+
[Unreleased]: https://github.com/23andMe/yhaplo/compare/2.1.7..HEAD
11+
12+
13+
## [2.1.7] - 2024-02-23
14+
15+
### Added
16+
- `SNP.info` property, called from `Tree.query_snp_path`
17+
18+
[2.1.7]: https://github.com/23andMe/yhaplo/compare/2.1.6..2.1.7
1119

1220

1321
## [2.1.6] - 2024-02-07
@@ -73,7 +81,7 @@ and faster processing of most input types.
7381
- BCF support
7482
- Automated tests
7583
- Optional dependencies
76-
- `Sample` subclasses: `TextSample`, `VCFSample`, `AblockSample`
84+
- `Sample` subclasses: `TextSample`, `VCFSample`
7785
- `CHANGELOG.md`
7886

7987
### Changed

yhaplo/api/command_line_args.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def get_command_line_args(set_defaults: bool = False) -> argparse.Namespace:
9292
action="store_true",
9393
help="Generate all auxiliary output.\n"
9494
"Equivalent to these seven options:\n"
95-
"--ancDerCounts --haplogroupPaths --haplogroupPathsDetail\n"
96-
"--derSNPs --derSNPsDetail --ancSNPs --ancSNPsDetail",
95+
"--anc_der_counts --haplogroup_paths --haplogroup_paths_detail\n"
96+
"--der_snps --der_snps_detail --anc_snps --anc_snps_detail",
9797
)
9898
group.add_argument(
9999
"-c",
@@ -204,7 +204,8 @@ def get_command_line_args(set_defaults: bool = False) -> argparse.Namespace:
204204
"--snp_query",
205205
dest="query_snp_names",
206206
metavar="snp_names",
207-
help="List phylogenetic path for each SNP in comma-separated list",
207+
help="For each SNP in comma-separated list, output properties\n"
208+
"and the phylogenetic path to the haplogroup it is associated with",
208209
)
209210
group.add_argument(
210211
"-pt",

yhaplo/sample.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* Sample
55
* TextSample
66
* VCFSample
7-
* AblockSample
87
98
"""
109

yhaplo/snp.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ def __str__(self) -> str:
125125
f"{self.ancestral}->{self.derived}"
126126
)
127127

128+
@property
129+
def info(self) -> str:
130+
"""Return multiline summary of SNP."""
131+
132+
names = [name for name in self.name_list if name != self.label]
133+
aliases_str = ", ".join(names) if names else "None"
134+
info = (
135+
f"Name: {self.label}\n"
136+
f"YCC haplogroup: {self.node.label}\n"
137+
f"GRCh37 position: {self.position:,}\n"
138+
f"Mutation: {self.ancestral}->{self.derived}\n"
139+
f"Aliases: {aliases_str}"
140+
)
141+
return info
142+
128143
@property
129144
def str_with_all_names(self) -> str:
130145
"""Return long string representation.
@@ -133,8 +148,8 @@ def str_with_all_names(self) -> str:
133148
plus a comma-separated list of names.
134149
135150
"""
136-
names = ",".join(self.name_list)
137-
str_with_all_names = f"{str(self)} {names}"
151+
names_str = ",".join(self.name_list)
152+
str_with_all_names = f"{str(self)} {names_str}"
138153
return str_with_all_names
139154

140155
@property

yhaplo/tree.py

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def query_snp_path(self, query_snp_name: str) -> None:
239239
snp = self.snp_dict.get(query_snp_name)
240240

241241
if snp:
242+
logger.info(f"{snp.info}\n")
242243
for node in snp.back_trace_path():
243244
logger.info(node.str_simple)
244245

0 commit comments

Comments
 (0)