private static Object[] setCanonicalHELMFirstSection(HELM2Notation helm2notation) throws HELM1ConverterException, HELM1FormatException, ClassNotFoundException, IOException, ValidationException,
      ChemistryException, org.helm.notation2.parser.exceptionparser.NotationException {
    Map<String, String> idLabelMap = new HashMap<String, String>();
    Map<String, List<String>> labelIdMap = new TreeMap<String, List<String>>();

    for (PolymerNotation polymer : helm2notation.getListOfPolymers()) {
      String id = polymer.getPolymerID().getId();
      String elementsToHELM = polymer.getPolymerElements().toHELM();
      Map<String, String> adHocList = findAdHocMonomers(elementsToHELM, polymer.getPolymerID().getType());
      Map<String, String> convert = convertAdHocMonomersIntoSMILES(adHocList);
      for (Map.Entry<String, String> e : convert.entrySet()) {
        elementsToHELM = elementsToHELM.replaceAll(e.getKey(), e.getValue());
      }

      elementsToHELM = elementsToHELM.replace("[", "");
      elementsToHELM = elementsToHELM.replace("]", "");
      idLabelMap.put(id, elementsToHELM);
      if (labelIdMap.containsKey(elementsToHELM)) {
        List<String> l = labelIdMap.get(elementsToHELM);
        l.add(id);
      } else {
        List<String> l = new ArrayList<String>();
        l.add(id);
        labelIdMap.put(elementsToHELM, l);
      }
    }

    Set<String> sortedLabelSet = labelIdMap.keySet();
    List<List<String[]>> lol = new ArrayList<List<String[]>>();
    for (String key : sortedLabelSet) {
      List<String> value = labelIdMap.get(key);
      List<String[]> al = new ArrayList<String[]>();
      al.add(value.toArray(new String[0]));
      PermutationAndExpansion.expand(lol, al);
    }

    List<List<String>> nodeIdPermutations = PermutationAndExpansion.linearize(lol);
    List<String> notationList = new ArrayList<String>();
    Map<String, String> convertsortedIdstoIds = new HashMap<String, String>();
    for (List<String> sortedIdList : nodeIdPermutations) {

      String notation = "";
      int countCHEM = 0;
      int countPEPTIDE = 0;
      int countRNA = 0;
      for (String id : sortedIdList) {

        int count = 0;
        if (helm2notation.getPolymerNotation(id).getPolymerID().getType().equals("PEPTIDE")) {
          countPEPTIDE += 1;
          count = countPEPTIDE;
        }
        if (helm2notation.getPolymerNotation(id).getPolymerID().getType().equals("CHEM")) {
          countCHEM += 1;
          count = countCHEM;
        }
        if (helm2notation.getPolymerNotation(id).getPolymerID().getType().equals("RNA")) {
          countRNA += 1;
          count = countRNA;
        }

        notation = notation + helm2notation.getPolymerNotation(id).getPolymerID().getType() + count + "{" + helm2notation.getPolymerNotation(id).toHELM() + "}|";
        convertsortedIdstoIds.put(helm2notation.getPolymerNotation(id).getPolymerID().getId(), helm2notation.getPolymerNotation(id).getPolymerID().getType() + count);

      }

      notation = notation.substring(0, notation.length() - 1);
      notationList.add(notation);
    }

    Collections.sort(notationList);
    return new Object[] {convertsortedIdstoIds, notationList.get(0)};
  }
