# [Biojava-l] Sort symbols in an alphabet

Ren, Zhen zren@amylin.com
Thu, 9 Jan 2003 15:12:49 -0800

I am using DP and HMM.  A distribution is an encapsulation of a probability distribution over the Symbols within an alphabet.  Set up emission probabilities like this in a HMM object:

for(int i = 0; i < symbols.length; i++)
dist.setWeight(symbols[i], frequency[i]);

Later, a DP object is created using the HMM with the above emission probabilities:

DP dp=DPFactory.DEFAULT.createDP(myHMM);
SymbolList sequence = ProteinTools.createProtein("AGFAVENDSAQWP")
SymbolList[] array = { sequence };
double score = dp.forward(array, ScoreType.PROBABILITY);
System.out.println("score = " + score);

I expect some kind of score would be printed.  But, nothing.  Not even the string "score = ".  It seems the line is not executed.  I thought maybe the emission probability is not there at all because those probabilities may have been assigned to a copy of the original symbols.

Most likely, my understanding is completely wrong.  I just keep trying various things.  Any more tutorials on HMM and DP other than the Dice example?  It's painful to learn APIs.  Thanks.

Zhen

-----Original Message-----
From: Schreiber, Mark [mailto:mark.schreiber@agresearch.co.nz]
Sent: Thursday, January 09, 2003 2:47 PM
To: Ren, Zhen; biojava-l@biojava.org
Subject: RE: [Biojava-l] Sort symbols in an alphabet

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
>
>     //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.
=======================================================================