Skip to content

Commit

Permalink
Convert seqnames and strand for generic use when exporting as pandas …
Browse files Browse the repository at this point in the history
…data frame (#82)

Also updated tests
  • Loading branch information
jkanche authored Apr 18, 2024
1 parent b3e59e1 commit 0546dbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/genomicranges/GenomicRanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,8 @@ def to_pandas(self) -> "pandas.DataFrame":
import pandas as pd

_rdf = self._ranges.to_pandas()
_rdf["seqnames"] = self._seqnames
_rdf["strand"] = self._strand
_rdf["seqnames"] = self.get_seqnames()
_rdf["strand"] = self.get_strand(as_type="list")

if self._names is not None:
_rdf.index = self._names
Expand Down
13 changes: 13 additions & 0 deletions tests/test_gr_methods_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,16 @@ def test_export():

assert df is not None
assert df.shape[0] == len(gr)
assert df["seqnames"].tolist() == [
"chr1",
"chr2",
"chr2",
"chr2",
"chr1",
"chr1",
"chr3",
"chr3",
"chr3",
"chr3",
]
assert df["strand"].tolist() == ["-", "+", "+", "*", "*", "+", "+", "+", "-", "-"]

0 comments on commit 0546dbd

Please sign in to comment.