X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src2%2Ffr%2Forsay%2Flri%2Fvarna%2Ffactories%2FRNAAlignment.java;fp=src2%2Ffr%2Forsay%2Flri%2Fvarna%2Ffactories%2FRNAAlignment.java;h=0cbf17c12181b41aae8db0455c322a064157f94f;hb=9f55415c9f8005e9dcd8243453883ff853fd5b76;hp=0000000000000000000000000000000000000000;hpb=d8e8c742b864e58406d13e21d124699a26b6492f;p=jalview.git diff --git a/src2/fr/orsay/lri/varna/factories/RNAAlignment.java b/src2/fr/orsay/lri/varna/factories/RNAAlignment.java new file mode 100644 index 0000000..0cbf17c --- /dev/null +++ b/src2/fr/orsay/lri/varna/factories/RNAAlignment.java @@ -0,0 +1,106 @@ +package fr.orsay.lri.varna.factories; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Hashtable; +import java.util.Stack; + +import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax; +import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses; +import fr.orsay.lri.varna.models.rna.RNA; + +/** + * BH SwingJS -- must explicitly check for array out of bounds + */ +public class RNAAlignment { + private ArrayList _lst = new ArrayList (); + private Hashtable _index = new Hashtable (); + private Hashtable _accession = new Hashtable (); + private String _secStr = ""; + + public void addSequence(String id, String s) + { + if (!_index.containsKey(id)) + { + _index.put(id,_lst.size()); + _lst.add(s); + } + _lst.set(_index.get(id),s); + } + + public void setSecStr(String s) + { + _secStr = s; + } + + public void setAccession(String id, String AC) + { + _accession.put(id,AC); + } + + public ArrayList getRNAs() throws ExceptionUnmatchedClosingParentheses + { + ArrayList result = new ArrayList(); + int[] str = RNAFactory.parseSecStr(_secStr); + ArrayList ids = new ArrayList(_index.keySet()); + Collections.sort(ids,new Comparator(){ + public int compare(String o1, String o2) { + return o1.compareToIgnoreCase(o2); + }}); + for (String id: ids ) + { + int n = _index.get(id); + String seq = _lst.get(n); + if (seq.length() != str.length) + throw new ArrayIndexOutOfBoundsException(); // BH SwingJS -- must explicitly check for array out of bounds + String nseq =""; + String nstr =""; + for(int i=0;i