Search in sources :

Example 1 with MisoNamingException

use of uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException in project miso-lims by miso-lims.

the class DefaultLibraryAliasGenerator method generate.

@Override
public String generate(Library library) throws MisoNamingException, IOException {
    if (library.getSample() != null) {
        Pattern samplePattern = Pattern.compile("([A-z0-9]+)_S([A-z0-9]+)_(.*)");
        Matcher m = samplePattern.matcher(library.getSample().getAlias());
        if (m.matches()) {
            Collection<Library> siblings = libraryService.listBySampleId(library.getSample().getId());
            Set<String> siblingAliases = siblings.stream().map(Library::getAlias).collect(Collectors.toSet());
            String alias = null;
            long siblingNumber = siblings.stream().filter(sibling -> sibling.getId() != library.getId()).count();
            do {
                siblingNumber++;
                alias = m.group(1) + "_" + "L" + m.group(2) + "-" + siblingNumber + "_" + m.group(3);
            } while (siblingAliases.contains(alias));
            return alias;
        } else {
            throw new MisoNamingException("Cannot generate Library alias from supplied sample alias: " + library.getSample().getAlias());
        }
    } else {
        throw new NullPointerException("This alias generation scheme requires the Library to have a parent Sample set.");
    }
}
Also used : Matcher(java.util.regex.Matcher) LibraryService(uk.ac.bbsrc.tgac.miso.core.service.LibraryService) Collection(java.util.Collection) Library(uk.ac.bbsrc.tgac.miso.core.data.Library) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException) IOException(java.io.IOException) Pattern(java.util.regex.Pattern) Collectors(java.util.stream.Collectors) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Library(uk.ac.bbsrc.tgac.miso.core.data.Library) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Example 2 with MisoNamingException

use of uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException in project miso-lims by miso-lims.

the class OicrBaseLibraryAliasGenerator method getLibraryTypeAbbreviation.

/**
 * @param item the item that an alias is being generated for
 * @return the name portion representing the LibraryType
 * @throws NullPointerException if item's LibraryType is not set
 * @throws MisoNamingException if unable to generate an alias for any other reason
 */
private String getLibraryTypeAbbreviation(R item) throws MisoNamingException {
    LibraryType libraryType = getLibraryType(item);
    String abbr = libraryType.getAbbreviation();
    if (abbr == null) {
        throw new MisoNamingException("Cannot generate alias for library type '" + libraryType.getDescription() + "'");
    }
    return abbr;
}
Also used : LibraryType(uk.ac.bbsrc.tgac.miso.core.data.type.LibraryType) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Example 3 with MisoNamingException

use of uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException in project miso-lims by miso-lims.

the class V2LibraryAliquotAliasGenerator method generate.

@Override
public String generate(LibraryAliquot aliquot) throws MisoNamingException, IOException {
    if (!isDetailedLibraryAliquot(aliquot)) {
        throw new MisoNamingException("Can only generate an alias for detailed library aliquots");
    }
    Library library = aliquot.getLibrary();
    String partialAlias = library.getAlias() + "-";
    int next = siblingNumberGenerator.getFirstAvailableSiblingNumber(LibraryAliquot.class, partialAlias);
    String siblingNumber = zeroPad(next, 2);
    return partialAlias + siblingNumber;
}
Also used : Library(uk.ac.bbsrc.tgac.miso.core.data.Library) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Example 4 with MisoNamingException

use of uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException in project miso-lims by miso-lims.

the class AbstractNamingScheme method generateNameFor.

@Override
public String generateNameFor(Nameable nameable) throws MisoNamingException, IOException {
    if (getNameGenerator() == null)
        throw new UnsupportedOperationException("check hasNameGenerator() to determine availability");
    String name = getNameGenerator().generate(nameable);
    ValidationResult vr = validateName(name);
    if (vr.isValid())
        return name;
    throw new MisoNamingException("failed to generate a valid name: " + vr.getMessage());
}
Also used : ValidationResult(uk.ac.bbsrc.tgac.miso.core.service.naming.validation.ValidationResult) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Example 5 with MisoNamingException

use of uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException in project miso-lims by miso-lims.

the class DefaultPoolService method create.

@Override
public long create(Pool pool) throws IOException {
    if (pool.isDiscarded()) {
        pool.setVolume(BigDecimal.ZERO);
    }
    if (pool.getConcentration() == null) {
        pool.setConcentrationUnits(null);
    }
    if (pool.getVolume() == null) {
        pool.setVolumeUnits(null);
    }
    pool.setName(generateTemporaryName());
    loadPoolElements(pool.getPoolContents(), pool);
    pool.setChangeDetails(authorizationManager.getCurrentUser());
    boxService.throwIfBoxPositionIsFilled(pool);
    validateChange(pool, null);
    poolStore.save(pool);
    try {
        NamingScheme namingScheme = namingSchemeHolder.getPrimary();
        pool.setName(namingScheme.generateNameFor(pool));
        validateNameOrThrow(pool, namingScheme);
    } catch (MisoNamingException e) {
        throw new IOException("Invalid name for pool", e);
    }
    if (autoGenerateIdBarcodes) {
        LimsUtils.generateAndSetIdBarcode(pool);
    }
    long savedId = poolStore.save(pool);
    boxService.updateBoxableLocation(pool);
    return savedId;
}
Also used : NamingScheme(uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme) IOException(java.io.IOException) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Aggregations

MisoNamingException (uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)15 NamingScheme (uk.ac.bbsrc.tgac.miso.core.service.naming.NamingScheme)8 IOException (java.io.IOException)5 ValidationException (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException)5 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)4 ValidationError (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)4 DetailedSample (uk.ac.bbsrc.tgac.miso.core.data.DetailedSample)3 Library (uk.ac.bbsrc.tgac.miso.core.data.Library)3 TransferSample (uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample)2 ValidationResult (uk.ac.bbsrc.tgac.miso.core.service.naming.validation.ValidationResult)2 User (com.eaglegenomics.simlims.core.User)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 DetailedLibrary (uk.ac.bbsrc.tgac.miso.core.data.DetailedLibrary)1 IlluminaRun (uk.ac.bbsrc.tgac.miso.core.data.IlluminaRun)1 LS454Run (uk.ac.bbsrc.tgac.miso.core.data.LS454Run)1