Skip to content

Commit

Permalink
Addressing nils comments on sort order specification in SamBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Roach committed Dec 29, 2022
1 parent 1fa2209 commit 45ad823
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 0 additions & 2 deletions fgpyo/sam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,4 @@ class SamOrder(enum.Enum):
Unsorted = "unsorted" #: the SAM / BAM / CRAM is unsorted
Coordinate = "coordinate" #: coordinate sorted
QueryName = "queryname" #: queryname sorted
TemplateCoordinate = "unsorted" #: the sort order (@HD SO) is unsorted, the group order (GO)
#: is query, and the sub-sort (SS) is template-coordinate
Unknown = "unknown" # Unknown SAM / BAM / CRAM sort order
13 changes: 5 additions & 8 deletions fgpyo/sam/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def __init__(
`::class::~pysam.AlignmentHeader` for more details.
seed: a seed value for random number/string generation
sort_order: optional sort order, if `None` reads will be output in the same order as
they were appended. If `SamOrder.Coordinate`, reads will be ordered by reference
index and coordinate order. If `SamOrder.QueryName`, reads will be ordered by
query name. `SamOrder.TemplateCoordinate` is not currently supported.
they were appended.
"""

self.r1_len: int = r1_len if r1_len is not None else self.DEFAULT_R1_LENGTH
Expand All @@ -131,11 +129,10 @@ def __init__(
self.mapping_quality: int = mapping_quality

sort_order = SamOrder.Unsorted if sort_order is None else sort_order
assert sort_order in [
SamOrder.Coordinate,
SamOrder.QueryName,
SamOrder.Unsorted,
], "`sort_order for `SamBuilder` must be one of `Coordinate` `QueryName` or `Unsorted`"
assert sort_order in [SamOrder.Coordinate, SamOrder.QueryName, SamOrder.Unsorted], (
"`sort_order` for `SamBuilder` must be one of `Coordinate` `QueryName` or `Unsorted`."
+ f" Found {sort_order}"
)
self.sort_order: SamOrder = sort_order

self._header: Dict[str, Any] = {
Expand Down

0 comments on commit 45ad823

Please sign in to comment.