about summary refs log tree commit diff
path: root/gn3/computations
diff options
context:
space:
mode:
authorAlexander_Kabui2025-02-05 12:13:25 +0300
committerBonfaceKilz2025-02-06 12:43:15 +0300
commit46841d8afc75c1b945af66e486aad3711a4cac5f (patch)
tree5ade6b5f7f290d4e0b1cc2dd9cdd400d89ccdb4c /gn3/computations
parenta3052281899a96b6be853582e9bdc5486a78a803 (diff)
downloadgenenetwork3-46841d8afc75c1b945af66e486aad3711a4cac5f.tar.gz
feat: Include the physical map position in results.
Diffstat (limited to 'gn3/computations')
-rw-r--r--gn3/computations/rqtl2.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/gn3/computations/rqtl2.py b/gn3/computations/rqtl2.py
index 0fd8a7f..02dc621 100644
--- a/gn3/computations/rqtl2.py
+++ b/gn3/computations/rqtl2.py
@@ -174,25 +174,37 @@ def fetch_significance_results(file_path: str):
 
 
 def process_scan_results(qtl_file_path: str,
-                         gmap_file_path: str) -> List[Dict[str, str]]:
+                         pmap_file_path: str,
+                         gmap_file_path: str) -> List[Dict[str, Any]]:
     """Function to process genome scanning results and obtain marker_name, Lod score,
     marker_position, and chromosome.
     Args:
         qtl_file_path (str): Path to the QTL scan results CSV file.
+        pmap_file_path (str): Path to the physical map CSV file.
         gmap_file_path (str): Path to the genetic map CSV file.
 
     Returns:
         List[Dict[str, str]]: A list of dictionaries containing the marker data.
     """
     gmap = {}
+    # read the genetic map
     with open(gmap_file_path, "r", encoding="utf-8") as file_handler:
         reader = csv.reader(file_handler)
         next(reader)
         for line in reader:
             marker, chr_, position = line
-            gmap[marker] = {"chr": chr_, "position": position}
+            gmap[marker] = {"chr": chr_, "cM": float(position), "Mb" : 0}
 
-    # Process QTL scan results and merge with the gmap data
+   # read the physcical map
+    with open(pmap_file_path, "r", encoding="utf-8") as file_handler:
+        reader = csv.reader(file_handler)
+        next(reader)
+        for line in reader:
+            marker, chr_, position = line
+            if marker in gmap:
+                gmap[marker]["Mb"] = float(position)
+
+    # Process QTL scan results and merge the positional data
     results = []
     with open(qtl_file_path, encoding="utf-8") as file_handler:
         reader = csv.reader(file_handler)
@@ -202,8 +214,8 @@ def process_scan_results(qtl_file_path: str,
             lod_score = line[1]
             results.append({
                 "name": marker,
-                "lod_score": lod_score,
-                **gmap.get(marker, {})  # Add chromosome and position if available
+                "lod_score": float(lod_score),
+                **gmap.get(marker, {})  # Add chromosome and positions if available
             })
     return results
 
@@ -218,7 +230,9 @@ def process_qtl2_results(output_file: str) -> Dict[str, Any]:
             and permutation results along with input data.
     """
     results  = read_output_file(output_file)
-    qtl_results = process_scan_results(results["scan_file"], results["gmap_file"])
+    qtl_results = process_scan_results(results["scan_file"],
+                                       results["pmap_file"],
+                                       results["gmap_file"])
     permutation_results = process_permutation(results)
 
     return {