📄 profile7.java
字号:
import java.util.*;import java.io.*;class Profile7 extends Module{ final double INIT_DD_PROB = 0.8; final double INIT_DM_PROB = 0.2; final double INIT_MD_PROB = 0.025; final double INIT_MM_PROB = 0.925; final double INIT_MI_PROB = 0.025; final double INIT_EXIT_PROB = 0.025; final double INIT_IM_PROB = 0.2; final double INIT_II_PROB = 0.8; final double INIT_NA_CLOSE_PROB = 0.01; final double INIT_NA_LOOP_PROB = 0.99; final double INIT_NA_OPEN_PROB = 0.01; final double INIT_A_OPEN_PROB = 0.99; String name; LinkedList theVertices; LinkedList theMatchVertices; LinkedList theDeleteVertices; LinkedList theInsertVertices; Vertex[] theOutVertices; int nrVertices; int vertexType; int distribType; int distribType_2; int distribType_3; int distribType_4; String label; String priorfile; String priorfile_2; String priorfile_3; String priorfile_4; String transPriorfile; int size; /* Default constructor making all vertices in/out vertices */ public Profile7(String name, int distribType, int vertexType, int size, String label, boolean global) { createProfile7Module(name, vertexType, size, label, distribType, null, true, global); } public Profile7(String name, double[] initDistrib, int vertexType, int size, String label, boolean global) { createProfile7Module(name, vertexType, size, label, 0, initDistrib, false, global); } private void createProfile7Module(String name, int vertexType, int size, String label, int distribType, double[] initDistrib, boolean autoDistrib, boolean global) { this.name = name; this.vertexType = vertexType; if(autoDistrib) { this.distribType = distribType; this.distribType_2 = distribType; this.distribType_3 = distribType; this.distribType_4 = distribType; } this.label = label; theVertices = new LinkedList(); theDeleteVertices = new LinkedList(); theMatchVertices = new LinkedList(); theInsertVertices = new LinkedList(); nrVertices = size * 3 + 4; inVertices = new int[1]; outVertices = new int[1]; theOutVertices = new Vertex[1]; priorfile = null; priorfile_2 = null; priorfile_3 = null; priorfile_4 = null; transPriorfile = null; /* create the vertices */ Vertex d0 = new Vertex(name, HMM.SILENT, HMM.ZERO, "D"); theVertices.add(d0); theDeleteVertices.add(d0); inVertices[0] = d0.getNumber(); Vertex N = null; if(autoDistrib) { N = new Vertex(name, HMM.STANDARD, distribType, "I"); } else { N = new Vertex(name, HMM.STANDARD, initDistrib, "I"); } theVertices.add(N); theInsertVertices.add(N); Vertex d1 = new Vertex(name, HMM.SILENT, HMM.ZERO, "D"); theVertices.add(d1); theDeleteVertices.add(d1); Vertex m1 = null; if(autoDistrib) { m1 = new Vertex(name, HMM.STANDARD, distribType, "M"); } else { m1 = new Vertex(name, HMM.STANDARD, initDistrib, "M"); } theVertices.add(m1); theMatchVertices.add(m1); Vertex i1 = null; if(autoDistrib) { i1 = new Vertex(name, HMM.STANDARD, distribType, "I"); } else { i1 = new Vertex(name, HMM.STANDARD, initDistrib, "I"); } theVertices.add(i1); theInsertVertices.add(i1); for(int j = 1; j < (nrVertices - 3)/3; j++) { Vertex d = new Vertex(name, HMM.SILENT, HMM.ZERO, "D"); theVertices.add(d); theDeleteVertices.add(d); Vertex m = new Vertex(name, HMM.STANDARD, m1.getEmissionProbs(), "M"); theVertices.add(m); theMatchVertices.add(m); if(j < (nrVertices - 6)/3) { Vertex i = new Vertex(name, HMM.STANDARD, i1.getEmissionProbs(), "I"); theVertices.add(i); theInsertVertices.add(i); } } Vertex d_last = new Vertex(name, HMM.SILENT, HMM.ZERO, "D"); theVertices.add(d_last); theDeleteVertices.add(d_last); Vertex i = new Vertex(name, HMM.STANDARD, i1.getEmissionProbs(), "I"); theVertices.add(i); theInsertVertices.add(i); Vertex d = new Vertex(name, HMM.SILENT, HMM.ZERO, "D"); theVertices.add(d); theDeleteVertices.add(d); outVertices[0] = d.getNumber(); theOutVertices[0] = d; int d_last_nr = d_last.getNumber(); /* add transitions between vertices according to plan7 architecture, that is * no delete-insert or insert-delete transitions */ ListIterator ds = theDeleteVertices.listIterator(); ListIterator ms = theMatchVertices.listIterator(); ListIterator is = theInsertVertices.listIterator(); d = null; Vertex d_first = null; Vertex m = null; i = null; int d_first_nr = 0; int m_nr = 0; int i_nr = 0; int d_nr = 0; if(ds.hasNext() && ms.hasNext() && is.hasNext()) { d_first = (Vertex)ds.next(); if(ds.hasNext()) { d = (Vertex)ds.next(); } m = (Vertex)ms.next(); i = (Vertex)is.next(); d_first_nr = d_first.getNumber(); m_nr = m.getNumber(); i_nr = i.getNumber(); d_nr = d.getNumber(); i.addTransition(d_first_nr, INIT_NA_CLOSE_PROB, true); i.addTransition(i_nr, INIT_NA_LOOP_PROB, true); d_first.addTransition(i_nr, INIT_NA_OPEN_PROB, true); d_first.addTransition(m_nr, INIT_A_OPEN_PROB / ((double)((size + 1))), true); d_first.addTransition(d_nr, INIT_A_OPEN_PROB / ((double)((size + 1))), true); } while(ds.hasNext() && ms.hasNext() && is.hasNext()) { Vertex d_next = (Vertex)ds.next(); Vertex m_next = (Vertex)ms.next(); Vertex i_next = (Vertex)is.next(); int d_next_nr = d_next.getNumber(); int m_next_nr = m_next.getNumber(); int i_next_nr = i_next.getNumber(); d.addTransition(d_next_nr, INIT_DD_PROB, true); d.addTransition(m_next_nr, INIT_DM_PROB, true); m.addTransition(d_next_nr, INIT_MD_PROB, true); m.addTransition(m_next_nr, INIT_MM_PROB, true); m.addTransition(i_next_nr, INIT_MI_PROB, true); if(!global) { m.addTransition(d_last_nr, INIT_EXIT_PROB, true); } i_next.addTransition(m_next_nr, INIT_IM_PROB, true); i_next.addTransition(i_next_nr, INIT_II_PROB, true); if(!global) { d_first.addTransition(m_next_nr, INIT_A_OPEN_PROB / ((double)(size + 1)), true); } d = d_next; m = m_next; i = i_next; d_nr = d_next_nr; m_nr = m_next_nr; i_nr = i_next_nr; } if(ds.hasNext()) { d_last = (Vertex)ds.next(); d_last_nr = d_last.getNumber(); m.addTransition(d_last_nr, 1.0, true); d.addTransition(d_last_nr, 1.0, true); } if(is.hasNext() && ds.hasNext()) { i = (Vertex)is.next(); i_nr = i.getNumber(); d = (Vertex)ds.next(); d_nr = d.getNumber(); i.addTransition(d_last_nr, INIT_NA_CLOSE_PROB, true); i.addTransition(i_nr, INIT_NA_LOOP_PROB, true); d_last.addTransition(i_nr, INIT_NA_OPEN_PROB, true); d_last.addTransition(d_nr, INIT_EXIT_PROB, true); } size = theVertices.size(); } public int getSize() { return size; } public String getName() { return name; } public String getLabel() { return label; } public int getVertexType() { return vertexType; } public int getDistribType() { return distribType; } public String getPriorfile() { return priorfile; } public double[] getEmissionProbs() { Vertex v = (Vertex)theVertices.get(0); return v.getEmissionProbs(); } public int[] getInVertices() { return inVertices; } public LinkedList getVertices() { return theVertices; } public Vertex getVertex(int nr) { for(int i = 0; i < theVertices.size(); i++) { Vertex v = ((Vertex)theVertices.get(i)); if(v.getNumber() == nr) { return v; } } return null; } public int getNrOfTransitions() { int nrTransitions = 0; for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) { Vertex v = (Vertex)i.next(); nrTransitions = nrTransitions + v.getNrOfTransitions(); nrTransitions = nrTransitions + v.getNrOfEndTransitions(); } return nrTransitions; } public int getNrOfRegularTransitions() { int nrTransitions = 0; for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) { Vertex v = (Vertex)i.next(); nrTransitions = nrTransitions + v.getNrOfTransitions(); } return nrTransitions; } public int getNrOfEndTransitions() { int nrTransitions = 0; for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) { Vertex v = (Vertex)i.next(); nrTransitions = nrTransitions + v.getNrOfEndTransitions(); } return nrTransitions; } public int[] getOutVertices() { return outVertices; } public void setTransPriorScaler(double d) { for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) { Vertex v = (Vertex)i.next(); v.setTransPriorScaler(d); } } public void setEmissPriorScaler(double d) { for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) { Vertex v = (Vertex)i.next(); v.setEmissPriorScaler(d); } } public void setEmissPriorScaler(int nr, double d) { for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) { Vertex v = (Vertex)i.next(); v.setEmissPriorScaler(nr, d); } } public void setEmissPriorScalerInsert(int nr, double d) { for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) { Vertex v = (Vertex)i.next(); if(v.getLabel().equals("I")) { v.setEmissPriorScaler(nr, d); } } } public void lockVertexEmissions() { for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) { Vertex v = (Vertex)i.next(); v.lock(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -