    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.CompositeInput;
    013    import calhoun.analysis.crf.io.InputSequence;
    014    import calhoun.analysis.crf.io.TrainingSequence;
    015
    016    public class ESTExon extends AbstractFeatureManager<CompositeInput> implements FeatureManagerNode<CompositeInput> {
    017            private static final long serialVersionUID = -7659288739348604129L;
    018            private static final Log log = LogFactory.getLog(ESTExon.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 ESTExon() {
    032            }
    033
    034            public int getNumFeatures() {
    035                    return 4;
    036            }
    037
    038            public String getFeatureName(int featureIndex) {
    039                    return "ESTExon";
    040            }
    041
    042            public void evaluateNode(InputSequence<? extends CompositeInput> seq, int pos, int state, FeatureList result) {
    043                    if(pos == seq.length()-1) {
    044                            return;
    045                    }
    046
    047                    InputSequence<Integer>  pest = (InputSequence<Integer>) seq.getComponent("pest");
    048                    InputSequence<Integer>  mest = (InputSequence<Integer>) seq.getComponent("mest");
    049
    050                    int plusEst  = pest.getX(pos+1);
    051                    int minusEst = mest.getX(pos+1);
    052                    // 0 - no data
    053                    // 1 - exon only
    054                    // 2 - intron only
    055                    // 3 - mixed
    056
    057                    if (plusExonState[state] && (plusEst==1)) { result.addFeature(startIx, 1); }
    058                    if (minusExonState[state] && (minusEst==1)) { result.addFeature(startIx, 1); }
    059
    060                    if (plusExonState[state] && (plusEst==3)) { result.addFeature(startIx+1, 1); }
    061                    if (minusExonState[state] && (minusEst==3)) { result.addFeature(startIx+1, 1); }
    062
    063                    if (plusIntronState[state] && (plusEst==2)) { result.addFeature(startIx+2, 1); }
    064                    if (minusIntronState[state] && (minusEst==2)) { result.addFeature(startIx+2, 1); }
    065
    066                    if (plusIntronState[state] && (plusEst==3)) { result.addFeature(startIx+3, 1); }
    067                    if (minusIntronState[state] && (minusEst==3)) { result.addFeature(startIx+3, 1); }
    068
    069            }
    070
    071
    072            public void train(int startingIndex, ModelManager modelInfo, List<? extends TrainingSequence<? extends CompositeInput>> data) {
    073                    startIx = startingIndex;
    074                    model = modelInfo;
    075
    076                    int nStates = model.getNumStates();
    077
    078                    plusExonState = new boolean[nStates];
    079                    for (int j=0; j<nStates; j++) { plusExonState[j] = false; }
    080                    plusExonState[model.getStateIndex("exon1")] = true;
    081                    plusExonState[model.getStateIndex("exon2")] = true;
    082                    plusExonState[model.getStateIndex("exon3")] = true;
    083
    084                    minusExonState = new boolean[nStates];
    085                    for (int j=0; j<nStates; j++) { minusExonState[j] = false; }
    086                    minusExonState[model.getStateIndex("exon1m")] = true;
    087                    minusExonState[model.getStateIndex("exon2m")] = true;
    088                    minusExonState[model.getStateIndex("exon3m")] = true;
    089
    090                    plusIntronState = new boolean[nStates];
    091                    for (int j=0; j<nStates; j++) { plusIntronState[j] = false; }
    092                    plusIntronState[model.getStateIndex("intron1")] = true;
    093                    plusIntronState[model.getStateIndex("intron2")] = true;
    094                    plusIntronState[model.getStateIndex("intron3")] = true;
    095
    096                    minusIntronState = new boolean[nStates];
    097                    for (int j=0; j<nStates; j++) { minusIntronState[j] = false; }
    098                    minusIntronState[model.getStateIndex("intron1m")] = true;
    099                    minusIntronState[model.getStateIndex("intron2m")] = true;
    100                    minusIntronState[model.getStateIndex("intron3m")] = true;
    101            }
    102    }
    103