    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.FeatureList;
    010    import calhoun.analysis.crf.FeatureManagerNode;
    011    import calhoun.analysis.crf.ModelManager;
    012    import calhoun.analysis.crf.io.InputSequence;
    013    import calhoun.analysis.crf.io.TrainingSequence;
    014    import calhoun.analysis.crf.io.IntervalInputSequence.IntervalPosition;
    015
    016    public class IntervalPresenceFeatures extends AbstractFeatureManager<IntervalPosition> implements FeatureManagerNode<IntervalPosition> {
    017            private static final long serialVersionUID = -7659288739348604129L;
    018            private static final Log log = LogFactory.getLog(IntervalPresenceFeatures.class);
    019            boolean debug = log.isDebugEnabled();
    020
    021
    022
    023            int startIx;  // The index of the first feature managed by this FeatureManager
    024            ModelManager model;
    025
    026            boolean[] plusExonState;
    027            boolean[] minusExonState;
    028            boolean[] plusIntronState;
    029            boolean[] minusIntronState;
    030
    031            public IntervalPresenceFeatures() {
    032            }
    033
    034            public int getNumFeatures() {
    035                    return 2;
    036            }
    037
    038            public String getFeatureName(int featureIndex) {
    039                    return "IntervalPresenceFeatures";
    040            }
    041
    042            public void evaluateNode(InputSequence<? extends IntervalPosition> seq, int pos, int state, FeatureList result) {
    043                    if(pos == seq.length()-1) {
    044                            return;
    045                    }
    046
    047                    boolean plusInt  = seq.getX(pos).queryPlus();
    048                    boolean minusInt = seq.getX(pos).queryMinus();
    049
    050                    if (plusExonState[state] && plusInt ) { result.addFeature(startIx, 1); }
    051                    if (minusExonState[state] && minusInt ) { result.addFeature(startIx, 1); }
    052
    053                    if (plusIntronState[state] && plusInt ) { result.addFeature(startIx+1, 1); }
    054                    if (minusIntronState[state] && minusInt ) { result.addFeature(startIx+1, 1); }
    055            }
    056
    057            public void train(int startingIndex, ModelManager modelInfo, List<? extends TrainingSequence<? extends IntervalPosition>> data) {
    058                    startIx = startingIndex;
    059                    model = modelInfo;
    060
    061                    int nStates = model.getNumStates();
    062
    063                    plusExonState = new boolean[nStates];
    064                    for (int j=0; j<nStates; j++) { plusExonState[j] = false; }
    065                    plusExonState[model.getStateIndex("exon1")] = true;
    066                    plusExonState[model.getStateIndex("exon2")] = true;
    067                    plusExonState[model.getStateIndex("exon3")] = true;
    068
    069                    minusExonState = new boolean[nStates];
    070                    for (int j=0; j<nStates; j++) { minusExonState[j] = false; }
    071                    minusExonState[model.getStateIndex("exon1m")] = true;
    072                    minusExonState[model.getStateIndex("exon2m")] = true;
    073                    minusExonState[model.getStateIndex("exon3m")] = true;
    074
    075                    plusIntronState = new boolean[nStates];
    076                    for (int j=0; j<nStates; j++) { plusIntronState[j] = false; }
    077                    plusIntronState[model.getStateIndex("intron1")] = true;
    078                    plusIntronState[model.getStateIndex("intron2")] = true;
    079                    plusIntronState[model.getStateIndex("intron3")] = true;
    080
    081                    minusIntronState = new boolean[nStates];
    082                    for (int j=0; j<nStates; j++) { minusIntronState[j] = false; }
    083                    minusIntronState[model.getStateIndex("intron1m")] = true;
    084                    minusIntronState[model.getStateIndex("intron2m")] = true;
    085                    minusIntronState[model.getStateIndex("intron3m")] = true;
    086            }
    087    }
    088