Mercurial > repos > artbio > cnv_facets
comparison facets_analysis.R @ 3:d1914f4d9daf draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
| author | artbio |
|---|---|
| date | Sun, 05 Oct 2025 00:55:34 +0000 |
| parents | 66a56502199d |
| children | 3f62267c4be7 |
comparison
equal
deleted
inserted
replaced
| 2:66a56502199d | 3:d1914f4d9daf |
|---|---|
| 4 # This script serves as the backend for the Galaxy FACETS Analysis tool. | 4 # This script serves as the backend for the Galaxy FACETS Analysis tool. |
| 5 # It takes a SNP pileup file as input and performs allele-specific copy | 5 # It takes a SNP pileup file as input and performs allele-specific copy |
| 6 # number analysis using the R package 'facets'. | 6 # number analysis using the R package 'facets'. |
| 7 # ============================================================================== | 7 # ============================================================================== |
| 8 | 8 |
| 9 # --- 1. Load Libraries --- | 9 # --- Load Libraries --- |
| 10 suppressPackageStartupMessages(library(argparse)) | 10 suppressPackageStartupMessages(library(argparse)) |
| 11 suppressPackageStartupMessages(library(facets)) | 11 suppressPackageStartupMessages(library(facets)) |
| 12 | 12 |
| 13 # --- 2. Define and Parse Arguments --- | 13 # --- Source the external plot_facets_enhanced function --- |
| 14 # This finds the path of the currently running script and sources | |
| 15 # the R function file relative to it. | |
| 16 initial_opts <- commandArgs(trailingOnly = FALSE) | |
| 17 script_path <- dirname(sub("--file=", "", initial_opts[grep("--file=", initial_opts)])) | |
| 18 source(file.path(script_path, "plot_facets_enhanced-v22.R")) | |
| 19 | |
| 20 # --- Define and Parse Arguments --- | |
| 14 | 21 |
| 15 # Create the parser | 22 # Create the parser |
| 16 parser <- ArgumentParser(description = "Run FACETS algorithm on a SNP pileup file.") | 23 parser <- ArgumentParser(description = "Run FACETS algorithm on a SNP pileup file.") |
| 17 | 24 |
| 18 # Define arguments | 25 # Define arguments |
| 33 type = "character", required = TRUE, | 40 type = "character", required = TRUE, |
| 34 help = "Path for the output summary file (TSV)." | 41 help = "Path for the output summary file (TSV)." |
| 35 ) | 42 ) |
| 36 parser$add_argument("--output_plots", | 43 parser$add_argument("--output_plots", |
| 37 type = "character", required = TRUE, | 44 type = "character", required = TRUE, |
| 38 help = "Path for the output plots file (PDF)." | 45 help = "Path for the main output plots file (PNG)." |
| 39 ) | 46 ) |
| 40 | 47 parser$add_argument("--output_spider", |
| 48 type = "character", required = TRUE, | |
| 49 help = "Path for the diagnostic spider plot file (PNG)." | |
| 50 ) | |
| 41 parser$add_argument("--cval", | 51 parser$add_argument("--cval", |
| 42 type = "double", default = 150, | 52 type = "double", default = 150, |
| 43 help = "Critical value for segmentation." | 53 help = "Critical value for segmentation." |
| 44 ) | 54 ) |
| 45 parser$add_argument("--min_nhet", | 55 parser$add_argument("--min_nhet", |
| 54 type = "character", default = "hg38", | 64 type = "character", default = "hg38", |
| 55 choices = c("hg19", "hg38", "hg18", "mm9", "mm10"), | 65 choices = c("hg19", "hg38", "hg18", "mm9", "mm10"), |
| 56 help = "Genome build used for alignment." | 66 help = "Genome build used for alignment." |
| 57 ) | 67 ) |
| 58 | 68 |
| 59 # --- 3. Main Analysis Function --- | 69 # --- Main Analysis Function --- |
| 60 main <- function(args) { | 70 main <- function(args) { |
| 61 # Set seed for reproducibility | 71 # Set seed for reproducibility |
| 62 set.seed(1965) | 72 set.seed(1965) |
| 63 | 73 |
| 64 # --- Read the data with readSnpMatrix() from facets --- | 74 # --- Read the data with readSnpMatrix() from facets --- |
| 102 args$gbuild | 112 args$gbuild |
| 103 ) | 113 ) |
| 104 ) | 114 ) |
| 105 write.table(summary_df, file = args$output_summary, sep = "\t", quote = FALSE, row.names = FALSE) | 115 write.table(summary_df, file = args$output_summary, sep = "\t", quote = FALSE, row.names = FALSE) |
| 106 | 116 |
| 107 # Generate the plots PDF | 117 # Generate the plots PNG |
| 108 pdf(file = args$output_plots, width = 12, height = 8) | 118 png(file = args$output_plots, width = 12, height = 8, units = "in", res = 300) |
| 109 plotSample(x = oo, emfit = fit, sname = args$sample_id) | 119 plotSample(x = oo, emfit = fit, sname = args$sample_id) |
| 120 plot_facets_enhanced(oo, emfit = fit, plot.type = "em", sname = args$sample_id) | |
| 121 dev.off() | |
| 122 png(file = args$output_spider, width = 8, height = 8, units = "in", res = 300) | |
| 123 logRlogORspider(oo$out, oo$dipLogR) | |
| 110 dev.off() | 124 dev.off() |
| 111 } | 125 } |
| 112 | 126 |
| 113 # --- 4. Execution Block --- | 127 # --- Execution Block --- |
| 114 if (!interactive()) { | 128 if (!interactive()) { |
| 115 args <- parser$parse_args() | 129 args <- parser$parse_args() |
| 116 main(args) | 130 main(args) |
| 117 } | 131 } |
