This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Creating multiple partitions of the alignment

I have alignment that has sequences with an average length of 900 base pairs (bp). I would like to breakup this alignment into several blocks of alignments each 300 bases long. I can do that in Se-Al by simply copying and pasting into a new window, but I wanted to know if there is a command line tool that can allow me to do so. I want to specify a window length in the command (e.g 300), and it outputs for me several alignments (300 bp each) extracted consecutively from my original big alignment (900 bp) and also with the correct sequence labels. Thank you in advance

alignment

An example of input and ouputs:

----Input: alignment_900bp_long.fasta 
----Options: partitions [window_length]
----Outputs: alignment1_positions_1-300.fasta    alignment2_positions_301-600.fasta     alignment3_positions_601-900.fasta

1 answer

using bioalcidae: http://lindenb.github.io/jvarkit/BioAlcidaeJdk.html

$ java -jar src/jvarkit-git/dist/bioalcidaejdk.jar -e 'final List<FastaSequence> seqs = stream().collect(Collectors.toList()); final int max_len = seqs.stream().mapToInt(S->S.length()).max().orElse(0); int p=0; while(p< max_len) { java.io.PrintWriter w=new java.io.PrintWriter(String.format("tmp.%05d.fa",p)); for(FastaSequence s:seqs) {w.println(">"+s.getName());for(int i=p;i< p+300 && i < max_len;i++) w.print(i<s.length()?""+s.charAt(i):"-");w.println();} w.flush();w.close();p+=300;};' msa.fa

Thank you so much, let me check it out

Log in to answer this question.