@@ -2,80 +2,30 @@ package repositories
22
33import jakarta .inject .{Inject , Singleton }
44import models .dal .DatabaseSchema
5- import models .domain .genomics .{AlignmentCoverage , AlignmentMetadata , MetricLevel }
5+ import models .domain .genomics .{AlignmentMetadata , EmbeddedCoverage , MetricLevel }
66import play .api .db .slick .DatabaseConfigProvider
7+ import play .api .libs .json .Json
78
89import scala .concurrent .{ExecutionContext , Future }
910
1011/**
1112 * Repository interface for managing alignment metadata and coverage statistics.
1213 */
1314trait AlignmentRepository {
14- /**
15- * Creates a new alignment metadata record.
16- *
17- * @param metadata The alignment metadata to create
18- * @return A future containing the created metadata with its assigned ID
19- */
2015 def createMetadata (metadata : AlignmentMetadata ): Future [AlignmentMetadata ]
2116
22- /**
23- * Creates or updates coverage statistics for an alignment.
24- *
25- * @param coverage The coverage statistics to upsert
26- * @return A future containing the upserted coverage record
27- */
28- def upsertCoverage (coverage : AlignmentCoverage ): Future [AlignmentCoverage ]
29-
30- /**
31- * Finds all alignment metadata for a specific sequence file.
32- *
33- * @param sequenceFileId The sequence file ID
34- * @return A future containing a sequence of alignment metadata records
35- */
17+ def updateCoverage (metadataId : Long , coverage : EmbeddedCoverage ): Future [Boolean ]
18+
3619 def findMetadataBySequenceFile (sequenceFileId : Long ): Future [Seq [AlignmentMetadata ]]
3720
38- /**
39- * Finds alignment metadata for a specific contig.
40- *
41- * @param genbankContigId The GenBank contig ID
42- * @param metricLevel Optional filter by metric level
43- * @return A future containing a sequence of alignment metadata records
44- */
4521 def findMetadataByContig (genbankContigId : Int , metricLevel : Option [MetricLevel ] = None ): Future [Seq [AlignmentMetadata ]]
4622
47- /**
48- * Retrieves alignment metadata with associated coverage statistics.
49- *
50- * @param metadataId The alignment metadata ID
51- * @return A future containing an optional tuple of (metadata, coverage)
52- */
53- def findMetadataWithCoverage (metadataId : Long ): Future [Option [(AlignmentMetadata , Option [AlignmentCoverage ])]]
54-
55- /**
56- * Finds all alignment metadata and coverage for a sequence file.
57- *
58- * @param sequenceFileId The sequence file ID
59- * @return A future containing a sequence of tuples (metadata, coverage)
60- */
61- def findAllWithCoverageBySequenceFile (sequenceFileId : Long ): Future [Seq [(AlignmentMetadata , Option [AlignmentCoverage ])]]
62-
63- /**
64- * Deletes alignment metadata and associated coverage by ID.
65- *
66- * @param metadataId The alignment metadata ID to delete
67- * @return A future containing the number of deleted records
68- */
23+ def findMetadataById (metadataId : Long ): Future [Option [AlignmentMetadata ]]
24+
25+ def findAllBySequenceFile (sequenceFileId : Long ): Future [Seq [AlignmentMetadata ]]
26+
6927 def deleteMetadata (metadataId : Long ): Future [Int ]
7028
71- /**
72- * Finds regional alignment statistics for a specific genomic region.
73- *
74- * @param genbankContigId The GenBank contig ID
75- * @param startPos Start position (1-based, inclusive)
76- * @param endPos End position (1-based, inclusive)
77- * @return A future containing a sequence of regional alignment metadata
78- */
7929 def findRegionalMetadata (genbankContigId : Int , startPos : Long , endPos : Long ): Future [Seq [AlignmentMetadata ]]
8030}
8131
@@ -89,7 +39,6 @@ class AlignmentRepositoryImpl @Inject()(
8939 import models .dal .MyPostgresProfile .api .*
9040
9141 private val metadataTable = DatabaseSchema .domain.genomics.alignmentMetadata
92- private val coverageTable = DatabaseSchema .domain.genomics.alignmentCoverages
9342
9443 override def createMetadata (metadata : AlignmentMetadata ): Future [AlignmentMetadata ] = {
9544 val insertQuery = (metadataTable returning metadataTable.map(_.id)
@@ -99,12 +48,12 @@ class AlignmentRepositoryImpl @Inject()(
9948 db.run(insertQuery.transactionally)
10049 }
10150
102- override def upsertCoverage ( coverage : AlignmentCoverage ): Future [AlignmentCoverage ] = {
51+ override def updateCoverage ( metadataId : Long , coverage : EmbeddedCoverage ): Future [Boolean ] = {
10352 db.run(
104- coverageTable.insertOrUpdate(coverage )
105- .map(_ => coverage)
106- .transactionally
107- )
53+ metadataTable.filter(_.id === metadataId )
54+ .map(_. coverage)
55+ .update( Some ( Json .toJson(coverage)))
56+ ).map(_ > 0 )
10857 }
10958
11059 override def findMetadataBySequenceFile (sequenceFileId : Long ): Future [Seq [AlignmentMetadata ]] = {
@@ -125,23 +74,19 @@ class AlignmentRepositoryImpl @Inject()(
12574 db.run(filteredQuery.result)
12675 }
12776
128- override def findMetadataWithCoverage (metadataId : Long ): Future [Option [( AlignmentMetadata , Option [ AlignmentCoverage ]) ]] = {
77+ override def findMetadataById (metadataId : Long ): Future [Option [AlignmentMetadata ]] = {
12978 db.run(
13079 metadataTable
13180 .filter(_.id === metadataId)
132- .joinLeft(coverageTable)
133- .on(_.id === _.alignmentMetadataId)
13481 .result
13582 .headOption
13683 )
13784 }
13885
139- override def findAllWithCoverageBySequenceFile (sequenceFileId : Long ): Future [Seq [( AlignmentMetadata , Option [ AlignmentCoverage ]) ]] = {
86+ override def findAllBySequenceFile (sequenceFileId : Long ): Future [Seq [AlignmentMetadata ]] = {
14087 db.run(
14188 metadataTable
14289 .filter(_.sequenceFileId === sequenceFileId)
143- .joinLeft(coverageTable)
144- .on(_.id === _.alignmentMetadataId)
14590 .result
14691 )
14792 }
@@ -168,4 +113,4 @@ class AlignmentRepositoryImpl @Inject()(
168113 .result
169114 )
170115 }
171- }
116+ }
0 commit comments