This is a test version of Biostars. For the public version, visit https://www.biostars.org.
A Subset Of Phylip Alignment?

I wonder if there is a free tool that I can use to extract parts of a phylip alignment (not interleaved). An example of a phylip alignment could be like:

2 7

Seq1 ACGTA AC

Seq2 ACGAG AT

I want to extract a part of it, say, from column 3 to column 5.

Thank you,

SangChul

2 answers

A potential biopython solution... not tested, but this should work

from Bio import AlignIO 
align = AlignIO.read("alignment.phy", "phylip")
print align[:,2:5]

In addition to Whetting's answer on using biopython, you should be able to add an eliminate characters section in your PHYLIP matrix file similar to the characters block exclude function in a NEXUS file. I don't use PHYLIP much (one of the reasons I haven't adopted the program is that I have never really understood the reason for the PHYLIP file format over NEXUS file format). Is there a reason you have to use PHYLIP?

I think MESQUITE will allow you to import all your characters (nucleotides and morphology) and then lets you export PHYLIP format data matrices based on which characters you would like to exclude, but I have not actively used this.

Log in to answer this question.