Search in sources :

Example 1 with AnnotationMapping2Annotation

use of org.nextprot.api.commons.constants.AnnotationMapping2Annotation in project nextprot-api by calipho-sib.

the class PeptideMappingDaoImpl method findPeptideAnnotationEvidencesMap.

@Override
public Map<String, List<AnnotationEvidence>> findPeptideAnnotationEvidencesMap(List<String> names, boolean natural) {
    String datasourceClause = natural ? " ds.cv_name != 'SRMAtlas'" : " ds.cv_name  = 'SRMAtlas'";
    final AnnotationMapping2Annotation pmam = natural ? AnnotationMapping2Annotation.PEPTIDE_MAPPING : AnnotationMapping2Annotation.SRM_PEPTIDE_MAPPING;
    String sql = sqlDictionary.getSQLQuery("peptide-evidences-by-peptide-names").replace(":datasourceClause", datasourceClause);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("names", names);
    SqlParameterSource namedParams = new MapSqlParameterSource(params);
    List<AnnotationEvidence> evidences = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sql, namedParams, new RowMapper<AnnotationEvidence>() {

        @Override
        public AnnotationEvidence mapRow(ResultSet resultSet, int row) throws SQLException {
            AnnotationEvidence evidence = new AnnotationEvidence();
            // set later by service
            evidence.setAnnotationId(0);
            evidence.setEvidenceId(resultSet.getLong("evidence_id") + IdentifierOffset.PEPTIDE_MAPPING_ANNOTATION_EVIDENCE_OFFSET);
            evidence.setAssignedBy(resultSet.getString("assigned_by"));
            evidence.setAssignmentMethod(pmam.getAssignmentMethod());
            evidence.setEvidenceCodeAC(pmam.getEcoAC());
            evidence.setEvidenceCodeOntology(pmam.getEcoOntology());
            evidence.setEvidenceCodeName(pmam.getEcoName());
            evidence.setExperimentalContextId(null);
            evidence.setNegativeEvidence(false);
            evidence.setProperties(new ArrayList<AnnotationEvidenceProperty>());
            evidence.setQualifierType(pmam.getQualifierType());
            evidence.setQualityQualifier(pmam.getQualityQualifier());
            evidence.setResourceAccession(resultSet.getString("accession"));
            evidence.setResourceAssociationType("evidence");
            evidence.setResourceDb(resultSet.getString("database_name"));
            // temp value
            evidence.setResourceDescription(resultSet.getString("unique_name"));
            evidence.setResourceId(resultSet.getLong("resource_id"));
            evidence.setResourceType(resultSet.getString("resource_type"));
            return evidence;
        }
    });
    // turn this list into a map having the peptide name as the key
    Map<String, List<AnnotationEvidence>> result = new HashMap<>();
    for (AnnotationEvidence ev : evidences) {
        String pepKey = ev.getResourceDescription();
        // remove temp value
        ev.setResourceDescription(null);
        if (!result.containsKey(pepKey))
            result.put(pepKey, new ArrayList<AnnotationEvidence>());
        result.get(pepKey).add(ev);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) AnnotationMapping2Annotation(org.nextprot.api.commons.constants.AnnotationMapping2Annotation) ArrayList(java.util.ArrayList) AnnotationEvidence(org.nextprot.api.core.domain.annotation.AnnotationEvidence) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AnnotationMapping2Annotation (org.nextprot.api.commons.constants.AnnotationMapping2Annotation)1 AnnotationEvidence (org.nextprot.api.core.domain.annotation.AnnotationEvidence)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)1