diff --git a/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/alignments/GenomeAlignmentsHelper.java b/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/alignments/GenomeAlignmentsHelper.java index f154428..246ca7f 100644 --- a/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/alignments/GenomeAlignmentsHelper.java +++ b/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/alignments/GenomeAlignmentsHelper.java @@ -156,7 +156,7 @@ private static int getIncrement(Document genomeAlignment){ return genomeAlignment.getInteger(SchemaConstants.Field.ORIENTATION); } - private static List mapToGenomeIndex(int proteinIndex, Range proteinRange, Range genomeRange){ + public static List mapToGenomeIndex(int proteinIndex, Range proteinRange, Range genomeRange){ if(!proteinRange.contains(proteinIndex)) return List.of(); int begin = 3 * (proteinIndex - proteinRange.bottom()) + genomeRange.bottom(); diff --git a/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/annotations/AnnotationsCollector.java b/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/annotations/AnnotationsCollector.java index 6c24a85..732e022 100644 --- a/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/annotations/AnnotationsCollector.java +++ b/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/annotations/AnnotationsCollector.java @@ -5,10 +5,9 @@ package org.rcsb.rcsbsequencecoordinates.collectors.annotations; import org.bson.Document; +import org.rcsb.rcsbsequencecoordinates.collectors.alignments.AlignmentsCollector; import org.rcsb.rcsbsequencecoordinates.collectors.alignments.SequenceAlignmentsCollector; import org.rcsb.rcsbsequencecoordinates.collectors.utils.AnnotationFilterOperator; -import org.rcsb.rcsbsequencecoordinates.collectors.utils.AnnotationRangeIntersection; -import org.rcsb.rcsbsequencecoordinates.collectors.utils.RangeIntersectionOperator; import org.rcsb.graphqlschema.params.AnnotationFilter; import org.rcsb.graphqlschema.reference.AnnotationReference; import org.rcsb.graphqlschema.reference.GroupReference; @@ -46,10 +45,10 @@ public Flux getAnnotations( List annotationFilters, List range ) { - RangeIntersectionOperator annotationRangeIntersection = new RangeIntersectionOperator(range, new AnnotationRangeIntersection()); - return getAnnotations(queryId, sequenceReference, annotationReferences, annotationFilters) - .filter(annotationRangeIntersection::isConnected) - .map(annotationRangeIntersection::applyRange); + return Flux.fromIterable(annotationReferences) + .flatMap( + annotationReference -> getAnnotations(queryId, sequenceReference, annotationReference, annotationFilters, range) + ); } public Flux getAnnotations( @@ -59,25 +58,13 @@ public Flux getAnnotations( List annotationFilters ){ if(groupReference.equals(GroupReference.MATCHING_UNIPROT_ACCESSION)) - return getAnnotations(groupId, SequenceReference.UNIPROT, annotationReferences, annotationFilters); + return getAnnotations(groupId, SequenceReference.UNIPROT, annotationReferences, annotationFilters, null); return Flux.fromIterable(annotationReferences) .flatMap( annotationReference -> getAnnotations(groupId, groupReference, annotationReference, annotationFilters) ); } - private Flux getAnnotations( - String queryId, - SequenceReference sequenceReference, - List annotationReferences, - List annotationFilters - ) { - return Flux.fromIterable(annotationReferences) - .flatMap( - annotationReference -> getAnnotations(queryId, sequenceReference, annotationReference, annotationFilters) - ); - } - private Flux getAnnotations( String groupId, GroupReference groupReference, @@ -126,14 +113,18 @@ private Flux getAnnotations( String queryId, SequenceReference sequenceReference, AnnotationReference annotationReference, - List annotationFilters + List annotationFilters, + List range ) { - return sequenceAlignmentsCollector + AlignmentsCollector alignmentsCollector = sequenceAlignmentsCollector .request( - queryId, - sequenceReference, - annotationReference.toSequenceReference() - ) + queryId, + sequenceReference, + annotationReference.toSequenceReference() + ); + if(range != null) + alignmentsCollector.range(range); + return alignmentsCollector .get() .flatMap( alignment -> getAnnotations(annotationReference, annotationFilters, alignment) @@ -152,7 +143,8 @@ private Flux getAnnotations( .filter(filter::targetCheck) .map(filter::applyFilterToFeatures) .filter(AnnotationsHelper::hasFeatures) - .map(annotations -> mapAnnotations(annotations, alignment)); + .map(annotations -> mapAnnotations(annotations, alignment)) + .filter(annotations -> !annotations.isEmpty()); } private Flux switchAlignmentEntityIdToReference(Document alignment, SequenceReference reference){ diff --git a/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/annotations/AnnotationsHelper.java b/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/annotations/AnnotationsHelper.java index cc05eb1..6728917 100644 --- a/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/annotations/AnnotationsHelper.java +++ b/src/main/java/org/rcsb/rcsbsequencecoordinates/collectors/annotations/AnnotationsHelper.java @@ -23,6 +23,7 @@ import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Filters.or; import static com.mongodb.client.model.Projections.*; +import static org.rcsb.rcsbsequencecoordinates.collectors.alignments.GenomeAlignmentsHelper.mapToGenomeIndex; import static org.rcsb.rcsbsequencecoordinates.collectors.map.MapHelper.parseAsymFromInstance; import static org.rcsb.rcsbsequencecoordinates.collectors.map.MapHelper.parseEntryFromInstance; import static org.rcsb.utils.RangeMethods.intersection; @@ -69,12 +70,15 @@ public static List getAggregation(List ids){ } public static Document mapAnnotations(Document annotations, Document alignment){ + List features = annotations.getList(SequenceCoordinatesConstants.FEATURES, Document.class).stream() + .map(feature-> mapFeature(feature, alignment)) + .filter(d->!d.getList(SequenceCoordinatesConstants.FEATURE_POSITIONS, Document.class).isEmpty()) + .toList(); + if (features.isEmpty()) + return new Document(); annotations.put( SchemaConstants.Field.FEATURES, - annotations.getList(SequenceCoordinatesConstants.FEATURES, Document.class).stream() - .map(feature-> mapFeature(feature, alignment)) - .filter(d->!d.getList(SequenceCoordinatesConstants.FEATURE_POSITIONS, Document.class).isEmpty()) - .toList() + features ); return annotations; } @@ -164,7 +168,9 @@ private static Document valuesIntersection(Document featureRegion, Document alig alignmentRegion.getInteger(SequenceCoordinatesConstants.QUERY_END) ); return new Document(Map.of( - SchemaConstants.Field.BEG_SEQ_ID, mapIndex(intersection.bottom(), targetRange, queryRange), + SchemaConstants.Field.BEG_SEQ_ID, alignmentRegion.containsKey(SequenceCoordinatesConstants.EXON_SHIFT) ? + mapToGenomeIndex(intersection.bottom(), targetRange, queryRange).get(0) : + mapIndex(intersection.bottom(), targetRange, queryRange), SchemaConstants.Field.BEG_ORI_ID, intersection.bottom(), SchemaConstants.Field.VALUES, featureValues.subList( intersection.bottom() - featureRange.bottom(), @@ -195,8 +201,12 @@ private static Document regionIntersection(Document featureRegion, Document alig alignmentRegion.getInteger(SequenceCoordinatesConstants.QUERY_END) ); return new Document(Map.of( - SchemaConstants.Field.BEG_SEQ_ID, mapIndex(intersection.bottom(), targetRange, queryRange), - SchemaConstants.Field.END_SEQ_ID, mapIndex(intersection.top(), targetRange, queryRange), + SchemaConstants.Field.BEG_SEQ_ID, alignmentRegion.containsKey(SequenceCoordinatesConstants.EXON_SHIFT) ? + mapToGenomeIndex(intersection.bottom(), targetRange, queryRange).get(0) : + mapIndex(intersection.bottom(), targetRange, queryRange), + SchemaConstants.Field.END_SEQ_ID, alignmentRegion.containsKey(SequenceCoordinatesConstants.EXON_SHIFT) ? + mapToGenomeIndex(intersection.top(), targetRange, queryRange).get(2) : + mapIndex(intersection.top(), targetRange, queryRange), SchemaConstants.Field.BEG_ORI_ID, intersection.bottom(), SchemaConstants.Field.END_ORI_ID, intersection.top(), SchemaConstants.Field.OPEN_BEGIN, intersection.bottom() != featureRegion.getInteger(SequenceCoordinatesConstants.BEG_SEQ_ID), diff --git a/src/main/resources/static/graphiql/index.html b/src/main/resources/static/graphiql/index.html index 0375c26..2b5422b 100644 --- a/src/main/resources/static/graphiql/index.html +++ b/src/main/resources/static/graphiql/index.html @@ -5,7 +5,9 @@ - GraphiQL + + + RCSB PDB Sequence Coordinates - GraphiQL