From 8e9a48caf995f3ed966f5a3c25a63c13794c0655 Mon Sep 17 00:00:00 2001 From: Chunmingl Date: Sun, 15 Sep 2024 02:55:53 -0400 Subject: [PATCH] update region info and study name handling --- code/pecotmr_integration/twas.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/pecotmr_integration/twas.ipynb b/code/pecotmr_integration/twas.ipynb index 67a131ae..6b3c0bdb 100644 --- a/code/pecotmr_integration/twas.ipynb +++ b/code/pecotmr_integration/twas.ipynb @@ -424,7 +424,7 @@ " library(IRanges)\n", " library(R6)\n", " library(pecotmr)\n", - " \n", + " \n", " LD_meta_file_path = \"${ld_meta_data}\"\n", " region_block <- unlist(strsplit(\"${_filtered_region_info[3]}\", \"_\\\\s*\"))\n", " chrom = as.integer(gsub(\"chr\", \"\", region_block[1]))\n", @@ -452,7 +452,7 @@ " weight_dbs <- weight_db_list_update[[gene_db]]\n", " twas_weights_results[[gene_db]] = generate_twas_db(weight_dbs, contexts=NULL,variable_name_obj=c(\"variant_names\"), susie_obj=\"susie_weights_intermediate\",\n", " twas_weights_table = \"twas_weights\", min_rsq_threshold = ${rsq_threshold}, \n", - " p_val_cutoff = ${p_value_cutoff}, data_type_table=xqtl_type_table)\n", + " p_val_cutoff = ${p_value_cutoff}, data_type_table=xqtl_type_table, region_name=gene_db)\n", " if (gene_db %in% names(twas_weights_results)){\n", " # merge and update export_twas_weights_db for imputable genes, merge if same gene's other context results are available \n", " if (!is.null(twas_weights_results[[gene_db]])){\n", @@ -476,7 +476,7 @@ " twas_contexts <- do.call(rbind, lapply(gwas_studies, function(study){\n", " twas_rs <- twas_analysis(twas_data_qced[[gene]][[\"weights_qced\"]][[context]], twas_data_qced[[gene]][[\"gwas_qced\"]][[study]], \n", " twas_data_qced[[gene]][[\"LD\"]], rownames(twas_data_qced[[gene]][[\"weights_qced\"]][[context]]))\n", - " context_table <- data.frame(gwas_study=study, method=gsub( \"_.*$\", \"\",names(twas_rs)), twas_z=find_data(twas_rs, c(2, \"z\")),\n", + " context_table <- data.frame(gwas_study=study, method=sub(\"_[^_]+$\", \"\",names(twas_rs)), twas_z=find_data(twas_rs, c(2, \"z\")),\n", " twas_pval=find_data(twas_rs, c(2, \"pval\")))\n", " return(context_table)\n", " }))\n", @@ -497,7 +497,7 @@ " function(file){if(twas_weights_results[[file]]$gene == gene) twas_weights_results[[file]]$cv_performance}))\n", " # loop through each context for all methods\n", " gene_table <- do.call(rbind, lapply(contexts, function(context){\n", - " methods <- gsub(\"_.*$\", \"\", names(cv_data[[context]]))\n", + " methods <- sub(\"_[^_]+$\", \"\",names(cv_data[[context]]))\n", " is_imputable = export_twas_weights_db[[\"${_filtered_region_info[3]}\"]][[gene]][[context]]$is_imputable\n", " selected_method = export_twas_weights_db[[\"${_filtered_region_info[3]}\"]][[gene]][[context]]$selected_model\n", " if(is.null(selected_method)) selected_method <- NA\n",