use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class Mdata method convertXmlToMDataContext.
static MDataContext convertXmlToMDataContext(String xml) {
try {
JSONObject jObject = XML.toJSONObject(xml);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
return mapper.readValue(jObject.toString(), MDataContext.class);
} catch (IOException e) {
throw new NextProtException("Failed to convert XML mdata to object ", e);
}
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class FilePatternDictionary method loadResources.
protected void loadResources() {
resourcesMap = new TreeMap<>();
Resource[] resources;
try {
resources = new PathMatchingResourcePatternResolver().getResources(getLocation());
for (Resource r : resources) {
resourcesMap.put(r.getFilename().replace(getExtension(), ""), Resources.toString(r.getURL(), Charsets.UTF_8));
}
} catch (IOException e) {
throw new NextProtException("Error on loading SQL Dict", e);
}
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class PepXServiceImpl method buildEntryWithVirtualAnnotations.
static List<Annotation> buildEntryWithVirtualAnnotations(String peptide, boolean modeIsoleucine, List<PepXIsoformMatch> pepXisoforms, List<Annotation> varAnnotations, List<Isoform> isoforms) {
List<Annotation> finalAnnotations = new ArrayList<>();
for (PepXIsoformMatch isoNameAndOptionalPosition : pepXisoforms) {
String isoformAc = isoNameAndOptionalPosition.getIsoformAccession();
Annotation annotation = new Annotation();
annotation.setAnnotationCategory(AnnotationCategory.PEPX_VIRTUAL_ANNOTATION);
annotation.setCvTermName(peptide);
annotation.setDescription("This virtual annotation describes the peptide " + peptide + " found in " + isoformAc);
AnnotationIsoformSpecificity is = new AnnotationIsoformSpecificity();
is.setIsoformAccession(isoformAc);
if (isoNameAndOptionalPosition.getPosition() != null) {
// It means there is a variant!!!
int startPeptidePosition = isoNameAndOptionalPosition.getPosition();
int endPeptidePosition = startPeptidePosition + peptide.length();
List<Annotation> variantAnnotations = AnnotationUtils.filterAnnotationsBetweenPositions(startPeptidePosition, endPeptidePosition, varAnnotations, isoformAc);
Isoform iso = IsoformUtils.getIsoformByIsoName(isoforms, isoformAc);
if (iso == null) {
throw new NextProtException("The variant at " + startPeptidePosition + " is not specific for this isoform " + isoformAc);
}
List<Annotation> validAnnotations = filterValidVariantAnnotations(peptide, modeIsoleucine, variantAnnotations, isoformAc, iso.getSequence());
if ((validAnnotations == null) || validAnnotations.isEmpty()) {
LOGGER.warn("No valid variants found for isoform " + isoformAc + " at position " + startPeptidePosition + " for peptide " + peptide + " in mode IL:" + modeIsoleucine);
continue;
// We used to throw an exception, but now we just skip
// throw new NextProtException("No valid variants found for isoform " + isoformName + " at position" + startPeptidePosition + " for peptide " + peptide + " in mode IL:" + modeIsoleucine);
}
if (validAnnotations.size() > 1) {
LOGGER.warn("There is more than 1 valid variant (" + validAnnotations.size() + ") for isoform (returning the 1st) " + isoformAc + " between position " + startPeptidePosition + " and " + endPeptidePosition + " for peptide " + peptide + " in mode IL:" + modeIsoleucine);
// Takes only the first valid
int startPos = validAnnotations.get(0).getStartPositionForIsoform(isoformAc);
int endPos = validAnnotations.get(0).getEndPositionForIsoform(isoformAc);
is.setFirstPosition(startPos);
is.setLastPosition(endPos);
AnnotationVariant var = validAnnotations.get(0).getVariant();
annotation.setVariant(var);
} else {
// one variant on that position
int startPos = validAnnotations.get(0).getStartPositionForIsoform(isoformAc);
int endPos = validAnnotations.get(0).getEndPositionForIsoform(isoformAc);
is.setFirstPosition(startPos);
is.setLastPosition(endPos);
AnnotationVariant var = validAnnotations.get(0).getVariant();
annotation.setVariant(var);
}
} else {
// No variant
Isoform iso = IsoformUtils.getIsoformByIsoName(isoforms, isoformAc);
String sequence = (iso != null) ? iso.getSequence() : null;
boolean isPeptideContained = PeptideUtils.isPeptideContainedInTheSequence(peptide, sequence, modeIsoleucine);
if (!isPeptideContained) {
LOGGER.warn("PepX returned a peptide (" + peptide + ") for an isoform (" + isoformAc + ") that is not in the current isoform in neXtProt");
continue;
}
// We used to throw an exception, but this would break the program (the algorithm could be improved to detect the specific case where pepx return a peptide of length 6 and generate a real error on other cases)
// NPreconditions.checkTrue(isPeptideContained, "PepX returned a peptide (" + peptide + ") for an isoform (" + isoformName + ") that is not in the current isoform in neXtProt");
}
annotation.addTargetingIsoforms(Arrays.asList(is));
finalAnnotations.add(annotation);
}
return finalAnnotations;
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class SearchServiceImpl method getAccessionsForSimple.
private Set<String> getAccessionsForSimple(QueryRequest queryRequest) {
Set<String> set = new LinkedHashSet<>();
try {
Query query = this.queryBuilderService.buildQueryForSearchIndexes("entry", "simple", queryRequest);
SearchResult results = solrService.executeIdQuery(query);
for (Map<String, Object> f : results.getFoundFacets("id")) {
String entry = (String) f.get("name");
set.add(entry);
}
} catch (SearchQueryException e) {
e.printStackTrace();
throw new NextProtException("Error when retrieving accessions");
}
return set;
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class EntryController method getSubPart.
@RequestMapping("/entry/{entry}/{blockOrSubpart}")
public String getSubPart(@PathVariable("entry") String entryName, @PathVariable("blockOrSubpart") String blockOrSubpart, @RequestParam(value = "term-child-of", required = false) String ancestorTerm, @RequestParam(value = "property-name", required = false) String propertyName, @RequestParam(value = "property-value", required = false) String propertyValueOrAccession, HttpServletRequest request, Model model) {
boolean goldOnly = "true".equalsIgnoreCase(request.getParameter("goldOnly"));
boolean bed = null == request.getParameter("bed") ? true : Boolean.valueOf(request.getParameter("bed"));
Entry entry = this.entryBuilderService.build(EntryConfig.newConfig(entryName).with(blockOrSubpart).withGoldOnly(goldOnly).withBed(bed));
if (ancestorTerm != null || propertyName != null) {
filterEntryAnnotations(entry, ancestorTerm, propertyName, propertyValueOrAccession);
}
if (request.getRequestURI().toLowerCase().endsWith(".tsv")) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
EntryPartWriterTSV writer = new EntryPartWriterTSV(EntryPartExporterImpl.fromSubPart(blockOrSubpart), baos);
writer.write(entry);
model.addAttribute("tsv", baos.toString(StandardCharsets.UTF_8.name()));
baos.close();
} catch (IOException e) {
throw new NextProtException("cannot export " + entryName + " " + blockOrSubpart + " in tsv format", e);
}
}
model.addAttribute("entry", entry);
return "entry";
}
Aggregations