Search in sources :

Example 1 with EntrySetNotFoundException

use of org.nextprot.api.commons.exception.EntrySetNotFoundException 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 2 with EntrySetNotFoundException

use of org.nextprot.api.commons.exception.EntrySetNotFoundException 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)

Aggregations

HashSet (java.util.HashSet)2 EntryNotFoundException (org.nextprot.api.commons.exception.EntryNotFoundException)2 EntrySetNotFoundException (org.nextprot.api.commons.exception.EntrySetNotFoundException)2