From 6b02a7e1f46c9010ff76cd2df254d5bb1dbf833c Mon Sep 17 00:00:00 2001 From: JoseCorCab Date: Thu, 23 May 2024 11:31:50 +0200 Subject: [PATCH] Add_mirna_mature and add_annotation have been merged --- inst/scripts/add_annotation.R | 29 ++++++++++++++++------ inst/scripts/add_mirna_mature.R | 44 --------------------------------- 2 files changed, 22 insertions(+), 51 deletions(-) delete mode 100755 inst/scripts/add_mirna_mature.R diff --git a/inst/scripts/add_annotation.R b/inst/scripts/add_annotation.R index aaf21ba..1fc190d 100755 --- a/inst/scripts/add_annotation.R +++ b/inst/scripts/add_annotation.R @@ -11,7 +11,7 @@ if( Sys.getenv('DEGHUNTER_MODE') == 'DEVELOPMENT' ){ organisms_table_file <- file.path(root_path, "inst","external_data", "organism_table.txt") # Load custom libraries - custom_libraries <- c('functional_analysis_library.R') + custom_libraries <- c('functional_analysis_library.R', 'miRNA_RNA_functions.R') for (lib in custom_libraries){ source(file.path(root_path, 'R', lib)) } @@ -35,6 +35,8 @@ option_list <- list( help="Define the output path. Default = %default"), optparse::make_option(c("-c", "--column"), type="character", default=1, help="Column name or index with ensembl_IDs. Default = %default"), + optparse::make_option(c("-m", "--mirna"), type= "logical", default = FALSE, action ="store_true", + help= "Indicate if the ids to translate are miRNA (from miRBase to mature ID). If activated, -I and -K are ignored"), optparse::make_option(c("-I", "--input_keytype"), type="character", default=NULL, help="Set the input keytype. Default=%default : All possible keytypes will be printed"), optparse::make_option(c("-K", "--output_keytype"), type="character", default="SYMBOL", @@ -52,12 +54,25 @@ if (grepl("[0-9]+", opt$column)) opt$column <- as.numeric(opt$column) table_to_annot <- read.table(opt$input_file, sep = "\t", header = TRUE) -translated_keytypes <- translate_ids_orgdb(ids = table_to_annot[,opt$column], - input_id=opt$input_keytype, output_id = opt$output_keytype, org_db=org_db) +if (opt$column == "rownames") { + ids_to_translate <- rownames(table_to_annot) +} else { + ids_to_translate <- table_to_annot[,opt$column] +} + +if (opt$mirna) { + + table_to_annot$miRNA_name <- translate_miRNA_ids(ids_to_translate) -translated_ids <- translated_keytypes[match(table_to_annot[,opt$column], - translated_keytypes[,opt$input_keytype]) ,opt$output_keytype] +} else { -table_to_annot[,opt$output_keytype] <- translated_ids + translated_keytypes <- translate_ids_orgdb(ids = ids_to_translate, + input_id=opt$input_keytype, output_id = opt$output_keytype, org_db=org_db) + + translated_ids <- translated_keytypes[match(ids_to_translate, + translated_keytypes[,opt$input_keytype]) ,opt$output_keytype] + + table_to_annot[,opt$output_keytype] <- translated_ids +} -write.table(table_to_annot, sep = "\t", quote = FALSE, row.names = FALSE, file = opt$output_file) \ No newline at end of file +write.table(table_to_annot, sep = "\t", quote = FALSE, row.names = (opt$column == "rownames"), file = opt$output_file) \ No newline at end of file diff --git a/inst/scripts/add_mirna_mature.R b/inst/scripts/add_mirna_mature.R deleted file mode 100755 index 2c7dd6d..0000000 --- a/inst/scripts/add_mirna_mature.R +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env Rscript - -option_list <- list( - optparse::make_option(c("-i", "--input_file"), type="character", default=NULL, - help="DEgenesHunter results table"), - optparse::make_option(c("-o", "--output_file"), type="character", default='./', - help="Define the output path. Default = './'") -) - -if( Sys.getenv('DEGHUNTER_MODE') == 'DEVELOPMENT' ){ - - full.fpath <- tryCatch(normalizePath(parent.frame(2)$ofile), - error=function(e) # works when using R CMD - normalizePath(unlist(strsplit(commandArgs()[grep('^--file=', - commandArgs())], '='))[2])) - main_path_script <- dirname(full.fpath) - root_path <- file.path(main_path_script, '..', '..') - custom_libraries <- c("miRNA_RNA_functions.R") - for (lib in custom_libraries){ - source(file.path(root_path, 'R', lib)) - } - template_folder <- file.path(root_path, 'inst', 'templates') - organism_table_path <- file.path(root_path,"inst","external_data", - "organism_table.txt") - -} else { - require('ExpHunterSuite') - root_path <- find.package('ExpHunterSuite') - template_folder <- file.path(root_path, 'templates') - organism_table_path <- file.path(root_path, "inst","external_data", - "organism_table.txt") -} - - - -opt <- optparse::parse_args(optparse::OptionParser(option_list=option_list)) - -original_table <- read.table(opt$input_file,header=TRUE, row.names=1, sep="\t") - -annotated_table <- original_table - -annotated_table$miRNA_name <- translate_miRNA_ids(rownames(annotated_table)) - -write.table(annotated_table, file.path(opt$output_file, "hunter_results_table_translated.txt"), quote=FALSE, row.names=TRUE, sep="\t")