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

📄 nexus.java

📁 生物物种进化历程的演示
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Generated By:JavaCC: Do not edit this line. Nexus.java */package Parser.nexus;//import Parse.*;import AccordionTreeDrawer.Tree;import AccordionTreeDrawer.TreeNode;import java.util.*;/**  * A static class used for parsing a Nexus format file containing multiple trees. * Given a Nexus tree file and an index number, the parser will find the corresponding  * tree with the given index number and initiate a tree object for it.  * @author Yunhong Zhou */public class Nexus implements NexusConstants {  /** the target tree to be initiated by the parser */  private static Tree tree;  /** the current TreeNode that the parser is visiting and initiating */  private static TreeNode current_node;  /** a helper TreeNode field */  private static TreeNode tn;  /** the index of the tree to be initiated from the collection of trees in the nexus file */  private static int index;  /** flag is true if the parser is visiting the target tree */  private static boolean flag;  private static int cnt;  /**    * transflag is true if the nexus file has a translation header.    * If transflag is true, then we need to translate the leaf label to its real name.   */  private static boolean transflag = false;  /** the hashtable ht_trans stores entries for label translation process */  private static Hashtable ht_trans;  /**    * function parseTree initiates field tree, call function Input to parse the input.   * @param t Tree t will be initiated throught the parsing process    * @param index The index of the tree to be initiated from parsing    * @author Yunhong Zhou   */  public void parseTree(Tree t, int index) {    tree = t;    this.index = index;    try{ Input(); }    catch( ParseException e ){        if(t.getName() == null)          System.out.println("Parsing error with input!");        else          System.out.println("Parsing error with input file " + t.getName());        e.printStackTrace();    }  }  static final public void Input() throws ParseException {  cnt = 0;    label_1:    while (true) {      if (jj_2_1(2)) {        jj_consume_token(token_tree);        tree_newick();      } else if (jj_2_2(2)) {        jj_consume_token(translate);        trans_statement();      } else if (jj_2_3(2)) {        jj_consume_token(unquoted_string);        other_statement();      } else {        jj_consume_token(-1);        throw new ParseException();      }      if (jj_2_4(2)) {        ;      } else {        break label_1;      }    }    jj_consume_token(0);  }  static final public void other_statement() throws ParseException {    label_2:    while (true) {      if (jj_2_5(2)) {        ;      } else {        break label_2;      }      if (jj_2_6(2)) {        jj_consume_token(unquoted_string);      } else if (jj_2_7(2)) {        jj_consume_token(quoted_string);      } else if (jj_2_8(2)) {        jj_consume_token(double_number);      } else if (jj_2_9(2)) {        jj_consume_token(token_tree);      } else if (jj_2_10(2)) {        jj_consume_token(equal);      } else if (jj_2_11(2)) {        jj_consume_token(lparen);      } else if (jj_2_12(2)) {        jj_consume_token(rparen);      } else if (jj_2_13(2)) {        jj_consume_token(comma);      } else if (jj_2_14(2)) {        jj_consume_token(colon);      } else {        jj_consume_token(-1);        throw new ParseException();      }    }    jj_consume_token(semicolon);  }/**  * function trans_statement generates a hash table for label translation */  static final public void trans_statement() throws ParseException {  String s_key, s_value;  transflag = true;  ht_trans = new Hashtable();  Hashtable ht_values = new Hashtable();    label_3:    while (true) {      s_key = label_text();      s_value = label_text();      if (jj_2_15(2)) {        jj_consume_token(comma);      } else {        ;      }      String prev_key = (String)(ht_values.get(s_value));      if(prev_key != null){        StringBuffer sb = new StringBuffer(s_value);        sb.append(" ").append(s_key);        ht_trans.put(s_key, sb.toString());        if(!prev_key.equals("-1")){          sb = new StringBuffer(s_value);          sb.append(" ").append(prev_key);          ht_trans.put(prev_key, sb.toString());          ht_values.put(s_value, "-1");        }      }else{        ht_trans.put(s_key, s_value);        ht_values.put(s_value, s_key);      }      if (jj_2_16(2)) {        ;      } else {        break label_3;      }    }    jj_consume_token(semicolon);    ht_values = null;  }/** this function is responsible for parsing one tree */  static final public void tree_newick() throws ParseException {  String s;  double len;    jj_consume_token(unquoted_string);    jj_consume_token(equal);    cnt++; flag = (cnt == index)?true:false;    if(flag)current_node = tree.getRoot();    descendant_list();    if (jj_2_17(2)) {      s = label();                  if(flag)current_node.setName(s);                  //System.out.println("Name: " + s);    } else {      ;    }    if (jj_2_18(2)) {      jj_consume_token(colon);      len = branch_length();                                    if(flag)current_node.setWeight(len);                                //System.out.println("weight: " + len);     } else {      ;    }    jj_consume_token(semicolon);  }  static final public void descendant_list() throws ParseException {    jj_consume_token(lparen);             if(flag){        tn = new TreeNode();        current_node.addChild(tn);        current_node = tn;        }    subtree();    label_4:    while (true) {      if (jj_2_19(2)) {        ;      } else {        break label_4;      }      jj_consume_token(comma);              if(flag){          tn = new TreeNode();          current_node.addChild(tn);          current_node = tn;          }      subtree();    }    jj_consume_token(rparen);  }/** function subtree will set name, length and weight for each tree node */  static final public void subtree() throws ParseException {  String s;  double len;    if (jj_2_24(2)) {      descendant_list();      if (jj_2_20(2)) {        s = label();                  if(flag)current_node.setName(s);                  //System.out.println("Name: " + s);       } else {        ;      }      if (jj_2_21(2)) {        jj_consume_token(colon);        len = branch_length();                                    if(flag)current_node.setWeight(len);                                //System.out.println("Weight: " + len);      } else {        ;      }         if(flag)current_node = current_node.parent();    } else {      if (jj_2_22(2)) {        s = label();                  if(flag)current_node.setName(s);                  //System.out.println("Name: " + s);       } else {        ;      }      if (jj_2_23(2)) {        jj_consume_token(colon);        len = branch_length();                                    if(flag)current_node.setWeight(len);                                //System.out.println("Weight: " + len);      } else {        ;      }         if(flag)current_node = current_node.parent();    }  }/** get the real name for each label, translate if necessary */  static final public String label() throws ParseException {  String s, s_trans = null; Token t;    s = label_text();                     if(transflag && flag){                       s_trans = (String)ht_trans.get(s);                       if(s_trans != null){                         {if (true) return s_trans;}                       }else {if (true) return s;}                     }else {if (true) return s;}                     // TODO : integer index    throw new Error("Missing return statement in function");  }/**  * for each unquoted label, we need to replace '_' by ' '. * for each quoted label, we remove double quotes from the string. */  static final public String label_text() throws ParseException {  String s; Token t;    if (jj_2_25(2)) {      t = jj_consume_token(unquoted_string);                          s = new String(t.toString());                          {if (true) return s.replace('_', ' ');}    } else if (jj_2_26(2)) {      t = jj_consume_token(quoted_string);                        s = new String(t.toString());                        {if (true) return s.substring(1, s.length()-1).replaceAll("[\n\r\f]", "");}    } else if (jj_2_27(2)) {      t = jj_consume_token(double_number);                        {if (true) return new String(t.toString());}    } else {      jj_consume_token(-1);      throw new ParseException();    }    throw new Error("Missing return statement in function");  }  static final public double branch_length() throws ParseException {  Token t;    t = jj_consume_token(double_number);                        {if (true) return Double.parseDouble(t.toString());}    throw new Error("Missing return statement in function");  }  static final private boolean jj_2_1(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_1(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(0, xla); }  }  static final private boolean jj_2_2(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_2(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(1, xla); }  }  static final private boolean jj_2_3(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_3(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(2, xla); }  }  static final private boolean jj_2_4(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_4(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(3, xla); }  }  static final private boolean jj_2_5(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_5(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(4, xla); }  }  static final private boolean jj_2_6(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_6(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(5, xla); }  }  static final private boolean jj_2_7(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_7(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(6, xla); }  }  static final private boolean jj_2_8(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_8(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(7, xla); }  }  static final private boolean jj_2_9(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_9(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(8, xla); }  }  static final private boolean jj_2_10(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_10(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(9, xla); }  }  static final private boolean jj_2_11(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_11(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(10, xla); }  }  static final private boolean jj_2_12(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_12(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(11, xla); }  }  static final private boolean jj_2_13(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_13(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(12, xla); }  }  static final private boolean jj_2_14(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_14(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(13, xla); }  }  static final private boolean jj_2_15(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_15(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(14, xla); }  }  static final private boolean jj_2_16(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_16(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(15, xla); }  }  static final private boolean jj_2_17(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_17(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(16, xla); }  }  static final private boolean jj_2_18(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_18(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(17, xla); }  }  static final private boolean jj_2_19(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_19(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(18, xla); }  }  static final private boolean jj_2_20(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_20(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(19, xla); }  }  static final private boolean jj_2_21(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_21(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(20, xla); }  }  static final private boolean jj_2_22(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_22(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(21, xla); }  }  static final private boolean jj_2_23(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_23(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(22, xla); }  }  static final private boolean jj_2_24(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_24(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(23, xla); }  }  static final private boolean jj_2_25(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_25(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(24, xla); }  }  static final private boolean jj_2_26(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_26(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(25, xla); }  }  static final private boolean jj_2_27(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    try { return !jj_3_27(); }    catch(LookaheadSuccess ls) { return true; }    finally { jj_save(26, xla); }  }  static final private boolean jj_3_18() {    if (jj_scan_token(colon)) return true;    if (jj_3R_10()) return true;    return false;  }  static final private boolean jj_3_17() {    if (jj_3R_9()) return true;    return false;  }  static final private boolean jj_3_9() {    if (jj_scan_token(token_tree)) return true;    return false;  }  static final private boolean jj_3R_10() {    if (jj_scan_token(double_number)) return true;    return false;  }  static final private boolean jj_3R_5() {    if (jj_scan_token(unquoted_string)) return true;    return false;  }  static final private boolean jj_3_27() {    if (jj_scan_token(double_number)) return true;    return false;  }  static final private boolean jj_3_26() {    if (jj_scan_token(quoted_string)) return true;    return false;  }

⌨️ 快捷键说明

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