1 package fr.orsay.lri.varna.factories;
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
6 import java.util.Comparator;
7 import java.util.Hashtable;
8 import java.util.Stack;
10 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
11 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
12 import fr.orsay.lri.varna.models.rna.RNA;
15 * BH SwingJS -- must explicitly check for array out of bounds
17 public class RNAAlignment {
18 private ArrayList<String> _lst = new ArrayList<String> ();
19 private Hashtable<String, Integer> _index = new Hashtable<String, Integer> ();
20 private Hashtable<String, String> _accession = new Hashtable<String, String> ();
21 private String _secStr = "";
23 public void addSequence(String id, String s)
25 if (!_index.containsKey(id))
27 _index.put(id,_lst.size());
30 _lst.set(_index.get(id),s);
33 public void setSecStr(String s)
38 public void setAccession(String id, String AC)
40 _accession.put(id,AC);
43 public ArrayList<RNA> getRNAs() throws ExceptionUnmatchedClosingParentheses
45 ArrayList<RNA> result = new ArrayList<RNA>();
46 int[] str = RNAFactory.parseSecStr(_secStr);
47 ArrayList<String> ids = new ArrayList<String>(_index.keySet());
48 Collections.sort(ids,new Comparator<String>(){
49 public int compare(String o1, String o2) {
50 return o1.compareToIgnoreCase(o2);
54 int n = _index.get(id);
55 String seq = _lst.get(n);
56 if (seq.length() != str.length)
57 throw new ArrayIndexOutOfBoundsException(); // BH SwingJS -- must explicitly check for array out of bounds
60 for(int i=0;i<seq.length();i++)
62 char c = seq.charAt(i);
65 if (!(c=='.' || c==':' || c=='-'))
74 int cp = seq.charAt(j);
75 if (cp=='.' || cp==':' || cp=='-')
81 nstr += _secStr.charAt(i);
90 if (_accession.containsKey(id))
92 r.setID(_accession.get(id));
99 } catch (ExceptionFileFormatOrSyntax e) {
100 // TODO Auto-generated catch block