comparison consensus_from_alignments.R @ 0:0ccbe1c20fc3 draft default tip

planemo upload for repository https://github.com/ColineRoyaux/Galaxy_tool_projects/tree/main/consensus_from_alignments commit ecc21de8f368c6a95c57d4e6511ed42af9e72a66
author ecology
date Tue, 25 Apr 2023 10:05:29 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0ccbe1c20fc3
1 #Rscript
2
3 ################################################################################
4 ## Extract consensus sequence from aligned forward and reverse fasta ##
5 ################################################################################
6
7 #####Packages
8 library(bioseq, quietly = TRUE)
9
10 ##Load arguments
11 args <- commandArgs(trailingOnly = TRUE)
12
13 if (length(args) == 0) {
14 stop("This tool needs at least one argument")
15 } else {
16 fasta_f <- args[1]
17 seq_type <- args[2]
18 meth_choice <- args[3]
19 gaps_tf <- as.logical(args[4])
20 out_og <- as.logical(args[5])
21 }
22
23 ## Read input file
24 seq_l <- bioseq::read_fasta(fasta_f, type = seq_type)
25
26 if(bioseq::seq_nseq(seq_l) < 2){
27 stop("Only one sequence in the file, at least two aligned sequences are needed to compute a consensus")
28 }else{
29 if(length(unique(bioseq::seq_nchar(seq_l))) > 1) {stop("Sequences have different lengths, please provide aligned sequences")}
30 }
31
32 ##Consensus sequence
33 seq_con <- bioseq::seq_consensus(seq_l, method = meth_choice, gaps = gaps_tf)
34
35 if(bioseq::seq_nseq(seq_con) > 1){stop("Consensus hasn't worked for an unknown reason, double-check your input file and the parameters you chose")}
36
37 names(seq_con) <- paste0("consensus_", Reduce(PTXQC::LCS, names(seq_l)))
38 ##Create output
39 if(out_og){
40 bioseq::write_fasta(c(seq_con, seq_l), file = "output.fasta", line_length = Inf, block_length = Inf)
41 }else{
42 bioseq::write_fasta(seq_con, file = "output.fasta", line_length = Inf, block_length = Inf)
43 }