Search in sources :

Example 1 with EntryNotFoundException

use of org.nextprot.api.commons.exception.EntryNotFoundException in project nextprot-api by calipho-sib.

the class DbXrefAnalyserTask method analyseNextprotEntriesDbXrefs.

private void analyseNextprotEntriesDbXrefs() throws IOException {
    LOGGER.info("**** Analysing dbxrefs from entry accession...");
    ConsoleProgressBar pb;
    try (DbXrefUrlVisitor visitor = new DbXrefUrlVisitor(outputDirectory + "/allentries-xrefs-url.tsv", outputDirectory + "/allentries-xrefs-url.log")) {
        DbXrefService xrefService = getBean(DbXrefService.class);
        Set<String> allEntryAcs = getNextprotEntries();
        pb = ConsoleProgressBar.determinated("analysing dbxrefs (from neXtProt entries)", allEntryAcs.size());
        pb.start();
        for (String entryAc : allEntryAcs) {
            try {
                visitor.visit(entryAc, xrefService.findDbXrefsByMaster(entryAc));
                visitor.flush();
                pb.incrementValue();
            } catch (EntryNotFoundException e) {
                LOGGER.error(e.getMessage() + ": skipping entry " + entryAc);
            }
        }
        visitor.flush();
        visitor.close();
    }
    pb.stop();
}
Also used : DbXrefService(org.nextprot.api.core.service.DbXrefService) EntryNotFoundException(org.nextprot.api.commons.exception.EntryNotFoundException) ConsoleProgressBar(org.nextprot.api.commons.app.ConsoleProgressBar)

Example 2 with EntryNotFoundException

use of org.nextprot.api.commons.exception.EntryNotFoundException in project nextprot-api by calipho-sib.

the class UserProteinListUtils method checkFormatAndCollectValidAccessionNumber.

/**
 * Apply nextprot format on uncheckedAccessionNumber if needed, check for validity and give it to collector
 *
 * @param uncheckedAccessionNumber accession number to check for validity
 * @param allNPAccessionNumbers set of all valid entries
 * @param validAccessionNumberCollector a collector of all valid accession numbers
 * @throws EntryNotFoundException if invalid accession number
 */
public static void checkFormatAndCollectValidAccessionNumber(String uncheckedAccessionNumber, Set<String> validAccessionNumberCollector, Set<String> allNPAccessionNumbers) {
    NPreconditions.checkNotNull(allNPAccessionNumbers, "The collector should not be null");
    String trimmed = uncheckedAccessionNumber.trim().toUpperCase();
    if (uncheckedAccessionNumber.charAt(0) != '#') {
        if (!trimmed.startsWith("NX_"))
            trimmed = "NX_" + trimmed;
        if (!allNPAccessionNumbers.contains(trimmed))
            throw new EntryNotFoundException(uncheckedAccessionNumber);
        validAccessionNumberCollector.add(trimmed);
    }
}
Also used : EntryNotFoundException(org.nextprot.api.commons.exception.EntryNotFoundException)

Example 3 with EntryNotFoundException

use of org.nextprot.api.commons.exception.EntryNotFoundException in project nextprot-api by calipho-sib.

the class UserProteinListUtils method parseAccessionNumbers.

/**
 * Extract the set of accession numbers from uploaded file. Only nextprot
 * and uniprot accession numbers found in {@code validAccessionNumbers} are
 * allowed.
 *
 * <p>
 * uniprot accession numbers should be converted in nextprot (prefixed with
 * "NX_")
 * </p>
 *
 * @param reader the reader
 * @param validAccessionNumbers a set of possible nextprot accession numbers
 * @param ignoreEntryNotFoundException if true this method ignores EntryNotFoundException else throw it
 *
 * @return a set of valid accession numbers
 * @throws IOException
 *             if input exception occurred
 * @throws EntrySetNotFoundException
 *             if entries was not found in validAccessionNumbers
 */
public static Set<String> parseAccessionNumbers(Reader reader, Set<String> validAccessionNumbers, boolean ignoreEntryNotFoundException) throws IOException {
    NPreconditions.checkNotNull(reader, "The reader should not be null");
    NPreconditions.checkNotNull(validAccessionNumbers, "The valid accession numbers should not be null");
    NPreconditions.checkTrue(!validAccessionNumbers.isEmpty(), "The valid accession numbers should not be null");
    Set<String> foundEntries = new HashSet<>();
    BufferedReader br = new BufferedReader(reader);
    String line;
    Set<String> unknownEntries = new HashSet<>();
    while ((line = br.readLine()) != null) {
        try {
            checkFormatAndCollectValidAccessionNumber(line, foundEntries, validAccessionNumbers);
        } catch (EntryNotFoundException e) {
            unknownEntries.add(e.getEntry());
        }
    }
    if (!ignoreEntryNotFoundException && !unknownEntries.isEmpty())
        throw new EntrySetNotFoundException(unknownEntries);
    return foundEntries;
}
Also used : EntrySetNotFoundException(org.nextprot.api.commons.exception.EntrySetNotFoundException) EntryNotFoundException(org.nextprot.api.commons.exception.EntryNotFoundException) HashSet(java.util.HashSet)

