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));
}
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);
}
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));
}
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;
}
Aggregations