    001    package calhoun.analysis.crf.scoring;
    002
    003    import calhoun.analysis.crf.LocalPathSimilarityScore;
    004    import calhoun.analysis.crf.io.TrainingSequence;
    005
    006    public class SimScoreStateAndExonBoundariesInt13 implements LocalPathSimilarityScore {
    007
    008            double stateBonus = 1.0;
    009            double boundaryPenalty = 50;
    010
    011            public double evaluate(int yprev, int y, TrainingSequence<?> seq, int pos) {
    012                    if (pos == 0) { return 0.0; }
    013                    int realy = seq.getY(pos);
    014                    int realyprev = seq.getY(pos-1);
    015                    double score = y == realy ? stateBonus : 0.0;
    016
    017                    if ((isPStart(yprev,y) ^ isPStart(realyprev,realy)) ||
    018                                    (isPDon(yprev,y)   ^ isPDon(realyprev,realy))   ||
    019                                    (isPAcc(yprev,y)   ^ isPAcc(realyprev,realy))   ||
    020                                    (isPStop(yprev,y)  ^ isPStop(realyprev,realy))  ||
    021                                    (isMStart(yprev,y) ^ isMStart(realyprev,realy)) ||
    022                                    (isMDon(yprev,y)   ^ isMDon(realyprev,realy))   ||
    023                                    (isMAcc(yprev,y)   ^ isMAcc(realyprev,realy))   ||
    024                                    (isMStop(yprev,y)  ^ isMStop(realyprev,realy))
    025                                    ) {
    026                            score -= boundaryPenalty;
    027                    }
    028
    029                    return score;
    030            }
    031
    032            private boolean isPStart(int yprev, int y) {
    033                    if ( (yprev==0) && (y==1)) { return true; }
    034                    return false;
    035            }
    036
    037            private boolean isPDon(int yprev, int y) {
    038                    if ( (yprev==1) && (y==4)) { return true; }
    039                    if ( (yprev==2) && (y==5)) { return true; }
    040                    if ( (yprev==3) && (y==6)) { return true; }
    041                    return false;
    042            }
    043
    044            private boolean isPAcc(int yprev, int y) {
    045                    if ( (yprev==4) && (y==2)) { return true; }
    046                    if ( (yprev==5) && (y==3)) { return true; }
    047                    if ( (yprev==6) && (y==1)) { return true; }
    048                    return false;
    049            }
    050
    051            private boolean isPStop(int yprev, int y) {
    052                    if ( (yprev==3) && (y==0)) { return true; }
    053                    return false;
    054            }
    055
    056            private boolean isMStart(int yprev, int y) {
    057                    if ( (yprev==7) && (y==0)) { return true; }
    058                    return false;
    059            }
    060
    061            private boolean isMDon(int yprev, int y) {
    062                    if ( (yprev==11) && (y==8)) { return true; }
    063                    if ( (yprev==10) && (y==7)) { return true; }
    064                    if ( (yprev==12) && (y==9)) { return true; }
    065                    return false;
    066            }
    067
    068            private boolean isMAcc(int yprev, int y) {
    069                    if ( (yprev==9) && (y==11)) { return true; }
    070                    if ( (yprev==8) && (y==10)) { return true; }
    071                    if ( (yprev==7) && (y==12)) { return true; }
    072                    return false;
    073            }
    074
    075            private boolean isMStop(int yprev, int y) {
    076                    if ( (yprev==0) && (y==9)) { return true; }
    077                    return false;
    078            }
    079    }