public static String[] getFormatedSirnaSequences(HELM2Notation helm2notation, String paddingChar, String basePairChar) throws NotationException, RNAUtilsException, HELM2HandledException,
      org.helm.notation2.exception.NotationException,
      ChemistryException {
    if (null == paddingChar || paddingChar.length() != 1) {
      throw new NotationException(
          "Padding string must be single character");
    }

    if (null == basePairChar || basePairChar.length() != 1) {
      throw new NotationException(
          "Base pair string must be single character");
    }

    List<PolymerNotation> rnaList = getRNAPolymers(helm2notation.getListOfPolymers());
    int count = rnaList.size();
    if (count == 0) {
      return new String[0];
    } else if (count == 1) {
      return new String[] {RNAUtils.getSequence(rnaList.get(0))};
    } else if (count == 2) {
      String rna1Seq = null;
      String rna2Seq = null;
      String rna1Annotation = null;
      String rna2Annotation = null;
      PolymerNotation one = null;
      PolymerNotation two = null;

      for (PolymerNotation node : rnaList) {
        if (node.getPolymerID().getId().equals("RNA1")) {
          rna1Seq = RNAUtils.getSequence(node);
          rna1Annotation = node.getAnnotation();
          one = node;
        } else if (node.getPolymerID().getId().equals("RNA2")) {
          rna2Seq = RNAUtils.getSequence(node);
          two = node;
          rna2Annotation = node.getAnnotation();
        }
      }
      String reverseRna2Seq = RNAUtils.getReverseSequence(two);

      List<ConnectionNotation> connections = getAllBasePairConnections(helm2notation.getListOfConnections());
      if (null == connections || connections.size() == 0) {
        return new String[] {rna1Seq, rna2Seq};
      } else {
        Map<Integer, Integer> monomerPositionMap = getSirnaMonomerPositionMap(connections);
        Map<Integer, Integer> seqPositionMap = new HashMap<Integer, Integer>();
        Set<Integer> monomerSet = monomerPositionMap.keySet();
        for (Integer key : monomerSet) {
          Integer value = monomerPositionMap.get(key);
          Integer seqKey = new Integer(key.intValue() / 3 + 1);
          Integer seqValue = new Integer(value.intValue() / 3 + 1);
          seqPositionMap.put(seqKey, seqValue);
        }

        Set<Integer> seqSet = seqPositionMap.keySet();
        List<Integer> seqList = new ArrayList<Integer>();
        for (Integer key : seqSet) {
          seqList.add(key);
        }
        Collections.sort(seqList);

        int rna1First = seqList.get(0).intValue();
        int rna2Last = seqPositionMap.get(seqList.get(0)).intValue();
        int rna1Last = seqList.get(seqList.size() - 1).intValue();
        int rna2First = seqPositionMap.get(seqList.get(seqList.size() - 1)).intValue();

        if ((rna1Last - rna1First) != (rna2Last - rna2First)) {
          throw new NotationException(
              "siRNA matching lengths are different");
        }

        int rna1LeftOverhang = rna1First - 1;
        int rna1RightOverhang = rna1Seq.length() - rna1Last;
        int rna2LeftOverhang = rna2Seq.length() - rna2Last;
        int rna2RightOverhang = rna2First - 1;
        StringBuffer[] sbs = new StringBuffer[3];
        for (int i = 0; i < sbs.length; i++) {
          sbs[i] = new StringBuffer();
        }

        if (rna1LeftOverhang >= rna2LeftOverhang) {
          sbs[0].append(rna1Seq);

          for (int i = 0; i < rna1LeftOverhang; i++) {
            sbs[1].append(paddingChar);
          }
          for (int i = rna1First; i < (rna1Last + 1); i++) {
            Integer in = new Integer(i);
            if (seqPositionMap.containsKey(in)) {
              sbs[1].append(basePairChar);
            } else {
              sbs[1].append(paddingChar);
            }
          }

          for (int i = 0; i < rna1LeftOverhang - rna2LeftOverhang; i++) {
            sbs[2].append(paddingChar);
          }
          sbs[2].append(reverseRna2Seq);
        } else {
          for (int i = 0; i < rna2LeftOverhang - rna1LeftOverhang; i++) {
            sbs[0].append(paddingChar);
          }
          sbs[0].append(rna1Seq);

          for (int i = 0; i < rna2LeftOverhang; i++) {
            sbs[1].append(paddingChar);
          }
          for (int i = rna1First; i < (rna1Last + 1); i++) {
            Integer in = new Integer(i);
            if (seqPositionMap.containsKey(in)) {
              sbs[1].append(basePairChar);
            } else {
              sbs[1].append(paddingChar);
            }
          }

          sbs[2].append(reverseRna2Seq);
        }

        if (rna1RightOverhang >= rna2RightOverhang) {
          for (int i = 0; i < rna1RightOverhang; i++) {
            sbs[1].append(paddingChar);
          }

          for (int i = 0; i < rna1RightOverhang - rna2RightOverhang; i++) {
            sbs[2].append(paddingChar);
          }
        } else {
          for (int i = 0; i < rna2RightOverhang - rna1RightOverhang; i++) {
            sbs[0].append(paddingChar);
          }

          for (int i = 0; i < rna2RightOverhang - rna1RightOverhang; i++) {
            sbs[1].append(paddingChar);
          }
        }

        if ((rna1Annotation != null && rna1Annotation.equalsIgnoreCase("AS"))
            || (rna2Annotation != null && rna2Annotation.equalsIgnoreCase("SS"))) {
          return new String[] {reverseString(sbs[2].toString()),
              reverseString(sbs[1].toString()),
              reverseString(sbs[0].toString())};
        } else {
          return new String[] {sbs[0].toString(), sbs[1].toString(),
              sbs[2].toString()};
        }
      }

    } else {
      throw new NotationException(
          "Structure contains more than two RNA sequences");
    }

  }
