-
- public RNA trimRNA(RNA rna){
- RNA rnaTrim = new RNA("trim_"+rna.getName());
- try {
- rnaTrim.setRNA(rna.getSeq(),replaceOddGaps(rna.getStructDBN()));
- } catch (ExceptionUnmatchedClosingParentheses e2) {
- e2.printStackTrace();
- } catch (ExceptionFileFormatOrSyntax e3) {
- e3.printStackTrace();
- }
-
- StringBuffer seq=new StringBuffer(rnaTrim.getSeq());
- StringBuffer struc=new StringBuffer(rnaTrim.getStructDBN());
- for(int i=0;i<rnaTrim.getSeq().length();i++){
- //TODO: Jalview utility for gap detection java.utils.isGap()
- //TODO: Switch to jalview rna datamodel
- if(seq.substring(i, i+1).compareTo("-")==0 || seq.substring(i, i+1).compareTo(".")==0){
- if(!rnaTrim.findPair(i).isEmpty()){
- int m=rnaTrim.findPair(i).get(1);
- int l=rnaTrim.findPair(i).get(0);
-
- struc.replace(m, m+1, "*");
- struc.replace(l, l+1, "*");
- }else{
- struc.replace(i, i+1, "*");
- }
- }
- }
-
- String newSeq=rnaTrim.getSeq().replace("-", "");
- rnaTrim.getSeq().replace(".", "");
- String newStruc=struc.toString().replace("*", "");
-
- try {
- rnaTrim.setRNA(newSeq,newStruc);
- } catch (ExceptionUnmatchedClosingParentheses e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ExceptionFileFormatOrSyntax e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return rnaTrim;
+
+ public RNA trimRNA(RNA rna, String name)
+ {
+ ShiftList offset = new ShiftList();
+ RNA rnaTrim = new RNA(name);
+ try
+ {
+ rnaTrim.setRNA(rna.getSeq(), replaceOddGaps(rna.getStructDBN()));
+ } catch (ExceptionUnmatchedClosingParentheses e2)
+ {
+ e2.printStackTrace();
+ } catch (ExceptionFileFormatOrSyntax e3)
+ {
+ e3.printStackTrace();
+ }
+
+ StringBuffer seq = new StringBuffer(rnaTrim.getSeq());
+ StringBuffer struc = new StringBuffer(rnaTrim.getStructDBN());
+ int ofstart = -1, sleng = rnaTrim.getSeq().length();
+ for (int i = 0; i < sleng; i++)
+ {
+ // TODO: Jalview utility for gap detection java.utils.isGap()
+ // TODO: Switch to jalview rna datamodel
+ if (jalview.util.Comparison.isGap(seq.charAt(i)))
+ {
+ if (ofstart == -1)
+ {
+ ofstart = i;
+ }
+ if (!rnaTrim.findPair(i).isEmpty())
+ {
+ int m = rnaTrim.findPair(i).get(1);
+ int l = rnaTrim.findPair(i).get(0);
+
+ struc.replace(m, m + 1, "*");
+ struc.replace(l, l + 1, "*");
+ }
+ else
+ {
+ struc.replace(i, i + 1, "*");
+ }
+ }
+ else
+ {
+ if (ofstart > -1)
+ {
+ offset.addShift(offset.shift(ofstart), ofstart - i);
+ ofstart = -1;
+ }
+ }
+ }
+ // final gap
+ if (ofstart > -1)
+ {
+ offset.addShift(offset.shift(ofstart), ofstart - sleng);
+ ofstart = -1;
+ }
+ String newSeq = rnaTrim.getSeq().replace("-", "");
+ rnaTrim.getSeq().replace(".", "");
+ String newStruc = struc.toString().replace("*", "");
+
+ try
+ {
+ rnaTrim.setRNA(newSeq, newStruc);
+ registerOffset(rnaTrim, offset);
+ } catch (ExceptionUnmatchedClosingParentheses e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ExceptionFileFormatOrSyntax e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return rnaTrim;
+ }
+
+ // needs to be many-many
+ Map<RNA, SequenceI> seqs = new Hashtable<RNA, SequenceI>();
+
+ Map<SequenceI, RNA> rnas = new Hashtable<SequenceI, RNA>();
+
+ Map<RNA, ShiftList> offsets = new Hashtable<RNA, ShiftList>();
+
+ Map<RNA, ShiftList> offsetsInv = new Hashtable<RNA, ShiftList>();
+
+ private void registerOffset(RNA rnaTrim, ShiftList offset)
+ {
+ offsets.put(rnaTrim, offset);
+ offsetsInv.put(rnaTrim, offset.getInverse());