[Biojava-l] Getting a Slice of an Alignment

Richard Holland richard.holland at ebi.ac.uk
Tue Jun 27 09:17:38 UTC 2006


Your getSlice method, assuming it must return a FlexibleAlignment
instance, could be better written as:

public static FlexibleAlignment getSlice(Alignment alignment, Location
location) {
	Alignment subAlignment = alignment.subAlignment(null, location);
	List<AlignmentElement> subAlignmentElements = new
ArrayList<AlignmentElement>();
	List<String> labels = (List<String>) alignment.getLabels();
	for (String label : labels) 
		subAlignmentElements.add(new SimpleAlignmentElement(
			label,
			subAlignment.symbolListForLabel(label),
			location);
	return new FlexibleAlignment(subAlignmentElements);
}

or if you don't care what class of alignment you get back, then even
just this would work:

public static Alignment getSlice(Alignment alignment, Location location)
{
	return alignment.subAlignment(null, location);
}

I'm afraid I still don't understand what it is that the above code can't
do. Could you give example code showing what it is you are doing with
the sub alignment once it has been created, the output you'd expect or
want from the example code, and the output it actually gives? 

cheers,
Richard

On Mon, 2006-06-26 at 09:04 -0700, Dexter Riley wrote:
> I should have clarified; the >Seq1 lines were just to indicate that the
> series of sequences were part of an alignment.  I did a quick implementation
> of what I was looking for, but was hoping that something like this already
> existed, in a form that could handle gaps and alignment shifts properly :
> 
>   public static Alignment getSlice(Alignment alignment, Location location) 
>   throws BioException{
>     List<AlignmentElement> subAlignment = new ArrayList<AlignmentElement>();
>     List<String> labels = (List<String>) alignment.getLabels();
>     for (String label: labels){
>       subAlignment.add(new SimpleAlignmentElement(
>         label, 
>         alignment.symbolListForLabel(label).subList(location.getMin(),
> location.getMax()),
>         location)     
>       );
>     }
>     return new FlexibleAlignment(subAlignment);        
>   }
>  
> This implementation will probably not work as expected if the sequences
> don't all begin at location 1.  I'm honestly surprised that there's no
> Alignment utility that will do something like this already; surely someone
> else has had a need for a view to a part of an alignment before?
> 
> -Ed
> --
> View this message in context: http://www.nabble.com/Getting-a-Slice-of-an-Alignment-t1849222.html#a5049831
> Sent from the BioJava forum at Nabble.com.
> 
> _______________________________________________
> Biojava-l mailing list  -  Biojava-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biojava-l
-- 
Richard Holland (BioMart Team)
EMBL-EBI
Wellcome Trust Genome Campus
Hinxton
Cambridge CB10 1SD
UNITED KINGDOM
Tel: +44-(0)1223-494416




More information about the Biojava-l mailing list