From 1aaf4bcf1faa540ae142e08f939bca0485b1f115 Mon Sep 17 00:00:00 2001 From: Simon Penel Date: Tue, 16 Jul 2024 10:11:42 +0200 Subject: [PATCH] Improve fix https://github.com/lbbe-software/seqinr/issues/10 . Just need to decrement nseq --- DESCRIPTION | 2 +- R/read.alignment.R | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1ea7ebb..c54f2e9 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: seqinr Title: Biological Sequences Retrieval and Analysis -Version: 4.2-40 +Version: 4.2-41 Depends: R (>= 2.10.0) Imports: ade4,segmented Authors@R: c(person("Delphine", "Charif", role = "aut"), diff --git a/R/read.alignment.R b/R/read.alignment.R index b8251ee..e4fa1af 100644 --- a/R/read.alignment.R +++ b/R/read.alignment.R @@ -54,7 +54,6 @@ read.alignment <- function(file, format, forceToLower = TRUE, white <- characters[-length(characters)] == " " black <- characters[-1] != " " istart <- which(white & black)[1] - # Get sequence names nam <- character() nseq <- 1 @@ -74,7 +73,12 @@ read.alignment <- function(file, format, forceToLower = TRUE, nseq <- nseq - 1 break # alredy seen } - if (seqname == 'NA') {break} + # this happens with short alignments because seqname is never found + # in mam + if (seqname == 'NA') { + nseq <- nseq - 1 + break + } nam[nseq] <- seqname nseq <- nseq + 1 } @@ -98,14 +102,11 @@ read.alignment <- function(file, format, forceToLower = TRUE, # Concatenation of sequence lines in a single string seq <- vector(mode = "list") for(iseq in seq_len(nseq)){ - if (iseq <= length(filecontent)) { - ii <- seq(iseq, length(filecontent), by = nseq) - seq[[iseq]] <- paste0(filecontent[ii], collapse = "") - if(forceToLower) seq[[iseq]] <- tolower(seq[[iseq]]) - } + ii <- seq(iseq, length(filecontent), by = nseq) + seq[[iseq]] <- paste0(filecontent[ii], collapse = "") + if(forceToLower) seq[[iseq]] <- tolower(seq[[iseq]]) } - - return(as.alignment(nb = length(seq), nam = nam, seq = seq, com = NA)) + return(as.alignment(nb = nseq, nam = nam, seq = seq, com = NA)) }