|
1 | 1 | package org.alliancegenome.neo4j.repository; |
2 | 2 |
|
3 | | -import static java.util.stream.Collectors.joining; |
| 3 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 4 | +import lombok.extern.slf4j.Slf4j; |
| 5 | +import org.alliancegenome.core.util.FileHelper; |
| 6 | +import org.alliancegenome.es.model.query.Pagination; |
| 7 | +import org.alliancegenome.neo4j.entity.node.*; |
| 8 | +import org.alliancegenome.neo4j.entity.relationship.GenomeLocation; |
| 9 | +import org.alliancegenome.neo4j.view.OrthologyFilter; |
| 10 | +import org.apache.commons.collections.CollectionUtils; |
| 11 | +import org.apache.commons.collections4.map.MultiKeyMap; |
| 12 | +import org.neo4j.ogm.model.Result; |
4 | 13 |
|
5 | 14 | import java.io.BufferedReader; |
6 | 15 | import java.io.IOException; |
7 | 16 | import java.io.InputStreamReader; |
8 | 17 | import java.io.Serializable; |
9 | 18 | import java.net.URL; |
10 | | -import java.util.ArrayList; |
11 | | -import java.util.Arrays; |
12 | | -import java.util.Comparator; |
13 | | -import java.util.HashMap; |
14 | | -import java.util.HashSet; |
15 | | -import java.util.Iterator; |
16 | | -import java.util.LinkedHashMap; |
17 | | -import java.util.List; |
18 | | -import java.util.Map; |
19 | | -import java.util.Objects; |
20 | | -import java.util.Set; |
21 | | -import java.util.StringJoiner; |
| 19 | +import java.util.*; |
22 | 20 | import java.util.regex.Matcher; |
23 | 21 | import java.util.regex.Pattern; |
24 | 22 | import java.util.stream.Collectors; |
25 | 23 | import java.util.stream.StreamSupport; |
26 | 24 |
|
27 | | -import org.alliancegenome.core.util.FileHelper; |
28 | | -import org.alliancegenome.es.model.query.Pagination; |
29 | | -import org.alliancegenome.neo4j.entity.node.AffectedGenomicModel; |
30 | | -import org.alliancegenome.neo4j.entity.node.BioEntityGeneExpressionJoin; |
31 | | -import org.alliancegenome.neo4j.entity.node.GOTerm; |
32 | | -import org.alliancegenome.neo4j.entity.node.Gene; |
33 | | -import org.alliancegenome.neo4j.entity.node.OrthoAlgorithm; |
34 | | -import org.alliancegenome.neo4j.entity.node.ParaAlgorithm; |
35 | | -import org.alliancegenome.neo4j.entity.node.SecondaryId; |
36 | | -import org.alliancegenome.neo4j.entity.node.UBERONTerm; |
37 | | -import org.alliancegenome.neo4j.view.OrthologyFilter; |
38 | | -import org.apache.commons.collections.CollectionUtils; |
39 | | -import org.apache.commons.collections4.map.MultiKeyMap; |
40 | | -import org.neo4j.ogm.model.Result; |
41 | | - |
42 | | -import com.fasterxml.jackson.annotation.JsonProperty; |
43 | | - |
44 | | -import lombok.extern.slf4j.Slf4j; |
| 25 | +import static java.util.stream.Collectors.joining; |
45 | 26 |
|
46 | 27 | @Slf4j |
47 | 28 | public class GeneRepository extends Neo4jRepository<Gene> { |
@@ -76,18 +57,43 @@ public Gene getOneGene(String primaryKey) { |
76 | 57 | HashMap<String, String> map = new HashMap<>(); |
77 | 58 |
|
78 | 59 | map.put("primaryKey", primaryKey); |
79 | | - String query = " MATCH p1=(q:Species)-[:FROM_SPECIES]-(g:Gene) WHERE g.primaryKey = $primaryKey " |
80 | | - + "OPTIONAL MATCH p2=(g:Gene)--(:SOTerm) " |
81 | | - + "OPTIONAL MATCH p3=(g:Gene)--(:Synonym) " |
82 | | - + "OPTIONAL MATCH p4=(g:Gene)--(:SecondaryId) " |
83 | | - + "OPTIONAL MATCH p5=(g:Gene)--(:GenomicLocation) " |
84 | | - + "OPTIONAL MATCH p6=(g:Gene)--(:CrossReference) " |
85 | | - + "RETURN p1, p2, p3, p4, p5, p6"; |
| 60 | + String query = """ |
| 61 | + MATCH (q:Species)-[:FROM_SPECIES]-(g:Gene {primaryKey: $primaryKey}) |
| 62 | + OPTIONAL MATCH (g)-[:ANNOTATED_TO]-(soTerm:SOTerm) |
| 63 | + WITH g, q, COLLECT(soTerm) AS soTerms |
| 64 | + OPTIONAL MATCH (g)-[:ALSO_KNOWN_AS]-(synonym:Synonym) |
| 65 | + WITH g, q, soTerms, COLLECT(synonym) AS synonyms |
| 66 | + OPTIONAL MATCH (g)-[:ALSO_KNOWN_AS]-(secondaryId:SecondaryId) |
| 67 | + WITH g, q, soTerms, synonyms, COLLECT(secondaryId) AS secondaryIds |
| 68 | + OPTIONAL MATCH (g)-[:ASSOCIATION]-(genomicLocation:GenomicLocation) |
| 69 | + WITH g, q, soTerms, synonyms, secondaryIds, COLLECT(genomicLocation) AS genomicLocations |
| 70 | + OPTIONAL MATCH (g)-[:CROSS_REFERENCE]->(crossRef:CrossReference) |
| 71 | + RETURN q AS Species, |
| 72 | + soTerms AS SOTerms, |
| 73 | + synonyms AS Synonyms, |
| 74 | + secondaryIds AS SecondaryIds, |
| 75 | + genomicLocations AS GenomicLocations, |
| 76 | + g AS Gene, |
| 77 | + COLLECT(crossRef) AS CrossReferences |
| 78 | + """; |
86 | 79 |
|
87 | 80 | Iterable<Gene> genes = query(query, map); |
88 | | - for (Gene g : genes) { |
89 | | - if (g.getPrimaryKey().equals(primaryKey)) { |
90 | | - return g; |
| 81 | + if (genes.iterator().hasNext()) { |
| 82 | + Gene gene = genes.iterator().next(); |
| 83 | + if (gene.getPrimaryKey().equals(primaryKey)) { |
| 84 | + Iterable<CrossReference> crossReferences = query(CrossReference.class, query, map); |
| 85 | + gene.setCrossReferences(StreamSupport.stream(crossReferences.spliterator(), false).toList()); |
| 86 | + Iterable<Synonym> synonyms = query(Synonym.class, query, map); |
| 87 | + gene.setSynonyms(StreamSupport.stream(synonyms.spliterator(), false).toList()); |
| 88 | + Iterable<SecondaryId> secondaryIds = query(SecondaryId.class, query, map); |
| 89 | + gene.setSecondaryIds(StreamSupport.stream(secondaryIds.spliterator(), false).toList()); |
| 90 | + Iterable<GenomeLocation> genomicLocations = query(GenomeLocation.class, query, map); |
| 91 | + gene.setGenomeLocations(StreamSupport.stream(genomicLocations.spliterator(), false).toList()); |
| 92 | + Iterable<Species> species = query(Species.class, query, map); |
| 93 | + gene.setSpecies(species.iterator().next()); |
| 94 | + Iterable<SOTerm> soTerm = query(SOTerm.class, query, map); |
| 95 | + gene.setSoTerm(soTerm.iterator().next()); |
| 96 | + return gene; |
91 | 97 | } |
92 | 98 | } |
93 | 99 | return null; |
|
0 commit comments