Search in sources :

Example 6 with Entry

use of org.nextprot.api.core.domain.Entry in project nextprot-api by calipho-sib.

the class PepXServiceImpl method computePeptideUnicityStatus.

/**
 * Computes a unicity value for each peptide: UNIQUE, PSEUDO_UNIQUE, NON_UNIQUE
 * based on the response returned by pepx (a list of peptide - isoform matches)
 * by using the PeptideUnicityService
 * @param entries
 * @param withVariants
 * @return a map with key = peptide sequence, value = unicity value
 */
private Map<String, PeptideUnicity> computePeptideUnicityStatus(List<Entry> entries, boolean withVariants) {
    Map<String, Set<String>> pepIsoSetMap = new HashMap<>();
    entries.forEach(e -> {
        e.getAnnotationsByCategory(AnnotationCategory.PEPX_VIRTUAL_ANNOTATION).stream().filter(a -> a.getVariant() == null || withVariants).forEach(a -> {
            String pep = a.getCvTermName();
            if (!pepIsoSetMap.containsKey(pep))
                pepIsoSetMap.put(pep, new TreeSet<String>());
            a.getTargetingIsoformsMap().values().forEach(i -> {
                pepIsoSetMap.get(pep).add(i.getIsoformAccession());
            });
        });
    });
    Map<String, PeptideUnicity> pepUnicityMap = new HashMap<>();
    pepIsoSetMap.entrySet().forEach(e -> {
        String pep = e.getKey();
        PeptideUnicity pu = peptideUnicityService.getPeptideUnicityFromMappingIsoforms(e.getValue());
        pepUnicityMap.put(pep, pu);
    });
    return pepUnicityMap;
}
Also used : java.util(java.util) PepXResponse(org.nextprot.api.web.domain.PepXResponse) PepXEntryMatch(org.nextprot.api.web.domain.PepXResponse.PepXEntryMatch) URL(java.net.URL) Annotation(org.nextprot.api.core.domain.annotation.Annotation) NextProtException(org.nextprot.api.commons.exception.NextProtException) Autowired(org.springframework.beans.factory.annotation.Autowired) PeptideUnicity(org.nextprot.api.core.domain.PeptideUnicity) EntryBuilderService(org.nextprot.api.core.service.EntryBuilderService) Value(org.springframework.beans.factory.annotation.Value) AnnotationIsoformSpecificity(org.nextprot.api.core.domain.annotation.AnnotationIsoformSpecificity) AnnotationCategory(org.nextprot.api.commons.constants.AnnotationCategory) EntryConfig(org.nextprot.api.core.service.fluent.EntryConfig) Service(org.springframework.stereotype.Service) URLConnection(java.net.URLConnection) IsoformUtils(org.nextprot.api.core.utils.IsoformUtils) AnnotationVariant(org.nextprot.api.core.domain.annotation.AnnotationVariant) AnnotationProperty(org.nextprot.api.core.domain.annotation.AnnotationProperty) PepXIsoformMatch(org.nextprot.api.web.domain.PepXResponse.PepXIsoformMatch) PeptideUnicityService(org.nextprot.api.core.service.PeptideUnicityService) Entry(org.nextprot.api.core.domain.Entry) PeptideUtils(org.nextprot.api.core.utils.PeptideUtils) IOException(java.io.IOException) PropertyApiModel(org.nextprot.api.commons.constants.PropertyApiModel) InputStreamReader(java.io.InputStreamReader) AnnotationUtils(org.nextprot.api.core.service.annotation.AnnotationUtils) PepXService(org.nextprot.api.web.service.PepXService) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) PepxUtils(org.nextprot.api.web.domain.PepxUtils) BufferedReader(java.io.BufferedReader) Isoform(org.nextprot.api.core.domain.Isoform) PeptideUnicity(org.nextprot.api.core.domain.PeptideUnicity)

Example 7 with Entry

use of org.nextprot.api.core.domain.Entry in project nextprot-api by calipho-sib.

the class PepXServiceImpl method findEntriesWithPeptides.

