[Biojava-l] alignments
Richard Holland
holland at eaglegenomics.com
Mon Feb 9 14:47:45 UTC 2009
Yes, you can cast it back. In fact you don't need to actually cast it at
all, as Java will do that for you automatically. FlexibleAlignment is an
implementation of the Alignment interface, which defines general
behaviour for all alignments. If your algorithm is written to accept a
parameter of type Alignment, then it will accept any object which
implements the Alignment interface, including FlexibleAlignment, Happy
and SadAlignment, etc. etc.
Unfortunately I'm not sure why there are so many different kinds of
alignment objects. I think it was something to do with wanting to make
some that are modifiable, and others that are read-only, then making
different kinds that store the underlying alignment data in
different/more efficient/faster/cleverer representations. It does rather
over-complicate things, however if your algorithm only requires
Alignment as the type of its parameter, then you can safely use all and
any of these as they all implement the Alignment interface.
cheers,
Richard
simon rayner wrote:
> Hi,
>
> i have a question about Alignment and FlexibleAlignment objects.
> Basically, i have a sequence alignment in FASTA format so followed a code
> sample i found from a previous posted query:
>
> BufferedReader br = new BufferedReader(new FileReader("file.txt"));
> FastaAlignmentFormat faf = new FastaAlignmentFormat();
> Alignment aligned = faf.read( br );
>
> so now i have an alignment stored in an Alignment object.
>
> 1. I do something with these sequences using the access methods for
> the Alignment object.
> something like
>
> java.util.Iterator iter = l.listIterator();
> while(iter.hasNext())
> {
> String currLabel = (String) iter.next();
> String currAA
> = aligned.symbolListForLabel(currLabel)
> .seqString().substring(base, base+1);
> }
>
> 2. Now i want to do the same analysis but on a random sample of
> sequences from this alignment.
> So to get a subset of these sequences i created a FlexibleAlignment
> and grabbed the sequences
> i need from the original alignment...
>
> Alignment al;
> Iterator l = al.symbolListIterator();
> java.util.List<String> names = al.getLabels();
> Iterator n = names.listIterator();
> java.util.ArrayList seqList = new java.util.ArrayList(1);
> String refs = "";
> while(refs.length() < al.length())
> {
> refs = refs.concat("x");
> }
>
> try{
> FlexibleAlignment FA = new FlexibleAlignment(seqList);
> SymbolList aa = ProteinTools.createProtein(refs);
>
> seqList.add(
> new SimpleAlignmentElement(
> "reference",
> aa,
> new RangeLocation(1, al.length()))
> );
> while (l.hasNext())
> {
> try{
> SymbolList sal = (SymbolList)l.next();
> String name = (String)n.next();
>
> FA.addSequence(new SimpleAlignmentElement(name,
> sal,
> new RangeLocation(1, al.length())));
>
> }
> catch (org.biojava.bio.BioException ex)
> {
> System.out.print("couldn't add sequence to alignment\n");
> System.err.print(ex);
> }
> }
> this.aligned = FA;
> }
> catch (org.biojava.bio.BioException ex)
> {
> System.out.print("couldn't add sequence to alignment\n");
> System.err.print(ex);
> }
>
> So now i have my alignment of random sequences in a FlexibleAlignment
> object, but my original analysis
> was written for an Alignment object (because that's the format that
> FastaAlignmentFormat spat back at me.
>
> So, can i cast a FlexibleAlignment object into an Alignment object? or
> am i just going about it the wrong way?
>
> p.s. Why are there so many diverse Alignment related objects?
> (AbstractULAlignment,
> AbstractULAlignment.SubULAlignment, FlexibleAlignment, RelabeledAlignment,
> EmptyPairwiseAlignment, SimpleAlignment, HappyAlignment,
> SadAlignment..) Is there any documentation (other than
> the standard java docs) to clarify which object when?
>
> thanks!
> _______________________________________________
> Biojava-l mailing list - Biojava-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biojava-l
>
--
Richard Holland, BSc MBCS
Finance Director, Eagle Genomics Ltd
M: +44 7500 438846 | E: holland at eaglegenomics.com
http://www.eaglegenomics.com/
More information about the Biojava-l
mailing list