    001    package calhoun.analysis.crf.features.interval13;
    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 BlastInterval13 extends AbstractFeatureManager<CompositeInput> implements FeatureManagerNode<CompositeInput> {
    019            private static final long serialVersionUID = -7659288739348604129L;
    020            private static final Log log = LogFactory.getLog(BlastInterval13.class);
    021            boolean debug = log.isDebugEnabled();
    022
    023            int startIx;  // The index of the first feature managed by this FeatureManager
    024            ModelManager model;
    025
    026            boolean[] intergenicState;
    027            boolean[] plusExonState;
    028            boolean[] minusExonState;
    029            boolean[] plusIntronState;
    030            boolean[] minusIntronState;
    031
    032            public BlastInterval13() {
    033            }
    034
    035            public int getNumFeatures() {
    036                    return 3;
    037            }
    038
    039            public String getFeatureName(int featureIndex) {
    040                    String[] types = new String[] {"exon", "intron", "Intergenic","a"};
    041                    return "Blast "+types[featureIndex-startIx];
    042            }
    043
    044            public void evaluateNode(InputSequence<? extends CompositeInput> seq, int pos, int state, FeatureList result) {
    045                    if(pos == seq.length()-1) {
    046                            return;
    047                    }
    048
    049                    InputSequence<Integer>  pblast = (InputSequence<Integer>) seq.getComponent("pblast");
    050                    InputSequence<Integer>  mblast = (InputSequence<Integer>) seq.getComponent("mblast");
    051
    052                    int plusEst  = pblast.getX(pos+1);
    053                    int minusEst = mblast.getX(pos+1);
    054                    // 0 - no data
    055                    // 1 - blast cluster hit here on this strand
    056
    057                    if ((plusExonState[state] && (plusEst==1)) || (minusExonState[state] && (minusEst==1))) {
    058                            result.addFeature(startIx, 1);
    059                    }
    060
    061                    if ((plusIntronState[state] && (plusEst==1)) || (minusIntronState[state] && (minusEst==1))) {
    062                            result.addFeature(startIx+1, 1);
    063                    }
    064
    065                    if (intergenicState[state] && (plusEst==1 || minusEst==1)) {
    066                            result.addFeature(startIx+2, 1);
    067                    }
    068    }
    069
    070            public void train(int startingIndex, ModelManager modelInfo, List<? extends TrainingSequence<? extends CompositeInput>> data) {
    071                    startIx = startingIndex;
    072                    model = modelInfo;
    073
    074                    int nStates = model.getNumStates();
    075
    076                    plusExonState = new boolean[nStates];
    077                    plusExonState[model.getStateIndex("exon0")] = true;
    078                    plusExonState[model.getStateIndex("exon1")] = true;
    079                    plusExonState[model.getStateIndex("exon2")] = true;
    080
    081                    minusExonState = new boolean[nStates];
    082                    minusExonState[model.getStateIndex("exon0m")] = true;
    083                    minusExonState[model.getStateIndex("exon1m")] = true;
    084                    minusExonState[model.getStateIndex("exon2m")] = true;
    085
    086                    plusIntronState = new boolean[nStates];
    087                    plusIntronState[model.getStateIndex("intron0")] = true;
    088                    plusIntronState[model.getStateIndex("intron1")] = true;
    089                    plusIntronState[model.getStateIndex("intron2")] = true;
    090
    091                    minusIntronState = new boolean[nStates];
    092                    minusIntronState[model.getStateIndex("intron0m")] = true;
    093                    minusIntronState[model.getStateIndex("intron1m")] = true;
    094                    minusIntronState[model.getStateIndex("intron2m")] = true;
    095
    096                    intergenicState = new boolean[nStates];
    097                    intergenicState[model.getStateIndex("intergenic")] = true;
    098            }
    099
    100            @Override
    101            public CacheStrategySpec getCacheStrategy() {
    102                    return new CacheStrategySpec(CacheStrategy.DENSE);
    103            }
    104    }
    105