diff options
Diffstat (limited to 'gn3/computations')
| -rw-r--r-- | gn3/computations/rqtl2.py | 26 |
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 { |