public static String [ ] getFormatedSirnaSequences ( HELM2Notation helm2notation , String paddingChar , String basePairChar ) throws NotationException , RNAUtilsException , HELM2HandledException , org . helm . notation2 . exception . NotationException , ChemistryException { if ( null == paddingChar || paddingChar . length ( ) != 1 ) { throw new NotationException ( "Padding string must be single character" ) ; } if ( null == basePairChar || basePairChar . length ( ) != 1 ) { throw new NotationException ( "Base pair string must be single character" ) ; } List < PolymerNotation > rnaList = getRNAPolymers ( helm2notation . getListOfPolymers ( ) ) ; int count = rnaList . size ( ) ; if ( count == 0 ) { return new String [ 0 ] ; } else if ( count == 1 ) { return new String [ ] { RNAUtils . getSequence ( rnaList . get ( 0 ) ) } ; } else if ( count == 2 ) { String rna1Seq = null ; String rna2Seq = null ; String rna1Annotation = null ; String rna2Annotation = null ; PolymerNotation one = null ; PolymerNotation two = null ; for ( PolymerNotation node : rnaList ) { if ( node . getPolymerID ( ) . getId ( ) . equals ( "RNA1" ) ) { rna1Seq = RNAUtils . getSequence ( node ) ; rna1Annotation = node . getAnnotation ( ) ; one = node ; } else if ( node . getPolymerID ( ) . getId ( ) . equals ( "RNA2" ) ) { rna2Seq = RNAUtils . getSequence ( node ) ; two = node ; rna2Annotation = node . getAnnotation ( ) ; } } String reverseRna2Seq = RNAUtils . getReverseSequence ( two ) ; List < ConnectionNotation > connections = getAllBasePairConnections ( helm2notation . getListOfConnections ( ) ) ; if ( null == connections || connections . size ( ) == 0 ) { return new String [ ] { rna1Seq , rna2Seq } ; } else { Map < Integer , Integer > monomerPositionMap = getSirnaMonomerPositionMap ( connections ) ; Map < Integer , Integer > seqPositionMap = new HashMap < Integer , Integer > ( ) ; Set < Integer > monomerSet = monomerPositionMap . keySet ( ) ; for ( Integer key : monomerSet ) { Integer value = monomerPositionMap . get ( key ) ; Integer seqKey = new Integer ( key . intValue ( ) / 3 + 1 ) ; Integer seqValue = new Integer ( value . intValue ( ) / 3 + 1 ) ; seqPositionMap . put ( seqKey , seqValue ) ; } Set < Integer > seqSet = seqPositionMap . keySet ( ) ; List < Integer > seqList = new ArrayList < Integer > ( ) ; for ( Integer key : seqSet ) { seqList . add ( key ) ; } Collections . sort ( seqList ) ; int rna1First = seqList . get ( 0 ) . intValue ( ) ; int rna2Last = seqPositionMap . get ( seqList . get ( 0 ) ) . intValue ( ) ; int rna1Last = seqList . get ( seqList . size ( ) - 1 ) . intValue ( ) ; int rna2First = seqPositionMap . get ( seqList . get ( seqList . size ( ) - 1 ) ) . intValue ( ) ; if ( ( rna1Last - rna1First ) != ( rna2Last - rna2First ) ) { throw new NotationException ( "siRNA matching lengths are different" ) ; } int rna1LeftOverhang = rna1First - 1 ; int rna1RightOverhang = rna1Seq . length ( ) - rna1Last ; int rna2LeftOverhang = rna2Seq . length ( ) - rna2Last ; int rna2RightOverhang = rna2First - 1 ; StringBuffer [ ] sbs = new StringBuffer [ 3 ] ; for ( int i = 0 ; i < sbs . length ; i ++ ) { sbs [ i ] = new StringBuffer ( ) ; } if ( rna1LeftOverhang >= rna2LeftOverhang ) { sbs [ 0 ] . append ( rna1Seq ) ; for ( int i = 0 ; i < rna1LeftOverhang ; i ++ ) { sbs [ 1 ] . append ( paddingChar ) ; } for ( int i = rna1First ; i < ( rna1Last + 1 ) ; i ++ ) { Integer in = new Integer ( i ) ; if ( seqPositionMap . containsKey ( in ) ) { sbs [ 1 ] . append ( basePairChar ) ; } else { sbs [ 1 ] . append ( paddingChar ) ; } } for ( int i = 0 ; i < rna1LeftOverhang - rna2LeftOverhang ; i ++ ) { sbs [ 2 ] . append ( paddingChar ) ; } sbs [ 2 ] . append ( reverseRna2Seq ) ; } else { for ( int i = 0 ; i < rna2LeftOverhang - rna1LeftOverhang ; i ++ ) { sbs [ 0 ] . append ( paddingChar ) ; } sbs [ 0 ] . append ( rna1Seq ) ; for ( int i = 0 ; i < rna2LeftOverhang ; i ++ ) { sbs [ 1 ] . append ( paddingChar ) ; } for ( int i = rna1First ; i < ( rna1Last + 1 ) ; i ++ ) { Integer in = new Integer ( i ) ; if ( seqPositionMap . containsKey ( in ) ) { sbs [ 1 ] . append ( basePairChar ) ; } else { sbs [ 1 ] . append ( paddingChar ) ; } } sbs [ 2 ] . append ( reverseRna2Seq ) ; } if ( rna1RightOverhang >= rna2RightOverhang ) { for ( int i = 0 ; i < rna1RightOverhang ; i ++ ) { sbs [ 1 ] . append ( paddingChar ) ; } for ( int i = 0 ; i < rna1RightOverhang - rna2RightOverhang ; i ++ ) { sbs [ 2 ] . append ( paddingChar ) ; } } else { for ( int i = 0 ; i < rna2RightOverhang - rna1RightOverhang ; i ++ ) { sbs [ 0 ] . append ( paddingChar ) ; } for ( int i = 0 ; i < rna2RightOverhang - rna1RightOverhang ; i ++ ) { sbs [ 1 ] . append ( paddingChar ) ; } } if ( ( rna1Annotation != null && rna1Annotation . equalsIgnoreCase ( "AS" ) ) || ( rna2Annotation != null && rna2Annotation . equalsIgnoreCase ( "SS" ) ) ) { return new String [ ] { reverseString ( sbs [ 2 ] . toString ( ) ) , reverseString ( sbs [ 1 ] . toString ( ) ) , reverseString ( sbs [ 0 ] . toString ( ) ) } ; } else { return new String [ ] { sbs [ 0 ] . toString ( ) , sbs [ 1 ] . toString ( ) , sbs [ 2 ] . toString ( ) } ; } } } else { throw new NotationException ( "Structure contains more than two RNA sequences" ) ; } }
@param helm2notation HELM2Notation
@param paddingChar  padding character
@param basePairChar base pair character
@return string array of formated nucleotide sequence
@throws NotationException if notation is not valid
@throws RNAUtilsException if the polymer is not a RNA/DNA
@throws HELM2HandledException if it contains HELM2 specific features, so that it can not be casted to HELM1 Format
@throws org.helm.notation2.exception.NotationException if notation is not valid
@throws ChemistryException if the Chemistry Engine can not be initialized