private static Object [ ] setCanonicalHELMFirstSection ( HELM2Notation helm2notation ) throws HELM1ConverterException , HELM1FormatException , ClassNotFoundException , IOException , ValidationException , ChemistryException , org . helm . notation2 . parser . exceptionparser . NotationException { Map < String , String > idLabelMap = new HashMap < String , String > ( ) ; Map < String , List < String > > labelIdMap = new TreeMap < String , List < String > > ( ) ; for ( PolymerNotation polymer : helm2notation . getListOfPolymers ( ) ) { String id = polymer . getPolymerID ( ) . getId ( ) ; String elementsToHELM = polymer . getPolymerElements ( ) . toHELM ( ) ; Map < String , String > adHocList = findAdHocMonomers ( elementsToHELM , polymer . getPolymerID ( ) . getType ( ) ) ; Map < String , String > convert = convertAdHocMonomersIntoSMILES ( adHocList ) ; for ( Map . Entry < String , String > e : convert . entrySet ( ) ) { elementsToHELM = elementsToHELM . replaceAll ( e . getKey ( ) , e . getValue ( ) ) ; } elementsToHELM = elementsToHELM . replace ( "[" , "" ) ; elementsToHELM = elementsToHELM . replace ( "]" , "" ) ; idLabelMap . put ( id , elementsToHELM ) ; if ( labelIdMap . containsKey ( elementsToHELM ) ) { List < String > l = labelIdMap . get ( elementsToHELM ) ; l . add ( id ) ; } else { List < String > l = new ArrayList < String > ( ) ; l . add ( id ) ; labelIdMap . put ( elementsToHELM , l ) ; } } Set < String > sortedLabelSet = labelIdMap . keySet ( ) ; List < List < String [ ] > > lol = new ArrayList < List < String [ ] > > ( ) ; for ( String key : sortedLabelSet ) { List < String > value = labelIdMap . get ( key ) ; List < String [ ] > al = new ArrayList < String [ ] > ( ) ; al . add ( value . toArray ( new String [ 0 ] ) ) ; PermutationAndExpansion . expand ( lol , al ) ; } List < List < String > > nodeIdPermutations = PermutationAndExpansion . linearize ( lol ) ; List < String > notationList = new ArrayList < String > ( ) ; Map < String , String > convertsortedIdstoIds = new HashMap < String , String > ( ) ; for ( List < String > sortedIdList : nodeIdPermutations ) { String notation = "" ; int countCHEM = 0 ; int countPEPTIDE = 0 ; int countRNA = 0 ; for ( String id : sortedIdList ) { int count = 0 ; if ( helm2notation . getPolymerNotation ( id ) . getPolymerID ( ) . getType ( ) . equals ( "PEPTIDE" ) ) { countPEPTIDE += 1 ; count = countPEPTIDE ; } if ( helm2notation . getPolymerNotation ( id ) . getPolymerID ( ) . getType ( ) . equals ( "CHEM" ) ) { countCHEM += 1 ; count = countCHEM ; } if ( helm2notation . getPolymerNotation ( id ) . getPolymerID ( ) . getType ( ) . equals ( "RNA" ) ) { countRNA += 1 ; count = countRNA ; } notation = notation + helm2notation . getPolymerNotation ( id ) . getPolymerID ( ) . getType ( ) + count + "{" + helm2notation . getPolymerNotation ( id ) . toHELM ( ) + "}|" ; convertsortedIdstoIds . put ( helm2notation . getPolymerNotation ( id ) . getPolymerID ( ) . getId ( ) , helm2notation . getPolymerNotation ( id ) . getPolymerID ( ) . getType ( ) + count ) ; } notation = notation . substring ( 0 , notation . length ( ) - 1 ) ; notationList . add ( notation ) ; } Collections . sort ( notationList ) ; return new Object [ ] { convertsortedIdstoIds , notationList . get ( 0 ) } ; }
method to convert the first section into canonical first section

@param helm2notation HELM2Notation
@return an Object containing in the first place a Map of converted ids and
in the second place the firstSection
@throws IOException
@throws HELM1ConverterException if there were HELM2 features in the
HELMNotation
@throws HELM1FormatException if the adHocMonomers can not be found
@throws ClassNotFoundException
@throws ValidationException if a smiles as monomer is not valid
@throws ChemistryException if the Chemistry Engine can not be initialized
@throws org.helm.notation2.parser.exceptionparser.NotationException