001    package calhoun.analysis.crf.features.tricycle13;
002    
003    import java.util.List;
004    
005    import org.apache.commons.logging.Log;
006    import org.apache.commons.logging.LogFactory;
007    
008    import calhoun.analysis.crf.AbstractFeatureManager;
009    import calhoun.analysis.crf.CacheStrategySpec;
010    import calhoun.analysis.crf.FeatureList;
011    import calhoun.analysis.crf.FeatureManagerNode;
012    import calhoun.analysis.crf.ModelManager;
013    import calhoun.analysis.crf.CacheStrategySpec.CacheStrategy;
014    import calhoun.analysis.crf.io.CompositeInput;
015    import calhoun.analysis.crf.io.InputSequence;
016    import calhoun.analysis.crf.io.TrainingSequence;
017    
018    public class PfamPhase extends AbstractFeatureManager<CompositeInput> implements FeatureManagerNode<CompositeInput> {
019            private static final long serialVersionUID = -7659288739348604129L;
020            private static final Log log = LogFactory.getLog(PfamPhase.class);
021            boolean debug = log.isDebugEnabled();
022            
023            /* Contains 1 features:
024             *    f returns 1 if either of two conditions below and 0 otherwise:
025             *      a) y_i=intron1,intron2,intron3 and pest(i+1) = 2 [intron only]
026             *      b) y_i= intron1m,intron2m,intron3m and mest(i+1) = 2 [intron only]
027             */
028            
029            int startIx;  // The index of the first feature managed by this FeatureManager
030            ModelManager model;
031            
032            int exon1S;
033            int exon2S;
034            int exon3S;
035            int exon1mS;
036            int exon2mS;
037            int exon3mS;
038            
039            public PfamPhase() {
040            }
041    
042            public int getNumFeatures() {
043                    return 1;
044            }       
045            
046            public String getFeatureName(int featureIndex) {
047                    return "PfamPhase";
048            }
049    
050            
051            public void evaluateNode(InputSequence<? extends CompositeInput> seq, int pos, int state, FeatureList result) {
052                    if(pos == seq.length()-1) {
053                            return;
054                    }               
055    
056                    InputSequence<Integer>  ppfam = (InputSequence<Integer>) seq.getComponent("ppfam");         
057                    InputSequence<Integer>  mpfam = (InputSequence<Integer>) seq.getComponent("mpfam");
058                    
059                    if ((state==exon1S) && (ppfam.getX(pos)==1))  { result.addFeature(startIx, 1); }
060                    if ((state==exon2S) && (ppfam.getX(pos)==2))  { result.addFeature(startIx, 1); }
061                    if ((state==exon3S) && (ppfam.getX(pos)==3))  { result.addFeature(startIx, 1); }
062    
063                    if ((state==exon1mS) && (mpfam.getX(pos)==1))  { result.addFeature(startIx, 1); }
064                    if ((state==exon2mS) && (mpfam.getX(pos)==2))  { result.addFeature(startIx, 1); }
065                    if ((state==exon3mS) && (mpfam.getX(pos)==3))  { result.addFeature(startIx, 1); }
066            }
067    
068    
069            public void train(int startingIndex, ModelManager modelInfo, List<? extends TrainingSequence<? extends CompositeInput>> data) {
070                    startIx = startingIndex;
071                    model = modelInfo;
072    
073                    exon1S = model.getStateIndex("exon1");
074                    exon2S = model.getStateIndex("exon2");
075                    exon3S = model.getStateIndex("exon3");
076    
077                    exon1mS = model.getStateIndex("exon1m");
078                    exon2mS = model.getStateIndex("exon2m");
079                    exon3mS = model.getStateIndex("exon3m");
080            }
081            @Override
082            public CacheStrategySpec getCacheStrategy() {
083                    return new CacheStrategySpec(CacheStrategy.UNSPECIFIED);
084            }
085    }
086