@Override public void persist(Collection<RawProtein<PantherRawMatch>> filteredProteins,Map<String,Signature> modelIdToSignatureMap,Map<String,Protein> proteinIdToProteinMap){
  for (  RawProtein<PantherRawMatch> 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<PantherMatch.PantherLocation> locations=null;
    String currentSignatureAc=null;
    Signature currentSignature=null;
    PantherRawMatch lastRawMatch=null;
    PantherMatch match=null;
    for (    PantherRawMatch rawMatch : rawProtein.getMatches()) {
      if (rawMatch == null) {
        continue;
      }
      if (currentSignatureAc == null || !currentSignatureAc.equals(rawMatch.getModelId())) {
        if (currentSignatureAc != null) {
          if (match != null) {
            entityManager.persist(match);
          }
          match=new PantherMatch(currentSignature,locations,lastRawMatch.getEvalue(),lastRawMatch.getFamilyName(),lastRawMatch.getScore());
          protein.addMatch(match);
        }
        locations=new HashSet<PantherMatch.PantherLocation>();
        currentSignatureAc=rawMatch.getModelId();
        currentSignature=modelIdToSignatureMap.get(currentSignatureAc);
        if (currentSignature == null) {
          throw new IllegalStateException("Cannot find PANTHER signature " + currentSignatureAc + " in the database.");
        }
      }
      LOGGER.debug(" protein length = " + protein.getSequenceLength() + " start location of raw match : "+ rawMatch.getLocationStart()+ " end location of raw match : "+ rawMatch.getLocationEnd());
      if (!pantherLocationWithinRange(protein,rawMatch)) {
        LOGGER.error("PANTHER match is out of range: " + " protein length = " + protein.getSequenceLength() + " raw match : "+ rawMatch.toString());
        throw new IllegalStateException("PANTHER match location is out of range " + currentSignatureAc + " protein length = "+ protein.getSequenceLength()+ " raw match : "+ rawMatch.toString());
      }
      locations.add(new PantherMatch.PantherLocation(rawMatch.getLocationStart(),rawMatch.getLocationEnd()));
      lastRawMatch=rawMatch;
    }
    if (lastRawMatch != null) {
      match=new PantherMatch(currentSignature,locations,lastRawMatch.getEvalue(),lastRawMatch.getFamilyName(),lastRawMatch.getScore());
      protein.addMatch(match);
      entityManager.persist(match);
    }
  }
}

@ Override public void persist ( Collection < RawProtein < PantherRawMatch > > filteredProteins , Map < String , Signature > modelIdToSignatureMap , Map < String , Protein > proteinIdToProteinMap ) { for ( RawProtein < PantherRawMatch > 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 < PantherMatch . PantherLocation > locations = null ; String currentSignatureAc = null ; Signature currentSignature = null ; PantherRawMatch lastRawMatch = null ; PantherMatch match = null ; for ( PantherRawMatch rawMatch : rawProtein . getMatches ( ) ) { if ( rawMatch == null ) { continue ; } if ( currentSignatureAc == null || ! currentSignatureAc . equals ( rawMatch . getModelId ( ) ) ) { if ( currentSignatureAc != null ) { if ( match != null ) { entityManager . persist ( match ) ; } match = new PantherMatch ( currentSignature , locations , lastRawMatch . getEvalue ( ) , lastRawMatch . getFamilyName ( ) , lastRawMatch . getScore ( ) ) ; protein . addMatch ( match ) ; } locations = new HashSet < PantherMatch . PantherLocation > ( ) ; currentSignatureAc = rawMatch . getModelId ( ) ; currentSignature = modelIdToSignatureMap . get ( currentSignatureAc ) ; if ( currentSignature == null ) { throw new IllegalStateException ( "Cannot find PANTHER signature " + currentSignatureAc + " in the database." ) ; } } LOGGER . debug ( " protein length = " + protein . getSequenceLength ( ) + " start location of raw match : " + rawMatch . getLocationStart ( ) + " end location of raw match : " + rawMatch . getLocationEnd ( ) ) ; if ( ! pantherLocationWithinRange ( protein , rawMatch ) ) { LOGGER . error ( "PANTHER match is out of range: " + " protein length = " + protein . getSequenceLength ( ) + " raw match : " + rawMatch . toString ( ) ) ; throw new IllegalStateException ( "PANTHER match location is out of range " + currentSignatureAc + " protein length = " + protein . getSequenceLength ( ) + " raw match : " + rawMatch . toString ( ) ) ; } locations . add ( new PantherMatch . PantherLocation ( rawMatch . getLocationStart ( ) , rawMatch . getLocationEnd ( ) ) ) ; lastRawMatch = rawMatch ; } if ( lastRawMatch != null ) { match = new PantherMatch ( currentSignature , locations , lastRawMatch . getEvalue ( ) , lastRawMatch . getFamilyName ( ) , lastRawMatch . getScore ( ) ) ; protein . addMatch ( match ) ; entityManager . persist ( match ) ; } } }
this is the method that should be implemented by specific filteredmatchdaoimpl ' s to persist filtered matches .
