Mercurial > repos > petr-novak > dante_ltr
annotate detect_putative_ltr.R @ 12:ff01d4263391 draft
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
author | petr-novak |
---|---|
date | Thu, 21 Jul 2022 08:23:15 +0000 |
parents | |
children | 559940c04c44 |
rev | line source |
---|---|
12
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
1 #!/usr/bin/env Rscript |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
2 initial_options <- commandArgs(trailingOnly = FALSE) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
3 file_arg_name <- "--file=" |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
4 script_name <- normalizePath(sub(file_arg_name, "", initial_options[grep(file_arg_name, initial_options)])) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
5 script_dir <- dirname(script_name) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
6 library(optparse) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
7 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
8 parser <- OptionParser() |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
9 option_list <- list( |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
10 make_option(c("-g", "--gff3"), action = "store", type = "character", |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
11 help = "gff3 with dante results", default = NULL), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
12 make_option(c("-s", "--reference_sequence"), action = "store", type = "character", |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
13 help = "reference sequence as fasta", default = NULL), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
14 make_option(c("-o", "--output"), action = "store", type = "character", |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
15 help = "output file path and prefix", default = NULL), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
16 make_option(c("-c", "--cpu"), type = "integer", default = 5, |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
17 help = "Number of cpu to use [default %default]", metavar = "number"), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
18 make_option(c("-M", "--max_missing_domains"), type = "integer", default = 0, |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
19 help = "Maximum number of missing domains is retrotransposon [default %default]", |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
20 metavar = "number"), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
21 make_option(c("-L", "--min_relative_length"), type = "numeric", default = 0.6, |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
22 help = "Minimum relative length of protein domain to be considered for retrostransposon detection [default %default]", |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
23 metavar = "number") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
24 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
25 ) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
26 description <- paste(strwrap("")) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
27 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
28 epilogue <- "" |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
29 parser <- OptionParser(option_list = option_list, epilogue = epilogue, description = description, |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
30 usage = "usage: %prog COMMAND [OPTIONS]") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
31 opt <- parse_args(parser, args = commandArgs(TRUE)) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
32 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
33 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
34 # load packages |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
35 suppressPackageStartupMessages({ |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
36 library(rtracklayer) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
37 library(Biostrings) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
38 library(BSgenome) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
39 library(parallel) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
40 }) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
41 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
42 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
43 # CONFIGURATION |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
44 OFFSET <- 15000 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
45 # load configuration files and functions: |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
46 lineage_file <- paste0(script_dir, "/databases/lineage_domain_order.csv") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
47 FDM_file <- paste0(script_dir, "/databases/feature_distances_model.RDS") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
48 trna_db <- paste0(script_dir, "/databases/tRNAscan-SE_ALL_spliced-no_plus-old-tRNAs_UC_unique-3ends.fasta") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
49 ltr_utils_r <- paste0(script_dir, "/R/ltr_utils.R") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
50 if (file.exists(lineage_file) & file.exists(trna_db)) { |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
51 lineage_info <- read.table(lineage_file, sep = "\t", header = TRUE, as.is = TRUE) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
52 FDM <- readRDS(FDM_file) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
53 source(ltr_utils_r) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
54 }else { |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
55 # this destination work is installed using conda |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
56 lineage_file <- paste0(script_dir, "/../share/dante_ltr/databases/lineage_domain_order.csv") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
57 FDM_file <- paste0(script_dir, "/../share/dante_ltr/databases/feature_distances_model.RDS") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
58 trna_db <- paste0(script_dir, "/../share/dante_ltr/databases/tRNAscan-SE_ALL_spliced-no_plus-old-tRNAs_UC_unique-3ends.fasta") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
59 ltr_utils_r <- paste0(script_dir, "/../share/dante_ltr/R/ltr_utils.R") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
60 if (file.exists(lineage_file) & file.exists((trna_db))) { |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
61 lineage_info <- read.table(lineage_file, sep = "\t", header = TRUE, as.is = TRUE) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
62 source(ltr_utils_r) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
63 FDM <- readRDS(FDM_file) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
64 }else( |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
65 stop("configuration files not found") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
66 ) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
67 } |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
68 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
69 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
70 # for testing |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
71 if (FALSE) { |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
72 g <- rtracklayer::import("/mnt/raid/454_data/cuscuta/Ceuropea_assembly_v4/0_final_asm_hifiasm+longstitch/repeat_annotation/DANTE_on_CEUR_filtered_short_names.gff3") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
73 s <- readDNAStringSet("/mnt/raid/454_data/cuscuta/Ceuropea_assembly_v4/0_final_asm_hifiasm+longstitch/asm.bp.p.ctg_scaffolds.short_names.fa") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
74 lineage_info <- read.table("/mnt/raid/users/petr/workspace/ltr_finder_test/lineage_domain_order.csv", sep = "\t", header = TRUE, as.is = TRUE) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
75 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
76 g <- rtracklayer::import("/mnt/raid/users/petr/workspace/dante_ltr/test_data/sample_DANTE_unfiltered.gff3") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
77 g <- rtracklayer::import("/mnt/raid/users/petr/workspace/ltr_finder_test/test_data/DANTE_filtered_part.gff3") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
78 s <- readDNAStringSet("/mnt/raid/users/petr/workspace/ltr_finder_test/test_data/Rbp_part.fa") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
79 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
80 # oriza |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
81 g <- rtracklayer::import("/mnt/raid/users/petr/workspace/dante_ltr/test_data/big_test_data/DANTE_full_oryza.gff3") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
82 s <- readDNAStringSet("/mnt/raid/users/petr/workspace/dante_ltr/test_data/big_test_data/o_sativa_msu7.0.fasta") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
83 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
84 g <- rtracklayer::import("/mnt/raid/users/petr/workspace/dante_ltr/test_data |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
85 /DANTE_Vfaba_chr5.gff3") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
86 s <- readDNAStringSet("/mnt/ceph/454_data/Vicia_faba_assembly/assembly/ver_210910 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
87 /fasta_parts/211010_Vfaba_chr5.fasta") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
88 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
89 g <- rtracklayer::import("/mnt/raid/users/petr/workspace/dante_ltr/test_data/big_test_data//Cocoa_theobroma_DANTE_filtered.gff3") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
90 s <- readDNAStringSet("/mnt/raid/users/petr/workspace/dante_ltr/test_data/big_test_data/Cocoa_theobroma_chr1.fasta.gz") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
91 # test on bigger data: |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
92 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
93 g <- rtracklayer::import("/mnt/raid/users/petr/workspace/dante_ltr/test_data/tmp/DANTE_unfiltered/1.gff3") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
94 s <- readDNAStringSet("/mnt/raid/users/petr/workspace/dante_ltr/test_data/tmp/fasta_parts/1.fasta") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
95 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
96 source("R/ltr_utils.R") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
97 ## feature distance model |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
98 FDM <- readRDS("./databases/feature_distances_model.RDS") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
99 g <- rtracklayer::import("./test_data/sample_DANTE.gff3") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
100 s <- readDNAStringSet("./test_data/sample_genome.fasta") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
101 outfile <- "/mnt/raid/users/petr/workspace/ltr_finder_test/te_with_domains_2.gff3" |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
102 lineage_info <- read.table("databases/lineage_domain_order.csv", sep = "\t", header = |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
103 TRUE, as.is = TRUE) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
104 trna_db <- "./databases/tRNAscan-SE_ALL_spliced-no_plus-old-tRNAs_UC_unique-3ends.fasta" |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
105 opt <- list(min_relative_length=0.6, cpu = 8) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
106 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
107 } |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
108 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
109 # MAIN ############################################################# |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
110 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
111 # load data: |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
112 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
113 cat("reading gff...") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
114 g <- rtracklayer::import(opt$gff3, format = 'gff3') # DANTE gff3 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
115 cat("done\n") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
116 cat("reading fasta...") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
117 s <- readDNAStringSet(opt$reference_sequence) # genome assembly |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
118 cat("done\n") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
119 outfile <- opt$output |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
120 # clean sequence names: |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
121 names(s) <- gsub(" .+", "", names(s)) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
122 lineage_domain <- lineage_info$Domains.order |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
123 lineage_domain_span <- lineage_info$domain_span |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
124 lineage_ltr_mean_length <- lineage_info$ltr_length |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
125 lineage_offset5prime <- lineage_info$offset5prime |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
126 lineage_offset3prime <- lineage_info$offset3prime |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
127 ln <- gsub("ss/I", "ss_I", gsub("_", "/", gsub("/", "|", lineage_info$Lineage))) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
128 names(lineage_offset3prime) <- ln |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
129 names(lineage_offset5prime) <- ln |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
130 names(lineage_domain) <- ln |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
131 names(lineage_domain_span) <- ln |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
132 names(lineage_ltr_mean_length) <- ln |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
133 lineage_domains_sequence <- unlist(mapply(function(d,l) { |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
134 paste(strsplit(d, " ")[[1]], ":", l, sep = "") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
135 }, d = lineage_domain, l = names(lineage_domain))) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
136 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
137 # filter g gff3 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
138 g <- dante_filtering(g, Relative_Length = opt$min_relative_length) # default |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
139 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
140 seqlengths(g) <- seqlengths(s)[names(seqlengths(g))] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
141 g <- add_coordinates_of_closest_neighbor(g) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
142 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
143 # add info about domain order: |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
144 g$domain_order <- as.numeric(factor(paste(g$Name, g$Final_Classification, sep = ":"), levels = lineage_domains_sequence)) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
145 # set NA to 0 in g$domain_order ( some domains are not fromm ClassI elements |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
146 g$domain_order[is.na(g$domain_order)] <- 0 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
147 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
148 # NOTE - some operation is faster of GrangesList but some on list of data.frames |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
149 # this is primary clusteing |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
150 cls <- get_domain_clusters(g) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
151 gcl <- split(as.data.frame(g), cls) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
152 # gcl_as_GRL <- split(g, cls) # delete? |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
153 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
154 cls_alt <- get_domain_clusters_alt(g, FDM) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
155 g$Cluster <- as.numeric(factor(cls_alt)) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
156 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
157 gcl_alt <- split(as.data.frame(g), cls_alt) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
158 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
159 TE_partial <- GRanges(seqnames = sapply(gcl_alt, function(x) x$seqnames[1]), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
160 Name = sapply(gcl_alt, function(x) x$Final_Classification[1]), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
161 Final_Classification = sapply(gcl_alt, function(x) x$Final_Classification[1]), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
162 ID = sapply(gcl_alt, function(x) paste0("TE_partial_", sprintf("%08d", x$Cluster[1]))), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
163 strand = sapply(gcl_alt, function(x) x$strand[1]), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
164 Ndomains = sapply(gcl_alt, function(x) nrow(x)), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
165 type = "transposable_element", |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
166 source = "dante_ltr", |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
167 Rank="D", |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
168 IRanges(start = sapply(gcl_alt, function(x) min(x$start)), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
169 end = sapply(gcl_alt, function(x) max(x$end))) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
170 ) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
171 g$Ndomains_in_cluster <- count_occurences_for_each_element(g$Cluster) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
172 g$Parent <- paste0("TE_partial_", sprintf("%08d", g$Cluster)) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
173 g$Rank <- "D" |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
174 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
175 # keep only partial TE with more than one domain |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
176 TE_partial_with_more_than_one_domain <- TE_partial[TE_partial$Ndomains > 1] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
177 g_with_more_than_one_domain <- g[as.vector(g$Ndomains_in_cluster > 1)] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
178 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
179 # first filtering - remove TEs with low number of domains |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
180 gcl_clean <- clean_domain_clusters(gcl, lineage_domain_span, min_domains = 5 - opt$max_missing_domains) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
181 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
182 # glc annotation |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
183 gcl_clean_lineage <- sapply(gcl_clean, function(x) x$Final_Classification[1]) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
184 gcl_clean_domains <- sapply(gcl_clean, function(x) ifelse(x$strand[1] == "-", |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
185 paste(rev(x$Name), collapse = " "), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
186 paste(x$Name, collapse = " ")) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
187 ) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
188 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
189 # compare detected domains with domains in lineages from REXdb database |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
190 dd <- mapply(domain_distance, |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
191 d_query = gcl_clean_domains, |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
192 d_reference = lineage_domain[gcl_clean_lineage]) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
193 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
194 # get lineages which has correct number and order of domains |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
195 # gcl_clean2 <- gcl_clean[gcl_clean_domains == lineage_domain[gcl_clean_lineage]] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
196 gcl_clean2 <- gcl_clean[dd <= opt$max_missing_domains] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
197 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
198 gcl_clean_with_domains <- gcl_clean2[check_ranges(gcl_clean2, s)] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
199 gr <- get_ranges(gcl_clean_with_domains) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
200 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
201 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
202 cat('Number of analyzed regions:\n') |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
203 cat('Total number of domain clusters : ', length(gcl), '\n') |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
204 cat('Number of clean clusters : ', length(gcl_clean), '\n') |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
205 cat('Number of clusters with complete domain set : ', length(gcl_clean_with_domains), '\n') |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
206 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
207 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
208 te_strand <- sapply(gcl_clean_with_domains, function(x)x$strand[1]) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
209 te_lineage <- sapply(gcl_clean_with_domains, function(x)x$Final_Classification[1]) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
210 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
211 max_left_offset <- ifelse(te_strand == "+", lineage_offset5prime[te_lineage], lineage_offset3prime[te_lineage]) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
212 max_right_offset <- ifelse(te_strand == "-", lineage_offset5prime[te_lineage], lineage_offset3prime[te_lineage]) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
213 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
214 grL <- get_ranges_left(gcl_clean_with_domains, max_left_offset) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
215 grR <- get_ranges_right(gcl_clean_with_domains, max_right_offset) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
216 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
217 s_left <- getSeq(s, grL) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
218 s_right <- getSeq(s, grR) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
219 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
220 expected_ltr_length <- lineage_ltr_mean_length[sapply(gcl_clean_with_domains, function (x)x$Final_Classification[1])] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
221 # for statistics |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
222 RT <- g[g$Name == "RT" & substring(g$Final_Classification, 1, 11) == "Class_I|LTR"] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
223 # cleanup |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
224 #rm(g) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
225 rm(gcl) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
226 rm(gcl_clean) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
227 rm(gcl_clean2) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
228 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
229 names(te_strand) <- paste(seqnames(gr), start(gr), end(gr), sep = "_") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
230 names(s_left) <- paste(seqnames(grL), start(grL), end(grL), sep = "_") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
231 names(s_right) <- paste(seqnames(grR), start(grR), end(grR), sep = "_") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
232 cat('Identification of LTRs...') |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
233 TE <- mclapply(seq_along(gr), function(x)get_TE(s_left[x], |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
234 s_right[x], |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
235 gcl_clean_with_domains[[x]], |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
236 gr[x], |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
237 grL[x], |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
238 grR[x], |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
239 expected_ltr_length[x]), |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
240 mc.set.seed = TRUE, mc.cores = opt$cpu, mc.preschedule = FALSE |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
241 ) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
242 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
243 cat('done.\n') |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
244 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
245 good_TE <- TE[!sapply(TE, is.null)] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
246 cat('Number of putative TE with identified LTR :', length(good_TE), '\n') |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
247 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
248 # TODO - extent TE region to cover also TSD |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
249 ID <- paste0('TE_', sprintf("%08d", seq(good_TE))) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
250 gff3_list <- mcmapply(get_te_gff3, g = good_TE, ID = ID, mc.cores = opt$cpu) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
251 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
252 cat('Identification of PBS ...') |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
253 gff3_list2 <- mclapply(gff3_list, FUN = add_pbs, s = s, trna_db = trna_db, mc.set.seed = TRUE, mc.cores = opt$cpu, mc.preschedule = FALSE) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
254 cat('done\n') |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
255 gff3_out <- do.call(c, gff3_list2) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
256 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
257 # define new source |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
258 src <- as.character(gff3_out$source) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
259 src[is.na(src)] <- "dante_ltr" |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
260 gff3_out$source <- src |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
261 gff3_out$Rank <- get_te_rank(gff3_out) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
262 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
263 # add partial TEs but first remove all ovelaping |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
264 TE_partial_parent_part <- TE_partial_with_more_than_one_domain[TE_partial_with_more_than_one_domain %outside% gff3_out] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
265 TE_partial_domain_part <- g[g$Parent %in% TE_partial_parent_part$ID] |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
266 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
267 gff3_out <- sort(c(gff3_out, TE_partial_domain_part, TE_partial_parent_part), by = ~ seqnames * start) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
268 # modify ID and Parent - add seqname - this will ensure it is unique is done on chunk level |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
269 gff3_out$ID[!is.na(gff3_out$ID)] <- paste0(gff3_out$ID[!is.na(gff3_out$ID)], "_", seqnames(gff3_out)[!is.na(gff3_out$ID)]) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
270 gff3_out$Parent[!is.na(gff3_out$Parent)] <- paste0(gff3_out$Parent[!is.na(gff3_out$Parent)], "_", seqnames(gff3_out)[!is.na(gff3_out$Parent)]) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
271 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
272 export(gff3_out, con = paste0(outfile, ".gff3"), format = 'gff3') |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
273 |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
274 all_tbl <- get_te_statistics(gff3_out, RT) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
275 all_tbl <- cbind(Classification = rownames(all_tbl), all_tbl) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
276 write.table(all_tbl, file = paste0(outfile, "_statistics.csv"), sep = "\t", quote = FALSE, row.names = FALSE) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
277 # export fasta files: |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
278 s_te <- get_te_sequences(gff3_out, s) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
279 for (i in seq_along(s_te)) { |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
280 outname <- paste0(outfile, "_", names(s_te)[i], ".fasta") |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
281 writeXStringSet(s_te[[i]], filepath = outname) |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
282 } |
ff01d4263391
"planemo upload commit 414119ad7c44562d2e956b765e97ca113bc35b2b-dirty"
petr-novak
parents:
diff
changeset
|
283 |