Search in sources :

Example 36 with NextProtException

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

the class StatementTransformationUtil method mapVariationStatementToEntry.

/**
 * @param variationStatement
 *            Can be a variant or mutagenesis
 * @param result
 * @return
 */
static Statement mapVariationStatementToEntry(Statement variationStatement, FeatureQuerySuccess result) {
    String beginPositionOfCanonicalOrIsoSpec = null;
    String endPositionOfCanonicalOrIsoSpec = null;
    String masterBeginPosition = null;
    String masterEndPosition = null;
    String isoCanonical = null;
    TargetIsoformSet targetIsoforms = new TargetIsoformSet();
    for (IsoformFeatureResult isoformFeatureResult : result.getData().values()) {
        if (isoformFeatureResult.isMapped()) {
            targetIsoforms.add(new TargetIsoformStatementPosition(isoformFeatureResult.getIsoformAccession(), isoformFeatureResult.getBeginIsoformPosition(), // Target
            isoformFeatureResult.getEndIsoformPosition(), // Target
            IsoTargetSpecificity.UNKNOWN.name(), // propagated)
            isoformFeatureResult.getIsoSpecificFeature()));
            // canonical
            if (beginPositionOfCanonicalOrIsoSpec == null) {
                beginPositionOfCanonicalOrIsoSpec = String.valueOf(isoformFeatureResult.getBeginIsoformPosition());
            }
            if (endPositionOfCanonicalOrIsoSpec == null) {
                endPositionOfCanonicalOrIsoSpec = String.valueOf(isoformFeatureResult.getEndIsoformPosition());
            }
            // If possible use canonical
            if (isoformFeatureResult.isCanonical()) {
                if (isoCanonical != null) {
                    throw new NextProtException("Canonical position set already");
                }
                isoCanonical = isoformFeatureResult.getIsoformAccession();
                beginPositionOfCanonicalOrIsoSpec = String.valueOf(isoformFeatureResult.getBeginIsoformPosition());
                endPositionOfCanonicalOrIsoSpec = String.valueOf(isoformFeatureResult.getEndIsoformPosition());
            }
            if (masterBeginPosition == null) {
                masterBeginPosition = String.valueOf(isoformFeatureResult.getBeginMasterPosition());
            }
            if (masterEndPosition == null) {
                masterEndPosition = String.valueOf(isoformFeatureResult.getEndMasterPosition());
            }
            if (masterBeginPosition != null) {
                if (!masterBeginPosition.equals(String.valueOf(isoformFeatureResult.getBeginMasterPosition()))) {
                    throw new NextProtException("Begin master position " + masterBeginPosition + " does not match " + String.valueOf(isoformFeatureResult.getBeginMasterPosition() + " for different isoforms (" + result.getData().values().size() + ") for statement " + variationStatement.getStatementId()));
                }
            }
            if (masterEndPosition != null) {
                if (!masterEndPosition.equals(String.valueOf(isoformFeatureResult.getEndMasterPosition()))) {
                    throw new NextProtException("End master position does not match for different isoforms" + variationStatement.getStatementId());
                }
            }
        }
    }
    Statement rs = // Keep
    StatementBuilder.createNew().addMap(variationStatement).addField(StatementField.RAW_STATEMENT_ID, variationStatement.getStatementId()).addField(StatementField.LOCATION_BEGIN, beginPositionOfCanonicalOrIsoSpec).addField(StatementField.LOCATION_END, endPositionOfCanonicalOrIsoSpec).addField(StatementField.LOCATION_BEGIN_MASTER, masterBeginPosition).addField(StatementField.LOCATION_END_MASTER, masterEndPosition).addField(StatementField.ISOFORM_CANONICAL, isoCanonical).addField(StatementField.TARGET_ISOFORMS, targetIsoforms.serializeToJsonString()).buildWithAnnotationHash(AnnotationType.ENTRY);
    return rs;
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) IsoformFeatureResult(org.nextprot.api.isoform.mapper.domain.impl.SingleFeatureQuerySuccessImpl.IsoformFeatureResult)

Example 37 with NextProtException

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

the class StatementTranformerServiceImpl method getIsoAccession.

private String getIsoAccession(String featureName, String entryAccession) {
    SequenceVariant sv;
    try {
        sv = new SequenceVariant(featureName);
    } catch (ParseException e) {
        throw new NextProtException(e);
    }
    List<Isoform> isoforms = isoformService.findIsoformsByEntryName(entryAccession);
    Isoform isoSpecific = IsoformUtils.getIsoformByName(isoforms, sv.getIsoformName());
    return isoSpecific.getIsoformAccession();
}
Also used : SequenceVariant(org.nextprot.api.isoform.mapper.domain.impl.SequenceVariant) NextProtException(org.nextprot.api.commons.exception.NextProtException) Isoform(org.nextprot.api.core.domain.Isoform) ParseException(java.text.ParseException)

Example 38 with NextProtException

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

the class BlastResultUpdaterServiceImpl method updateDescription.

