[Biojava-l] Getting a Slice of an Alignment

Andrew Walsh walsh at andrew.cmu.edu
Wed Aug 9 15:59:52 UTC 2006


I have just found a need to do something similar (i.e. extract select 
columns from an alignment) and have discovered that the subAlignment() 
implementation of the SimpleAlignment class does exactly what the 
original poster wants the method to do, and what the method description 
from the Alignment interface API suggests it should do.  It returns an 
Alignment object which contains only those sequences indicated by the 
first argument (a Set of labels), and only the symbols from the columns 
specified in the second argument (a Location object).  No further 
processing is needed to get just the symbols from the specified 
columns.  These columns need not even be contiguous; it will work 
correctly with any arbitrary subset of the columns.  It seems to me that 
since this method is part of the Alignment interface that all 
implementations should have the same behavior.  They should provide the 
specified subalignment without the need for further processing.  I would 
thus propose that a modification to the 
AbstractULAlignment.subAlignment() method (or the 
AbstractULAlignment.SubULAlignment(Set labels, Location loc) 
constructor, since this is where the actual work is done) be made to 
have it perform correctly.  Other Alignment implementing classes may 
also need to be modified as well.

-Andy

Dexter Riley wrote:
> I have time to think about the problem of creating a subalignment again.  To
> see if I understand Richard's solution, you:
> Create a subalignment from the original alignment, at the desired location
> Iterate through each SymbolList in the alignment, and 
>      determine the offset of the SymbolList in the original alignment,
>      determine the offset of the SymbolList in the subalignment,
>      create a new SymbolList using these offsets.
>
> My main problem with doing this is that you create an Alignment to get the
> SymbolLists that represent the slice, which I then would use to...create an
> Alignment.  Since all I really want is an Alignment view of a particular
> location slice of an Alignment, I really think your original idea of
> changing the behavior of
> AbstractULAlignment.SubULAlignment.symbolListForLabel() would be much more
> intuitive (at least to a new user like myself), and be at least one object
> lighter, and possibly faster to boot (can't say for sure since I'm not
> familiar with how AbstractULAlignment uses SubULAlignments.) 
> Thanks,
> Ed
>
>   




More information about the Biojava-l mailing list