about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander_Kabui2025-03-07 15:59:12 +0300
committerAlexander_Kabui2025-03-07 15:59:55 +0300
commit90f66c80cf5316f68f1215c2bd4ce73132e22367 (patch)
tree00f0b7adeb09a192e8c158b19a9c9d0e49674f78
parentb83cc2fce9e181f4054bc4b1188b4299852fc839 (diff)
downloadgenenetwork3-90f66c80cf5316f68f1215c2bd4ce73132e22367.tar.gz
refactor: Construct map object from cross with columns (Marker, chr,cM, Mb).
-rw-r--r--scripts/rqtl2_wrapper.R28
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/rqtl2_wrapper.R b/scripts/rqtl2_wrapper.R
index 9d288af..92cfd52 100644
--- a/scripts/rqtl2_wrapper.R
+++ b/scripts/rqtl2_wrapper.R
@@ -160,6 +160,7 @@ perform_genetic_pr <- function(cross, cores = NO_OF_CORES, step = 1, map = NULL,
 
 # Insert pseudomarkers to the genetic map
 cat("Inserting pseudomarkers to the genetic map with step 1 and stepwidth fixed.\n")
+
 MAP <- insert_pseudomarkers(cross$gmap, step = 1, stepwidth = "fixed", cores = NO_OF_CORES)
 
 # Calculate genetic probabilities
@@ -307,12 +308,39 @@ get_qtl_effect <- function(chromosome, geno_prob, pheno, covar = NULL, LOCO = NU
 gmap_file <- file.path(opt$directory, json_data$geno_map_file)
 pmap_file <- file.path(opt$directory, json_data$physical_map_file)
 
+
+
+
+
+# Construct the Map object from cross with columns (Marker, chr, cM, Mb)
+gmap <- cross$gmap  # Genetic map in cM
+pmap <- cross$pmap  # Physical map in Mb
+# Convert lists to data frames
+gmap_df <- data.frame(
+  marker = unlist(lapply(gmap, names)), 
+  chr = rep(names(gmap), sapply(gmap, length)),  # Add chromosome info
+  CM = unlist(gmap), 
+  stringsAsFactors = FALSE
+)
+
+pmap_df <- data.frame(
+  marker = unlist(lapply(pmap, names)), 
+  chr = rep(names(pmap), sapply(pmap, length)),  # Add chromosome info
+  MB = unlist(pmap), 
+  stringsAsFactors = FALSE
+)
+# Merge using full outer join (by marker and chromosome)
+merged_map <- merge(gmap_df, pmap_df, by = c("marker", "chr"), all = TRUE)
+map_file <- file.path(opt$directory, "map.csv")
+write.csv(merged_map, map_file, row.names = FALSE)
+
 output <- list(
   permutation_file = permutation_results_file,
   significance_file = significance_results_file,
   scan_file = scan_file,
   gmap_file = gmap_file,
   pmap_file = pmap_file,
+  map_file  = map_file,
   permutations = NO_OF_PERMUTATION,
   scan_method = SCAN_METHOD
 )