
> library(shipunov)
package 'shipunov', version 1.2-1

> dna <- structure(vector("list", 3), names=c("its", "rbcl", "trnl"))

> setwd("30_alignments")

> for (f in names(dna)) {
+ dna[[f]] <- Read.fasta(paste0(f, ".fasta"))
+ bb <- do.call(rbind, strsplit(dna[[f]]$sequence, split=""))
+ dd <- apply(bb, 2, function(.x) sum(.x == "-")/nrow(bb))
+ ee <- runmed(dd, 3) < 0.5 # trimming treshold: three subsequent sequence positions have more then 50% of non-gaps
+ left <- min(which(ee == TRUE))
+ right <- max(which(ee == TRUE))
+ ff <- bb[,left:right]
+ dna[[f]]$sequence <- apply(ff, 1, paste, collapse="")
+ Write.fasta(dna[[f]], file=paste0("../31_alignments_trimmed/", f, ".fasta"))
+ }
