public static Nucleotide convertToNucleotide ( String id , boolean last ) throws MonomerException , org . helm . notation2 . exception . NotationException , ChemistryException , NucleotideLoadingException , NotationException { Map < String , String > reverseNucMap = NucleotideFactory . getInstance ( ) . getReverseNucleotideTemplateMap ( ) ; // last nucleotide will be handled differently String tmpNotation = id ; String symbol = null ; // if (i == (notations.length - 1) && notation.endsWith(")")) { if ( last && id . endsWith ( ")" ) ) { tmpNotation = id + "P" ; } if ( reverseNucMap . containsKey ( tmpNotation ) ) { symbol = reverseNucMap . get ( tmpNotation ) ; } else { char [ ] chars = id . toCharArray ( ) ; String base = null ; symbol = "X" ; // find base for ( int j = 0 ; j < chars . length ; j ++ ) { char letter = chars [ j ] ; // skip modifications if not in branch if ( letter == MODIFICATION_START_SYMBOL ) { int matchingPos = NucleotideParser . getMatchingBracketPosition ( chars , j , MODIFICATION_START_SYMBOL , MODIFICATION_END_SYMBOL ) ; j ++ ; if ( matchingPos == - 1 ) { throw new NotationException ( "Invalid Polymer Notation: Could not find matching bracket" ) ; } j = matchingPos ; } // base is always a branch monomer else if ( letter == BRANCH_START_SYMBOL ) { int matchingPos = NucleotideParser . getMatchingBracketPosition ( chars , j , BRANCH_START_SYMBOL , BRANCH_END_SYMBOL ) ; j ++ ; if ( matchingPos == - 1 ) { throw new NotationException ( "Invalid Polymer Notation: Could not find matching bracket" ) ; } base = id . substring ( j , matchingPos ) ; if ( base . length ( ) == 1 ) { symbol = base ; } else { Monomer monomer = MethodsMonomerUtils . getMonomer ( "RNA" , base , "" ) ; if ( null == monomer . getNaturalAnalog ( ) ) { symbol = "X" ; } else { symbol = monomer . getNaturalAnalog ( ) ; } } j = matchingPos ; } } } Nucleotide nuc = new Nucleotide ( symbol , id ) ; return nuc ; }
method to convert an string to an nucleotide