aboutsummaryrefslogtreecommitdiff
path: root/r_qtl
diff options
context:
space:
mode:
Diffstat (limited to 'r_qtl')
-rw-r--r--r_qtl/r_qtl2.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index 26d6dd4..a221f26 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -65,20 +65,27 @@ def genotype_data(zfile: ZipFile, cdata: dict) -> Iterator[dict]:
def map_data(zfile: ZipFile, map_type: str, cdata: dict) -> dict:
"""Read gmap files to get the genome mapping data"""
assert map_type in ("genetic-map", "physical-map"), "Invalid map type"
- map_key = {"genetic-map": "gmap", "physical-map": "pmap"}[map_type]
- if not cdata.get("geno_transposed", False):
- with zfile.open(cdata[map_key]) as gmapfile:
+ map_file = cdata[{
+ "genetic-map": "gmap",
+ "physical-map": "pmap"
+ }[map_type]]
+ # TODO: Might need to check `gmap_transposed` and `pmap_transposed` instead
+ # of `geno_transposed` -- see
+ # https://github.com/rqtl/qtl2data/blob/main/ArabMAGIC/arabmagic_tair8.json
+ # for the *_transposed values
+ transposed_dict = {
+ "genetic-map": "gmap_transposed",
+ "physical-map": "pmap_transposed"
+ }
+ if not cdata.get(transposed_dict[map_type], False):
+ with zfile.open(map_file) as gmapfile:
reader = csv.DictReader(
filter(lambda line: not line.startswith("#"),
io.TextIOWrapper(gmapfile)),
delimiter=cdata.get("sep", ","))
- return {
- line["marker"]: {
- key: value for key,value in line.items() if key != "marker"
- } for line in reader
- }
+ return tuple(row for row in reader)
- with zfile.open(cdata["gmap"]) as gmapfile:
+ with zfile.open(map_file) as gmapfile:
lines = [[field.strip() for field in
line.strip().split(cdata.get("sep", ","))]
for line in
@@ -87,11 +94,9 @@ def map_data(zfile: ZipFile, map_type: str, cdata: dict) -> dict:
headers = tuple(line[0] for line in lines)
return reduce(
- lambda gmap, row: {
- **gmap,
- row[0]: dict(zip(headers[1:], row[1:]))},
+ lambda gmap, row: gmap + (dict(zip(headers, row)),),
zip(*(line[1:] for line in lines)),
- {})
+ tuple())
def read_r_qtl2_files(filepath: Path):
"""Read R/qtl2 format zip files."""