use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class StatementTranformerServiceImpl method transformStatements.
@Override
public Set<Statement> transformStatements(Set<Statement> rawStatements, ReportBuilder report) {
Map<String, Statement> sourceStatementsById = rawStatements.stream().collect(Collectors.toMap(Statement::getStatementId, Function.identity()));
Set<Statement> mappedStatementsToLoad = new HashSet<>();
for (Statement originalStatement : rawStatements) {
// If statements are complex with subject
if ((originalStatement.getSubjectStatementIds() != null) && (!originalStatement.getSubjectStatementIds().isEmpty())) {
String[] subjectStatemendIds = originalStatement.getSubjectStatementIdsArray();
Set<Statement> subjectStatements = getSubjects(subjectStatemendIds, sourceStatementsById);
subjectStatements.forEach(s -> s.processed());
originalStatement.processed();
String entryAccession = subjectStatements.iterator().next().getValue(StatementField.ENTRY_ACCESSION);
boolean isIsoSpecific = false;
String isoformName = validateSubject(subjectStatements);
String isoformSpecificAccession = null;
if (isSubjectIsoSpecific(subjectStatements)) {
if (isoformName != null) {
isIsoSpecific = true;
String featureName = subjectStatements.iterator().next().getValue(StatementField.ANNOTATION_NAME);
isoformSpecificAccession = getIsoAccession(featureName, entryAccession);
} else
throw new NextProtException("Something wrong occured when checking for iso specificity");
}
mappedStatementsToLoad.addAll(transformStatements(originalStatement, sourceStatementsById, subjectStatements, entryAccession, isIsoSpecific, isoformSpecificAccession, report));
}
}
// Currently only includes cases where we have the reciprocal binary interactions
Set<Statement> remainingRawStatements = getRemainingRawStatements(rawStatements);
Set<String> distinctCategories = remainingRawStatements.stream().map(s -> s.getValue(StatementField.ANNOTATION_CATEGORY)).distinct().collect(Collectors.toSet());
if (distinctCategories.contains(AnnotationCategory.PHENOTYPIC_VARIATION.getDbAnnotationTypeName())) {
throw new NextProtException("Not expecting phenotypic variation at this stage.");
}
LOGGER.info("Remaining categories are " + distinctCategories);
Set<Statement> remainingMappedStatements = transformRemainingRawStatementsToMappedStatements(remainingRawStatements);
mappedStatementsToLoad.addAll(remainingMappedStatements);
return mappedStatementsToLoad;
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class TerminologyUtils method populateTree.
static void populateTree(Tree.Node<CvTerm> currentNode, Map<String, CvTerm> termMap, int depth, final int maxDepth) {
if (depth > maxDepth)
return;
if (depth > 100)
throw new NextProtException("Getting stuck in building graph");
if (currentNode.getValue() == null || currentNode.getValue().getChildAccession() == null || currentNode.getValue().getChildAccession().isEmpty()) {
return;
}
for (String childAccession : currentNode.getValue().getChildAccession()) {
CvTerm childTerm = termMap.get(childAccession);
if (childTerm != null) {
if (currentNode.getChildren() == null) {
currentNode.setChildren(new ArrayList<Tree.Node<CvTerm>>());
}
Tree.Node<CvTerm> childNode = new Tree.Node<CvTerm>(childTerm);
childNode.setParents(Arrays.asList(currentNode));
currentNode.getChildren().add(childNode);
populateTree(childNode, termMap, depth + 1, maxDepth);
}
}
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class StreamEntryServiceImpl method streamAllChromosomeEntries.
@Override
public void streamAllChromosomeEntries(String chromosome, NextprotMediaType format, HttpServletResponse response) {
if (!Chromosome.exists(chromosome)) {
ChromosomeNotFoundException ex = new ChromosomeNotFoundException(chromosome);
response.setStatus(HttpStatus.SC_NOT_FOUND);
try {
response.getWriter().print(ex.getMessage());
} catch (IOException e) {
throw new NextProtException(format.getExtension() + " streaming failed: " + ex.getMessage(), e);
}
} else {
try {
setResponseHeader(response, format, "nextprot_chromosome_" + chromosome + "." + format.getExtension());
streamEntries(masterIdentifierService.findUniqueNamesOfChromosome(chromosome), format, "entry", response.getOutputStream(), "chromosome " + chromosome);
} catch (IOException e) {
throw new NextProtException(format.getExtension() + " streaming failed: cannot export all " + masterIdentifierService.findUniqueNames().size() + " entries from chromosome " + chromosome, e);
}
}
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class PepXServiceImpl method getPepXResponse.
private PepXResponse getPepXResponse(String peptides, boolean modeIsoleucine) {
String httpRequest = pepXUrl + "?format=json" + (modeIsoleucine ? ("&mode=IL&pep=" + peptides) : ("&pep=" + peptides));
try {
URL pepXUrl = new URL(httpRequest);
URLConnection px = pepXUrl.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(px.getInputStream()));
String line;
StringBuilder sb = new StringBuilder();
while ((line = in.readLine()) != null) {
sb.append(line);
}
in.close();
return PepxUtils.parsePepxResponse(sb.toString());
} catch (IOException e) {
throw new NextProtException(e);
}
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class SearchServiceImpl method sortAccessions.
@Override
public List<String> sortAccessions(QueryRequest queryRequest, Set<String> accessions) {
List<String> sortedAccessions = new ArrayList<String>();
try {
String queryString = "id:" + (accessions.size() > 1 ? "(" + Joiner.on(" ").join(accessions) + ")" : accessions.iterator().next());
queryRequest.setQuery(queryString);
Query query = queryBuilderService.buildQueryForSearchIndexes("entry", "pl_search", queryRequest);
SearchResult result = this.solrService.executeQuery(query);
List<Map<String, Object>> results = result.getResults();
for (Map<String, Object> res : results) {
String entry = (String) res.get("id");
sortedAccessions.add(entry);
}
} catch (SearchQueryException e) {
e.printStackTrace();
throw new NextProtException("Error when retrieving accessions");
}
return sortedAccessions;
}
Aggregations