@Override
public List<Entry> findEntriesWithPeptides(String peptides, boolean modeIsoleucine) {
    List<Entry> entries = new ArrayList<>();
    PepXResponse pepXResponse = getPepXResponse(peptides, modeIsoleucine);
    Set<String> entriesNames = pepXResponse.getEntriesNames();
    for (String entryName : entriesNames) {
        EntryConfig targetIsoconf = EntryConfig.newConfig(entryName).withTargetIsoforms().with("variant").withOverview().withoutAdditionalReferences().withoutProperties();
        Entry entry = entryBuilderService.build(targetIsoconf);
        List<Annotation> virtualAnnotations = new ArrayList<>();
        Set<String> peptidesForEntry = pepXResponse.getPeptidesForEntry(entryName);
        for (String peptide : peptidesForEntry) {
            PepXEntryMatch pepxEntryMatch = pepXResponse.getPeptideMatch(peptide).getPepxMatchesForEntry(entryName);
            if (pepxEntryMatch != null && pepxEntryMatch.getIsoforms() != null && pepxEntryMatch.getIsoforms().size() > 0) {
                virtualAnnotations.addAll(buildEntryWithVirtualAnnotations(peptide, modeIsoleucine, pepxEntryMatch.getIsoforms(), entry.getAnnotations(), entry.getIsoforms()));
            }
        }
        if ((virtualAnnotations != null) && (!virtualAnnotations.isEmpty())) {
            Entry resultEntry = new Entry(entry.getUniqueName());
            // Adds the overview as well
            resultEntry.setOverview(entry.getOverview());
            resultEntry.setAnnotations(virtualAnnotations);
            entries.add(resultEntry);
        }
    }
    // add peptide unicity extra info required to unicity checker and peptide viewer
    updateAnnotationsWithPeptideProperties(entries);
    return entries;
}
Also used : Entry(org.nextprot.api.core.domain.Entry) EntryConfig(org.nextprot.api.core.service.fluent.EntryConfig) PepXResponse(org.nextprot.api.web.domain.PepXResponse) PepXEntryMatch(org.nextprot.api.web.domain.PepXResponse.PepXEntryMatch) Annotation(org.nextprot.api.core.domain.annotation.Annotation)

Example 8 with Entry

use of org.nextprot.api.core.domain.Entry in project nextprot-api by calipho-sib.

the class EntryDataFetcherImpl method get.

@Override
public Entry get(DataFetchingEnvironment environment) {
    // TODO THIS IS A POC (Proof of Concept)
    // If we decide to go ahead with GraphQL please try to adapt this terrible function using EntryQueryResolver that implements GraphQLQueryResolver
    // graphql java tools allows to do newSchemaParser().file(schemaFile).resolvers(...).getSchemaObjects.getGraphqlSchema
    String accession = environment.getArgument("accession");
    Integer publicationLimit = -1;
    Integer annotationLimit = -1;
    String category = "";
    // Searching for publication limit
    Optional<Selection> publicationField = environment.getFields().get(0).getSelectionSet().getSelections().stream().filter(f -> ((Field) f).getName().equals("publications")).findAny();
    if (publicationField.isPresent()) {
        Optional<Argument> publicationLimitArg = ((Field) publicationField.get()).getArguments().stream().filter(f -> f.getName().equals("limit")).findAny();
        if (publicationLimitArg.isPresent()) {
            publicationLimit = Integer.valueOf(publicationLimitArg.get().getValue().toString().replace("IntValue{value=", "").replace("}", ""));
        }
    }
    // Searching for annotation field
    Optional<Selection> annotationField = environment.getFields().get(0).getSelectionSet().getSelections().stream().filter(f -> ((Field) f).getName().equals("annotations")).findAny();
    if (annotationField.isPresent()) {
        Optional<Argument> publicationLimitArg = ((Field) annotationField.get()).getArguments().stream().filter(f -> f.getName().equals("category")).findAny();
        if (publicationLimitArg.isPresent()) {
            category = publicationLimitArg.get().getValue().toString().replace("StringValue{value='", "").replace("'}", "");
        }
        Optional<Argument> annotationLimitArg = ((Field) annotationField.get()).getArguments().stream().filter(f -> f.getName().equals("limit")).findAny();
        if (annotationLimitArg.isPresent()) {
            annotationLimit = Integer.valueOf(annotationLimitArg.get().getValue().toString().replace("IntValue{value=", "").replace("}", ""));
        }
    }
    Entry entry = entryBuilderService.build(EntryConfig.newConfig(accession).with(category).withPublications().withOverview().withTargetIsoforms());
    if (publicationLimit != -1) {
        List<Publication> publications = entry.getPublications();
        List<Publication> publicationSubset = publications.subList(0, publicationLimit);
        entry.setPublications(publicationSubset);
    }
    if (annotationLimit != -1) {
        String cat = entry.getAnnotationsByCategory().keySet().iterator().next();
        entry.setAnnotations(entry.getAnnotationsByCategory(AnnotationCategory.getDecamelizedAnnotationTypeName(cat)).subList(0, annotationLimit));
    }
    return entry;
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) Entry(org.nextprot.api.core.domain.Entry) Autowired(org.springframework.beans.factory.annotation.Autowired) Field(graphql.language.Field) EntryBuilderService(org.nextprot.api.core.service.EntryBuilderService) Argument(graphql.language.Argument) Selection(graphql.language.Selection) Publication(org.nextprot.api.core.domain.Publication) Component(org.springframework.stereotype.Component) List(java.util.List) AnnotationCategory(org.nextprot.api.commons.constants.AnnotationCategory) EntryConfig(org.nextprot.api.core.service.fluent.EntryConfig) DataFetcher(graphql.schema.DataFetcher) Optional(java.util.Optional) Entry(org.nextprot.api.core.domain.Entry) Argument(graphql.language.Argument) Selection(graphql.language.Selection) Publication(org.nextprot.api.core.domain.Publication)

