Search in sources :

Example 6 with MainNames

use of org.nextprot.api.core.domain.MainNames in project nextprot-api by calipho-sib.

the class MainNamesDaoTest method testMapContentForMaster.

@Test
public void testMapContentForMaster() {
    Map<String, MainNames> namesMap = this.mainNamesDao.getMainNamesMap();
    // 3 masters + 4 isoforms = 7 entries in the map
    MainNames names = namesMap.get("NX_12345");
    assertEquals("NX_12345", names.getAccession());
    assertEquals("https://www.nextprot.org/entry/NX_12345", names.getUrl());
    assertEquals("Master name 1", names.getName());
    assertEquals(1, names.getGeneNameList().size());
    assertEquals("GENE1", names.getGeneNameList().get(0));
}
Also used : MainNames(org.nextprot.api.core.domain.MainNames) CoreUnitBaseTest(org.nextprot.api.core.test.base.CoreUnitBaseTest) Test(org.junit.Test)

Example 7 with MainNames

use of org.nextprot.api.core.domain.MainNames in project nextprot-api by calipho-sib.

the class BlastResultUpdaterServiceImpl method updateDescription.

@Override
public void updateDescription(Description description, String isoAccession, String entryAccession) {
    MainNames entryNames = mainNamesService.findIsoformOrEntryMainName(entryAccession).orElseThrow(() -> new NextProtException("could not find informations for entry " + entryAccession));
    MainNames isoNames = mainNamesService.findIsoformOrEntryMainName(isoAccession).orElseThrow(() -> new NextProtException("could not find informations for isoform " + isoAccession));
    String geneName = (!entryNames.getGeneNameList().isEmpty()) ? entryNames.getGeneNameList().get(0) : null;
    String proteinName = entryNames.getName();
    String title = proteinName + ((geneName != null) ? " (" + geneName + ")" : "") + " [" + isoNames.getAccession() + "]";
    description.setTitle(title);
    description.setEntryAccession(entryNames.getAccession());
    description.setIsoAccession(isoNames.getAccession());
    description.setIsoName(isoNames.getName());
    description.setProteinName(proteinName);
    description.setGeneName(geneName);
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) MainNames(org.nextprot.api.core.domain.MainNames)

Example 8 with MainNames

use of org.nextprot.api.core.domain.MainNames in project nextprot-api by calipho-sib.

the class BlastResultUpdaterServiceImplTest method mockMainNamesService.

private static void mockMainNamesService(MainNamesService mock) {
    MainNames mainNames = new MainNames();
    mainNames.setAccession("an accession");
    mainNames.setGeneNameList(Collections.singletonList("a gene name"));
    mainNames.setName("a name");
    Mockito.when(mock.findIsoformOrEntryMainName(any(String.class))).thenReturn(Optional.of(mainNames));
}
Also used : MainNames(org.nextprot.api.core.domain.MainNames)

Example 9 with MainNames

use of org.nextprot.api.core.domain.MainNames in project nextprot-api by calipho-sib.

the class MainNamesDAOImpl method getMainNamesMap.

@Override
public Map<String, MainNames> getMainNamesMap() {
    List<Map<String, Object>> rows = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("isoform-names"), new RowMapper<Map<String, Object>>() {

        @Override
        public Map<String, Object> mapRow(ResultSet resultSet, int row) throws SQLException {
            Map<String, Object> rec = new HashMap<>();
            // isoform accession
            String isoformAc = resultSet.getString("unique_name");
            rec.put("isoform_ac", isoformAc);
            // derive entry accession from isoform accession
            String masterAc = isoformAc.substring(0, isoformAc.indexOf("-"));
            rec.put("master_ac", masterAc);
            // entry (display) name
            rec.put("master_name", resultSet.getString("master_name"));
            // handle isoform name
            String isoName = resultSet.getString("isoform_name");
            try {
                // if it is a number, prefix it with "Iso "
                Integer.parseInt(isoName);
                isoName = "Iso " + isoName;
            } catch (NumberFormatException e) {
            }
            rec.put("isoform_name", isoName);
            // handle gene list
            String genes = resultSet.getString("gene_name");
            String[] geneArray = genes.split(";");
            List<String> geneList = new ArrayList<>();
            for (String g : geneArray) geneList.add(g.trim());
            rec.put("geneList", geneList);
            return rec;
        }
    });
    // now turn the list into a map
    Map<String, MainNames> result = new HashMap<>();
    for (Map<String, Object> rec : rows) {
        String masterAc = (String) rec.get("master_ac");
        // add a map entry for the master if not already done from a previous row
        if (!result.containsKey(masterAc)) {
            MainNames names = new MainNames();
            names.setAccession(masterAc);
            names.setName((String) rec.get("master_name"));
            names.setGeneNameList((List<String>) rec.get("geneList"));
            result.put(masterAc, names);
        }
        // add a map entry for the isoform
        MainNames names = new MainNames();
        String isoAc = (String) rec.get("isoform_ac");
        names.setAccession(isoAc);
        names.setName((String) rec.get("isoform_name"));
        names.setGeneNameList((List<String>) rec.get("geneList"));
        result.put(isoAc, names);
    }
    return result;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) HashMap(java.util.HashMap) MainNames(org.nextprot.api.core.domain.MainNames) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MainNames (org.nextprot.api.core.domain.MainNames)9 Test (org.junit.Test)6 CoreUnitBaseTest (org.nextprot.api.core.test.base.CoreUnitBaseTest)5 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 Map (java.util.Map)1 NextProtException (org.nextprot.api.commons.exception.NextProtException)1 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1