    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 ESTIntron extends AbstractFeatureManager<CompositeInput> implements FeatureManagerNode<CompositeInput> {
    019            private static final long serialVersionUID = -7659288739348604129L;
    020            private static final Log log = LogFactory.getLog(ESTIntron.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            boolean[] plusIntronState;
    033            boolean[] minusIntronState;
    034
    035
    036            public ESTIntron() {
    037            }
    038
    039            public int getNumFeatures() {
    040                    return 1;
    041            }
    042
    043            public String getFeatureName(int featureIndex) {
    044                    return "ESTIntron";
    045            }
    046
    047            public void evaluateNode(InputSequence<? extends CompositeInput> seq, int pos, int state, FeatureList result) {
    048                    if(pos == seq.length()-1) {
    049                            return;
    050                    }
    051
    052                    InputSequence<Integer>  pest = (InputSequence<Integer>) seq.getComponent("pest");
    053                    InputSequence<Integer>  mest = (InputSequence<Integer>) seq.getComponent("mest");
    054
    055                    boolean plusEstIntron = (pest.getX(pos+1) == 2);
    056                    boolean minusEstIntron = (mest.getX(pos+1) == 2);
    057
    058                    if (plusIntronState[state] && plusEstIntron) { result.addFeature(startIx, 1); }
    059                    if (minusIntronState[state] && minusEstIntron) { result.addFeature(startIx, 1); }
    060            }
    061
    062
    063            public void train(int startingIndex, ModelManager modelInfo, List<? extends TrainingSequence<? extends CompositeInput>> data) {
    064                    startIx = startingIndex;
    065                    model = modelInfo;
    066
    067                    int nStates = model.getNumStates();
    068
    069                    plusIntronState = new boolean[nStates];
    070                    for (int j=0; j<nStates; j++) { plusIntronState[j] = false; }
    071                    plusIntronState[model.getStateIndex("intron1")] = true;
    072                    plusIntronState[model.getStateIndex("intron2")] = true;
    073                    plusIntronState[model.getStateIndex("intron3")] = true;
    074
    075                    minusIntronState = new boolean[nStates];
    076                    for (int j=0; j<nStates; j++) { minusIntronState[j] = false; }
    077                    minusIntronState[model.getStateIndex("intron1m")] = true;
    078                    minusIntronState[model.getStateIndex("intron2m")] = true;
    079                    minusIntronState[model.getStateIndex("intron3m")] = true;
    080            }
    081            @Override
    082            public CacheStrategySpec getCacheStrategy() {
    083                    return new CacheStrategySpec(CacheStrategy.UNSPECIFIED);
    084            }
    085    }
    086