Example 4 with EntryNotFoundException

use of org.nextprot.api.commons.exception.EntryNotFoundException in project nextprot-api by calipho-sib.

the class UserProteinListUtils method checkAndFormatAccessionNumbers.

/**
 * Apply nextprot format on if needed and check for validity
 *
 * @param uncheckedAccessionNumbers set of accession numbers to check
 * @param validAccessionNumbers set of all valid entries
 * @return a well formatted set of accession numbers
 */
public static Set<String> checkAndFormatAccessionNumbers(Collection<String> uncheckedAccessionNumbers, Set<String> validAccessionNumbers) {
    NPreconditions.checkNotNull(uncheckedAccessionNumbers, "The collection of accessions should not be null");
    NPreconditions.checkNotNull(validAccessionNumbers, "The valid accession numbers should not be null");
    NPreconditions.checkTrue(!validAccessionNumbers.isEmpty(), "The valid accession numbers should not be null");
    Set<String> collector = new HashSet<>(uncheckedAccessionNumbers.size());
    Set<String> unknownEntries = new HashSet<>();
    for (String uncheckedAccessionNumber : uncheckedAccessionNumbers) {
        try {
            checkFormatAndCollectValidAccessionNumber(uncheckedAccessionNumber, collector, validAccessionNumbers);
        } catch (EntryNotFoundException e) {
            unknownEntries.add(e.getEntry());
        }
    }
    if (!unknownEntries.isEmpty())
        throw new EntrySetNotFoundException(unknownEntries);
    return collector;
}
Also used : EntrySetNotFoundException(org.nextprot.api.commons.exception.EntrySetNotFoundException) EntryNotFoundException(org.nextprot.api.commons.exception.EntryNotFoundException) HashSet(java.util.HashSet)

Example 5 with EntryNotFoundException

use of org.nextprot.api.commons.exception.EntryNotFoundException in project nextprot-api by calipho-sib.

the class ServiceEntryValidation method checkValidEntry.

@Around("execution(* org.nextprot.api.*.service.*.*(..))")
public // @Around("execution(* org.nextprot.api.*.service.*.*(.., @aspects.ValidEntry (*), ..))")
Object checkValidEntry(ProceedingJoinPoint pjp) throws Throwable {
    Object[] arguments = pjp.getArgs();
    for (Object arg : arguments) {
        if ((arg != null) && EntryConfig.class.isAssignableFrom(arg.getClass())) {
            String argument = ((EntryConfig) arg).getEntryName();
            String entryAccession = EntryUtils.getEntryName(argument);
            if (!uniqueNames.contains(entryAccession)) {
                LOGGER.error("neXtProt entry " + argument + " was not found, throwing EntryNotFoundException");
                throw new EntryNotFoundException(argument);
            }
        }
    }
    MethodSignature ms = (MethodSignature) pjp.getSignature();
    Annotation[][] annotations = ms.getMethod().getParameterAnnotations();
    int i = 0;
    for (Annotation[] paramAnnotations : annotations) {
        for (Annotation annotation : paramAnnotations) {
            if (ValidEntry.class.isAssignableFrom(annotation.getClass())) {
                if (!uniqueNames.contains(arguments[i])) {
                    LOGGER.error("neXtProt entry " + arguments[i] + " was not found, throwing EntryNotFoundException");
                    throw new EntryNotFoundException((String) arguments[i]);
                }
                break;
            }
        }
        i++;
    }
    return pjp.proceed();
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) EntryConfig(org.nextprot.api.core.service.fluent.EntryConfig) EntryNotFoundException(org.nextprot.api.commons.exception.EntryNotFoundException) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Annotation(java.lang.annotation.Annotation) Around(org.aspectj.lang.annotation.Around)

Aggregations

EntryNotFoundException (org.nextprot.api.commons.exception.EntryNotFoundException)5 HashSet (java.util.HashSet)2 EntrySetNotFoundException (org.nextprot.api.commons.exception.EntrySetNotFoundException)2 Annotation (java.lang.annotation.Annotation)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 Around (org.aspectj.lang.annotation.Around)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1 ConsoleProgressBar (org.nextprot.api.commons.app.ConsoleProgressBar)1 DbXrefService (org.nextprot.api.core.service.DbXrefService)1 EntryConfig (org.nextprot.api.core.service.fluent.EntryConfig)1