@Override @Transactional protected void persist(Collection<RawProtein<PrintsRawMatch>> filteredProteins,Map<String,Signature> modelIdToSignatureMap,Map<String,Protein> proteinIdToProteinMap){
  for (  RawProtein<PrintsRawMatch> rawProtein : filteredProteins) {
    Protein protein=proteinIdToProteinMap.get(rawProtein.getProteinIdentifier());
    if (protein == null) {
      throw new IllegalStateException("Cannot store match to a protein that is not in database " + "[protein ID= " + rawProtein.getProteinIdentifier() + "]");
    }
    Set<FingerPrintsMatch.FingerPrintsLocation> locations=null;
    String currentSignatureAc=null;
    Signature currentSignature=null;
    PrintsRawMatch lastRawMatch=null;
    final TreeSet<PrintsRawMatch> sortedMatches=new TreeSet<PrintsRawMatch>(PRINTS_RAW_MATCH_COMPARATOR);
    sortedMatches.addAll(rawProtein.getMatches());
    FingerPrintsMatch match=null;
    for (    PrintsRawMatch rawMatch : sortedMatches) {
      if (rawMatch == null) {
        continue;
      }
      if (currentSignatureAc == null || !currentSignatureAc.equals(rawMatch.getModelId())) {
        if (currentSignatureAc != null) {
          if (match != null) {
            entityManager.persist(match);
          }
          match=new FingerPrintsMatch(currentSignature,lastRawMatch.getEvalue(),lastRawMatch.getGraphscan(),locations);
          protein.addMatch(match);
        }
        locations=new HashSet<FingerPrintsMatch.FingerPrintsLocation>();
        currentSignatureAc=rawMatch.getModelId();
        currentSignature=modelIdToSignatureMap.get(currentSignatureAc);
        if (currentSignature == null) {
          throw new IllegalStateException("Cannot find PRINTS signature " + currentSignatureAc + " in the database.");
        }
      }
      locations.add(new FingerPrintsMatch.FingerPrintsLocation(rawMatch.getLocationStart(),boundedLocationEnd(protein,rawMatch),rawMatch.getPvalue(),rawMatch.getScore(),rawMatch.getMotifNumber()));
      lastRawMatch=rawMatch;
    }
    if (lastRawMatch != null) {
      match=new FingerPrintsMatch(currentSignature,lastRawMatch.getEvalue(),lastRawMatch.getGraphscan(),locations);
      protein.addMatch(match);
      entityManager.persist(match);
    }
  }
}

@ Override @ Transactional protected void persist ( Collection < RawProtein < PrintsRawMatch > > filteredProteins , Map < String , Signature > modelIdToSignatureMap , Map < String , Protein > proteinIdToProteinMap ) { for ( RawProtein < PrintsRawMatch > rawProtein : filteredProteins ) { Protein protein = proteinIdToProteinMap . get ( rawProtein . getProteinIdentifier ( ) ) ; if ( protein == null ) { throw new IllegalStateException ( "Cannot store match to a protein that is not in database " + "[protein ID= " + rawProtein . getProteinIdentifier ( ) + "]" ) ; } Set < FingerPrintsMatch . FingerPrintsLocation > locations = null ; String currentSignatureAc = null ; Signature currentSignature = null ; PrintsRawMatch lastRawMatch = null ; final TreeSet < PrintsRawMatch > sortedMatches = new TreeSet < PrintsRawMatch > ( PRINTS_RAW_MATCH_COMPARATOR ) ; sortedMatches . addAll ( rawProtein . getMatches ( ) ) ; FingerPrintsMatch match = null ; for ( PrintsRawMatch rawMatch : sortedMatches ) { if ( rawMatch == null ) { continue ; } if ( currentSignatureAc == null || ! currentSignatureAc . equals ( rawMatch . getModelId ( ) ) ) { if ( currentSignatureAc != null ) { if ( match != null ) { entityManager . persist ( match ) ; } match = new FingerPrintsMatch ( currentSignature , lastRawMatch . getEvalue ( ) , lastRawMatch . getGraphscan ( ) , locations ) ; protein . addMatch ( match ) ; } locations = new HashSet < FingerPrintsMatch . FingerPrintsLocation > ( ) ; currentSignatureAc = rawMatch . getModelId ( ) ; currentSignature = modelIdToSignatureMap . get ( currentSignatureAc ) ; if ( currentSignature == null ) { throw new IllegalStateException ( "Cannot find PRINTS signature " + currentSignatureAc + " in the database." ) ; } } locations . add ( new FingerPrintsMatch . FingerPrintsLocation ( rawMatch . getLocationStart ( ) , boundedLocationEnd ( protein , rawMatch ) , rawMatch . getPvalue ( ) , rawMatch . getScore ( ) , rawMatch . getMotifNumber ( ) ) ) ; lastRawMatch = rawMatch ; } if ( lastRawMatch != null ) { match = new FingerPrintsMatch ( currentSignature , lastRawMatch . getEvalue ( ) , lastRawMatch . getGraphscan ( ) , locations ) ; protein . addMatch ( match ) ; entityManager . persist ( match ) ; } } }
this is the method that should be implemented by specific filteredmatchdaoimpl ' s to persist filtered matches .
