⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hmm.java

📁 马尔科夫模型的c语言实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    case 1:		HMM.alphabet = D;		break;	    case 2:		HMM.alphabet_2 = D;		break;	    case 3:		HMM.alphabet_3 = D;		break;	    case 4:		HMM.alphabet_4 = D;		break;		    }	    break;	case AMINO_GAP:	    switch(nr) {	    case 1:		HMM.alphabet = A_gap;		break;	    case 2:		HMM.alphabet_2 = A_gap;		break;	    case 3:		HMM.alphabet_3 = A_gap;		break;	    case 4:		HMM.alphabet_4 = A_gap;		break;		    }	    break;	case AMINO_DOUBLE_GAP:	    switch(nr) {	    case 1:		HMM.alphabet = A_double_gap;		break;	    case 2:		HMM.alphabet_2 = A_double_gap;		break;	    case 3:		HMM.alphabet_3 = A_double_gap;		break;	    case 4:		HMM.alphabet_4 = A_double_gap;		break;		    }	    break;        default:	    System.out.println("nr = " + nr + ": alpha = " + alphabet);            P.INTERNAL_ERROR("HMM.setAlphabet multi: Unrecognized alphabet type");        }    }                     public void setAlphabet(String[] alphabet)    {        HMM.alphabet=alphabet;    }    public void setAlphabet(int nr, String[] alphabet)    {	switch(nr) {	case 1: 	    HMM.alphabet=alphabet;	    break;	case 2:	    HMM.alphabet_2=alphabet;	    break;	case 3: 	    HMM.alphabet_3=alphabet;	    break;	case 4:	    HMM.alphabet_4=alphabet;	    break;	}    }        public void setTransition(String fromModule, String toModule)    {        /* Get out-vertices from the from-module and in-vertices           from the to-module and add transition */                Module from = (Module)theModules.get(fromModule);        Module to = (Module)theModules.get(toModule);        if(to.getVertexType() == HMM.START) {            P.MESSAGE("Transition from " + fromModule + " to " + toModule +                       " already exists or is illegal");            return;        }        int[] inVertices = to.getInVertices();        if(to.getVertexType() == HMM.END  && from.getVertexType() != HMM.END) {            for(int i = 0; i < inVertices.length; i++) {                if(from.addEndTransition(inVertices[i])) {                    P.MESSAGE("Added end transition from " + fromModule + " to " + toModule);                                    }                else {                    P.MESSAGE("End transition from " + fromModule + " to " + toModule +                               " already exists or is illegal");                }            }        }        else {            for(int i = 0; i < inVertices.length; i++) {                if(from.addTransition(inVertices[i])) {                    P.MESSAGE("Added transition from " + fromModule + " to " + toModule);                }                else {                    P.MESSAGE("Transition from " + fromModule + " to " + toModule +                               " already exists or is illegal");                }            }        }    }    public void setInternalInitDistrib(String name, InternalInitDistrib iid)    {	Module m = ((Module)theModules.get(name));	m.setInternalInitDistrib(iid);    }    /********************CREATE and ADD methods*****************************************/    public int createModule(String name, int moduleType, int distribType, int size, String label, boolean global)    {        /* Check for doubles */        if(theModules.containsKey(name)) {            return DOUBLENAME;        }	if(size <= 0) {	    return INCORRECT_SIZE;	}        Module m;        switch (moduleType) {        case HMM.SINGLENODE:            m = new SingleNode(name, distribType, STANDARD, label);            theModuleList.add(m);            theModules.put(name, m);	    m.addVerticesToVertexHash(theVertices);            P.MESSAGE("Created singlenode module with name '"+name+"'");            break;        case HMM.STARTNODE:            m = new SingleNode(name, distribType, START, label);            theModuleList.add(m);            theModules.put(name, m);	    m.addVerticesToVertexHash(theVertices);            P.MESSAGE("Created startnode module with name '"+name+"'");            break;        case HMM.ENDNODE:            m = new SingleNode(name, distribType, END, label);            theModuleList.add(m);            theModules.put(name, m);	    m.addVerticesToVertexHash(theVertices);            P.MESSAGE("Created endnode module with name '"+name+"'");            break;        case HMM.CLUSTER:            m = new Cluster(name, distribType, STANDARD, size, label);            theModuleList.add(m);            theModules.put(name, m);	    m.addVerticesToVertexHash(theVertices);            P.MESSAGE("Created cluster module with name '"+name+"'");            break;	case HMM.SINGLELOOP:	    m = new SingleLoop(name, distribType, STANDARD, size, label);	    theModuleList.add(m);            theModules.put(name, m);	    m.addVerticesToVertexHash(theVertices);	    P.MESSAGE("Created singleloop module with name '"+name+"'");            break;	case HMM.PROFILE7:	    if(size < 2) {		return INCORRECT_SIZE;	    }	    m = new Profile7(name, distribType, STANDARD, size, label, global);	    theModuleList.add(m);            theModules.put(name, m);	    m.addVerticesToVertexHash(theVertices);	    P.MESSAGE("Created profile module with name '"+name+"'");	    break;	case HMM.PROFILE9:	    if(size < 2) {		return INCORRECT_SIZE;	    }	    m = new Profile9(name, distribType, STANDARD, size, label, global);	    theModuleList.add(m);            theModules.put(name, m);	    m.addVerticesToVertexHash(theVertices);	    P.MESSAGE("Created profile module with name '"+name+"'");	    break;	case HMM.U_TURN:	    if(size < 1) {		return INCORRECT_SIZE;	    }	    m = new U_Turn(name, distribType, STANDARD, size, label);	    theModuleList.add(m);            theModules.put(name, m);	    m.addVerticesToVertexHash(theVertices);	    P.MESSAGE("Created profile module with name '"+name+"'");	    break;	    	    /* add more modules here */	            default:            P.INTERNAL_ERROR("HMM.createModule: Unrecognized module type");                    }        return OKNAME;    }        public int createModule(String name, int moduleType, int distribType,			    int intervalStart, int intervalEnd, String label)    {        /* Check for doubles */        if(theModules.containsKey(name)) {            return DOUBLENAME;        }	if(intervalStart >= intervalEnd) {	    return INCORRECT_SIZE;	}        Module m;        switch (moduleType) {	case HMM.FORWARD_STD:            m = new Forward_std(name, distribType, STANDARD, intervalStart, intervalEnd, label);            theModuleList.add(m);            theModules.put(name, m);            P.MESSAGE("Created forward_std  module with name '"+name+"'");            break;	case HMM.FORWARD_ALT:	    m = new Forward_alt(name, distribType, STANDARD, intervalStart, intervalEnd, label);            theModuleList.add(m);            theModules.put(name, m);            P.MESSAGE("Created forward_std  module with name '"+name+"'");            break;	default:            P.INTERNAL_ERROR("HMM.createModule: Unrecognized module type");        }        return OKNAME;    }        public void addDistributionGroup(LinkedList group)    {	theDistributionGroups.add(group);	/* also check the emission probabilities for the nodes in the same	 * distribution group, they should be the same, and if they're not,	 * make them the same by forcing them all to have the same probs as	 * the first node in the list */	Module cur = null;	Module last = null;	ListIterator i = (ListIterator)group.iterator();	if(i.hasNext()) {	    cur = (Module)theModules.get(i.next());	    nrOfDistributionGroupVertices = nrOfDistributionGroupVertices + cur.getSize();	}	for(;i.hasNext();) {	    last = cur;	    cur = (Module)theModules.get(i.next());	    nrOfDistributionGroupVertices = nrOfDistributionGroupVertices + cur.getSize();	    if(cur.getDistribType() != last.getDistribType()) {		P.MESSAGE("Warning: Different initial probability types for modules in same " +			  "distribution group detected - autocorrecting");		double[] distribution = last.getEmissionProbs();		int distribType = last.getDistribType();		cur.setDistribType(distribType, distribution);	    }	    else if(cur.getDistribType() == HMM.RANDOM && last.getDistribType() == HMM.RANDOM) {		double[] distribution = last.getEmissionProbs();		int distribType = last.getDistribType();		cur.setDistribType(distribType, distribution);	    }	    	}	nrOfDistributionGroups++;    }        public void addPriorfile(String s)    {	if(s != null) {	    thePriorfiles.add(s);	}    }    public void addPriorfile(int nr, String s)    {	if(s != null) {	    switch(nr){	    case 1: 		thePriorfiles.add(s);		break;	    case 2:		thePriorfiles_2.add(s);		break;	    case 3: 		thePriorfiles_3.add(s);		break;	    case 4:		thePriorfiles_4.add(s);		break;		    }	}    }    public void addTransPriorfile(String s)    {	if(s != null) {	    theTransPriorfiles.add(s);	}    }    public void addTransTieGroup(LinkedList group)    {	theTransTieGroups.add(group);	ListIterator li = group.listIterator();	LinkedList nrTransList = new LinkedList();	while(li.hasNext()) {	    Module m = getModule(((String)li.next()));	    if(nrTransList.contains(new Integer(m.getNrOfRegularTransitions()))) {		nrOfTransTieGroupVertices = nrOfTransTieGroupVertices + m.getNrOfRegularTransitions();	    }	    else {		nrOfTransTieGroups = nrOfTransTieGroups + m.getNrOfRegularTransitions();		nrTransList.add(new Integer(m.getNrOfRegularTransitions()));		nrOfTransTieGroupVertices = nrOfTransTieGroupVertices + m.getNrOfRegularTransitions();	    }	   	}    }        /*************************MISC methods*************************************/    public void initializeTransitionProbabilities(String name)    {	Module module = (Module)theModules.get(name);		if(module == null) /* just double checking */{	    P.INTERNAL_ERROR("HMM.initializeTransitionProbabilities: module doesn't exist");	}	else {	    module.initializeTransitionProbabilities();	}    }    public boolean writeModule(String moduleName, BufferedWriter writer)    {	Module module = (Module)theModules.get(moduleName);	if(module == null) /* just checking */{	    P.INTERNAL_ERROR("HMM.moduleToString: module doesn't exist");	    return false;	}		else {	    return module.write(nrOfAlphabets, writer);	}    }        public boolean identicalModules(String moduleA, String moduleB)    {	/* modules are considered identical if they are of the same type	 * and the same size */	Module A = getModule(moduleA);	Module B = getModule(moduleB);	if(A instanceof SingleNode && B instanceof SingleNode) {	    return true;	}	else if(A instanceof SingleLoop && B instanceof SingleLoop) {	    return true;	}	else if(A instanceof Forward_std && B instanceof Forward_std) {	    if(A.getSize() == B.getSize()) {		return true;	    }	}	else if(A instanceof Forward_alt && B instanceof Forward_alt) {	    if(A.getSize() == B.getSize()) {		return true;	    }	}	else if(A instanceof Cluster && B instanceof Cluster) {	    if(A.getSize() == B.getSize()) {		return true;	    }	}	else if(A instanceof Profile7 && B instanceof Profile7) {	    if(A.getSize() == B.getSize()) {		return true;	    }	}	else if(A instanceof Profile9 && B instanceof Profile9) {	    if(A.getSize() == B.getSize()) {		return true;	    }	}	return false;    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -