[Biojava-l] Sort symbols in an alphabet

Schreiber, Mark mark.schreiber@agresearch.co.nz
Fri, 10 Jan 2003 11:46:34 +1300


You may be able to reengineer the AlphabetIndexers so the index they
produce is based on the order of Symbols by name. Note that a Set is
never really sorted only its pointers are.

You could also make a wrapper wraps a FiniteAlphabet, implements
FiniteAlphabet, delegates all its methods to the wrapped Alphabet but
overides the iterator() method of FiniteAlphabet so that they are
returned in some desirable order. This is not really ideal as you loose
the canonical status of the Alphabet.

I'm not sure why you would want to have the actual Alphabet sorted?

> -----Original Message-----
> From: Ren, Zhen [mailto:zren@amylin.com] 
> Sent: Friday, 10 January 2003 11:11 a.m.
> To: Schreiber, Mark; biojava-l@biojava.org
> Subject: RE: [Biojava-l] Sort symbols in an alphabet
> 
> 
> A copy of the symbol set in an alphabet is sorted.  What if I 
> want to sort the original symbol set in an alphabet?  Thanks. -Zhen
> 
> -----Original Message-----
> From: Schreiber, Mark [mailto:mark.schreiber@agresearch.co.nz]
> Sent: Thursday, January 09, 2003 12:39 PM
> To: Ren, Zhen; biojava-l@biojava.org
> Subject: RE: [Biojava-l] Sort symbols in an alphabet
> 
> 
> The following code should do it,
> 
> You could actually make the ComparableSymbol wrapper 
> implement Symbol and pass all the Symbol methods directly to 
> the wrapped Symbol. I may even submit a ComparableSymbol as a 
> class to biojava-live if people think they would use it.
> 
> - Mark
> 
> 
> import org.biojava.bio.seq.*;
> import org.biojava.bio.symbol.*;
> import java.util.*;
> 
> public class SortAlphabetByName {
>   public static void main(String[] args) {
>     List l = new ArrayList();
> 
>     //add Symbols out of order
>     l.add(new ComparableSymbol(DNATools.c()));
>     l.add(new ComparableSymbol(DNATools.g()));
>     l.add(new ComparableSymbol(DNATools.t()));
>     l.add(new ComparableSymbol(DNATools.a()));
> 
>     //sort them
>     Collections.sort(l);
> 
>     //print there names
>     for (int i = 0; i < l.size(); i++) {
>       ComparableSymbol cs = (ComparableSymbol)l.get(i);
>       System.out.println(cs.getWrapped().getName());
>     }
> 
>   }
> 
>   // a Mix in wrapper
>   static class ComparableSymbol implements Comparable{
>     private Symbol wrapped;
> 
>     public ComparableSymbol(Symbol wrapped){
>       this.wrapped = wrapped;
>     }
> 
>     public int compareTo(Object o){
>       Symbol s = ((ComparableSymbol)o).getWrapped();
> 
>       return wrapped.getName().compareTo(s.getName());
>     }
> 
>     public Symbol getWrapped(){
>       return wrapped;
>     }
>   }
> }
> > -----Original Message-----
> > From: Ren, Zhen [mailto:zren@amylin.com]
> > Sent: Friday, 10 January 2003 8:52 a.m.
> > To: biojava-l@biojava.org
> > Subject: [Biojava-l] Sort symbols in an alphabet
> > 
> > 
> > Hi,
> > 
> > Symbols in an alphabet is not sorted in any way.  How do I
> > sort them, for instance, by name?  Thanks.
> > 
> > Zhen
> > 
> > _______________________________________________
> > Biojava-l mailing list  -  Biojava-l@biojava.org
> > http://biojava.org/mailman/listinfo/biojava-l
> > 
> ==============================================================
> =========
> Attention: The information contained in this message and/or 
> attachments from AgResearch Limited is intended only for the 
> persons or entities to which it is addressed and may contain 
> confidential and/or privileged material. Any review, 
> retransmission, dissemination or other use of, or taking of 
> any action in reliance upon, this information by persons or 
> entities other than the intended recipients is prohibited by 
> AgResearch Limited. If you have received this message in 
> error, please notify the sender immediately. 
> ==============================================================
> =========
> 
=======================================================================
Attention: The information contained in this message and/or attachments
from AgResearch Limited is intended only for the persons or entities
to which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipients is prohibited by AgResearch
Limited. If you have received this message in error, please notify the
sender immediately.
=======================================================================