Example 9 with Entry

use of org.nextprot.api.core.domain.Entry in project nextprot-api by calipho-sib.

the class EntryXLSWriter method writeEntry.

@Override
protected void writeEntry(String entryName) throws IOException {
    EntryConfig config = EntryConfig.newConfig(entryName);
    for (EntryBlock block : entryDataProvider.getSourceEntryBlocks()) {
        config.withBlock(block);
    }
    Entry entry = entryBuilderService.build(config);
    for (Record record : entryDataProvider.getRecords(entry)) {
        HSSFRow row = worksheet.createRow(rowIndex);
        writeRecord(row, record);
        rowIndex++;
    }
}
Also used : Entry(org.nextprot.api.core.domain.Entry) EntryConfig(org.nextprot.api.core.service.fluent.EntryConfig) EntryBlock(org.nextprot.api.core.service.export.format.EntryBlock)

Example 10 with Entry

use of org.nextprot.api.core.domain.Entry in project nextprot-api by calipho-sib.

the class EntryPEFFStreamWriter method cacheBuiltEntries.

private void cacheBuiltEntries(Collection<String> entryAccessions) {
    for (String entryAccession : entryAccessions) {
        Entry entry = entryBuilderService.build(EntryConfig.newConfig(entryAccession).withTargetIsoforms());
        cachedEntries.put(entryAccession, entry);
    }
}
Also used : Entry(org.nextprot.api.core.domain.Entry)

Aggregations

Entry (org.nextprot.api.core.domain.Entry)60 Test (org.junit.Test)38 CoreUnitBaseTest (org.nextprot.api.core.test.base.CoreUnitBaseTest)16 Annotation (org.nextprot.api.core.domain.annotation.Annotation)9 Isoform (org.nextprot.api.core.domain.Isoform)8 EntryConfig (org.nextprot.api.core.service.fluent.EntryConfig)8 WebIntegrationBaseTest (org.nextprot.api.web.dbunit.base.mvc.WebIntegrationBaseTest)8 EntryBuilderService (org.nextprot.api.core.service.EntryBuilderService)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Assert (org.junit.Assert)4 Ignore (org.junit.Ignore)4 AnnotationCategory (org.nextprot.api.commons.constants.AnnotationCategory)4 DbXref (org.nextprot.api.core.domain.DbXref)4 ArrayList (java.util.ArrayList)3 PropertyApiModel (org.nextprot.api.commons.constants.PropertyApiModel)3 SolrDiffTest (org.nextprot.api.tasks.solr.indexer.entry.SolrDiffTest)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 java.util (java.util)2