[Biojava-l] Creating my own classes

Richard Holland richard.holland at ebi.ac.uk
Thu Apr 27 15:55:39 UTC 2006


Given some existing Location object (let's called it 'loc'), and an
existing Alignment (hypothetically called 'algn'), you can do this:

	// Obtain the labels of all the sequences in the alignment.
	Set labels = new HashSet(); 
	labels.addAll(algn.getLabels());
	// Obtain a sub-alignment including all the sequences in the 
 	// original alignment.
        Alignment subAlignment = algn.subAlignment(labels, loc);

cheers,
Richard


On Thu, 2006-04-27 at 16:44 +0100, Nathan S. Haigh wrote:
> Thanks Richard,
> 
> I'll think about this and try to do some deciphering. The only thing I'm in
> need of help for is possibly some actual code that would take an Alignment
> object and return a subalignment based on the positions specified in a
> Locations object - it's difficult to make sense of a new language until you
> start to pick up some of the basics.
> 
> Thanks
> Nathan
> 
> > -----Original Message-----
> > From: Richard Holland [mailto:richard.holland at ebi.ac.uk]
> > Sent: 27 April 2006 16:37
> > To: n.haigh at sheffield.ac.uk
> > Cc: biojava-l at lists.open-bio.org
> > Subject: Re: [Biojava-l] Creating my own classes
> > 
> > On Thu, 2006-04-27 at 16:12 +0100, Nathan S. Haigh wrote:
> > > My application essentially defines sets of positions from an alignment -
> > I
> > > call them CHARSETs as they are analogous to CHARSETs in the Nexus file
> > > format. I believe in Biojava the Locations object/interface (sorry, not
> > > familiar enough with correct terminology yet) is essentially the same
> > sort
> > > of thing. In my app, the user can use several approaches to define a
> > CHARSET
> > > e.g. a CHARSET containing just invariable sites, or a CHARSET containing
> > > sites above a given % identity.
> > 
> > You'd be right there. A Location in BioJava represents a range of
> > positions.
> > 
> > > My question is this, if I were to create a class called Charset, and I
> > > create several subclasses called e.g. Invariable etc is this reasonable?
> > Or
> > > should the class Charset contain many methods for creating a different
> > type
> > > of CHARSET?
> > 
> > My suggestion would be create an interface called Charset, which defines
> > behaviour which you expect all types of Charset to exhibit. Then,
> > implement a number of classes which implement this interface, one for
> > each type of Charset you have, which each add their own methods or
> > special behaviour. If a lot of the behaviour is common, you can define
> > an abstract class called something like AbstractCharset which defines
> > this common behaviour, and have the others extend it.
> > 
> > > In my app, a CHARSET needs to be associated with a particular alignment,
> > and
> > > settings used to define the CHARSET, so my Charset class have variables
> > such
> > > as an Alignment object, Locations objects etc. I'd like to write a
> > method
> > > that returns a subalignment based on the CHARSETs associated alignment
> > > object and Locations object but I'm not sure how to do this.
> > 
> > BioJava Alignment objects implement the SymbolList interface, which
> > means you can use all the methods from SymbolList to work with the
> > Alignment, including the subList() method.
> > 
> > cheers,
> > Richard
> > 
> > --
> > Richard Holland (BioMart Team)
> > EMBL-EBI
> > Wellcome Trust Genome Campus
> > Hinxton
> > Cambridge CB10 1SD
> > UNITED KINGDOM
> > Tel: +44-(0)1223-494416
> 
> ---
> avast! Antivirus: Outbound message clean.
> Virus Database (VPS): 0615-2, 12/04/2006
> Tested on: 27/04/2006 16:44:04
> avast! - copyright (c) 1988-2006 ALWIL Software.
> http://www.avast.com
> 
> 
> 
> 
> 
-- 
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