@Override
public void updateDescription(Description description, String isoAccession, String entryAccession) {
    MainNames entryNames = mainNamesService.findIsoformOrEntryMainName(entryAccession).orElseThrow(() -> new NextProtException("could not find informations for entry " + entryAccession));
    MainNames isoNames = mainNamesService.findIsoformOrEntryMainName(isoAccession).orElseThrow(() -> new NextProtException("could not find informations for isoform " + isoAccession));
    String geneName = (!entryNames.getGeneNameList().isEmpty()) ? entryNames.getGeneNameList().get(0) : null;
    String proteinName = entryNames.getName();
    String title = proteinName + ((geneName != null) ? " (" + geneName + ")" : "") + " [" + isoNames.getAccession() + "]";
    description.setTitle(title);
    description.setEntryAccession(entryNames.getAccession());
    description.setIsoAccession(isoNames.getAccession());
    description.setIsoName(isoNames.getName());
    description.setProteinName(proteinName);
    description.setGeneName(geneName);
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) MainNames(org.nextprot.api.core.domain.MainNames)

Example 39 with NextProtException

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

the class BlastProgram method process.

private O process(List<String> commandLine) throws ExceptionWithReason {
    SystemCommandExecutor commandExecutor = new SystemCommandExecutor(commandLine);
    try {
        commandExecutor.executeCommand();
        String stderr = commandExecutor.getLastExecutionStandardError();
        if (!stderr.isEmpty()) {
            ExceptionWithReason ewr = new ExceptionWithReason();
            ewr.getReason().addCause(name + " exception", stderr.replace("\n", " "));
            ewr.getReason().setMessage("Error while executing " + name);
            throw ewr;
        }
        return buildOutputFromStdout(commandExecutor.getLastExecutionStandardOutput());
    } catch (InterruptedException | IOException e) {
        throw new NextProtException("Internal error: cannot process " + name + " command line " + commandLine, e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) IOException(java.io.IOException) ExceptionWithReason(org.nextprot.api.commons.utils.ExceptionWithReason) SystemCommandExecutor(org.nextprot.api.commons.utils.SystemCommandExecutor)

Example 40 with NextProtException

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

the class UserProteinListUtils method combine.

/**
 * Apply the given operator to two user protein lists in a new instance of
 * {@code UserProteinList}
 *
 * @param l1 first user protein list
 * @param l2 second user protein list
 * @param operator operator applied to operands
 * @param username combined list user name
 * @param name combined list name
 * @param description combined list description
 * @return a new user protein list combining l1 and l2
 */
public static UserProteinList combine(UserProteinList l1, UserProteinList l2, Operator operator, String username, String name, String description) {
    NPreconditions.checkNotNull(l1, "The first user protein list should not be null");
    NPreconditions.checkNotNull(l2, "The second user protein list should not be null");
    NPreconditions.checkNotNull(operator, "The combine operator should not be null");
    NPreconditions.checkNotNull(name, "The user protein list name should not be null");
    NPreconditions.checkNotNull(username, "The user protein list user name should not be null");
    NPreconditions.checkTrue(!l1.equals(l2), "Can't make combination with the same lists");
    Set<String> combined = new HashSet<>();
    if (operator.equals(Operator.AND)) {
        combined.addAll(Sets.intersection(l1.getAccessionNumbers(), l2.getAccessionNumbers()));
    } else if (operator.equals(Operator.OR)) {
        combined = Sets.union(l1.getAccessionNumbers(), l2.getAccessionNumbers());
    } else if (operator.equals(Operator.NOT_IN)) {
        combined.addAll(Sets.difference(l1.getAccessionNumbers(), l2.getAccessionNumbers()));
    }
    if (combined.isEmpty())
        throw new NextProtException("The combined list is empty. Only combinations resulting on non-empty lists are saved.");
    UserProteinList combinedProteinList = new UserProteinList();
    combinedProteinList.setName(name);
    combinedProteinList.setOwner(username);
    combinedProteinList.setDescription(description);
    combinedProteinList.setAccessions(combined);
    return combinedProteinList;
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) UserProteinList(org.nextprot.api.user.domain.UserProteinList) HashSet(java.util.HashSet)

Aggregations

NextProtException (org.nextprot.api.commons.exception.NextProtException)68 IOException (java.io.IOException)30 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ApiMethod (org.jsondoc.core.annotation.ApiMethod)8 OutputStream (java.io.OutputStream)7 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)7 Cacheable (org.springframework.cache.annotation.Cacheable)6 Isoform (org.nextprot.api.core.domain.Isoform)5 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 Annotation (org.nextprot.api.core.domain.annotation.Annotation)4 NextprotMediaType (org.nextprot.api.core.service.export.format.NextprotMediaType)4 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)4 java.util (java.util)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 CvTerm (org.nextprot.api.core.domain.CvTerm)3 AnnotationVariant (org.nextprot.api.core.domain.annotation.AnnotationVariant)3 Query (org.nextprot.api.solr.Query)3 SearchResult (org.nextprot.api.solr.SearchResult)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2