Skip to content

Commit

Permalink
Add default checks to assembly when it is created
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Oct 21, 2024
1 parent 83c1409 commit 144fef9
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import idValidator from 'mongoose-id-validator'

import { AssembliesModule } from '../assemblies/assemblies.module'
import { CountersModule } from '../counters/counters.module'
import { ChecksModule } from '../checks/checks.module'
import { FeaturesModule } from '../features/features.module'
import { FilesModule } from '../files/files.module'
import { JBrowseModule } from '../jbrowse/jbrowse.module'
Expand Down Expand Up @@ -37,6 +38,7 @@ import { ChangesService } from './changes.service'
FilesModule,
UsersModule,
CountersModule,
ChecksModule,
MessagesModule,
JBrowseModule,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
AssemblyDocument,
Change,
ChangeDocument,
Check,
CheckDocument,
Feature,
FeatureDocument,
File,
Expand Down Expand Up @@ -68,6 +70,8 @@ export class ChangesService {
private readonly jbrowseConfigModel: Model<JBrowseConfigDocument>,
@InjectModel(Change.name)
private readonly changeModel: Model<ChangeDocument>,
@InjectModel(Check.name)
private readonly checkModel: Model<CheckDocument>,
private readonly filesService: FilesService,
private readonly countersService: CountersService,
private readonly pluginsService: PluginsService,
Expand Down Expand Up @@ -123,6 +127,7 @@ export class ChangesService {
fileModel: this.fileModel,
userModel: this.userModel,
jbrowseConfigModel: this.jbrowseConfigModel,
checkModel: this.checkModel,
session,
filesService: this.filesService,
counterService: this.countersService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ import { SequenceModule } from '../sequence/sequence.module'
]),
],

exports: [ChecksService],
exports: [ChecksService, MongooseModule],
controllers: [ChecksController],
})
export class ChecksModule {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Module, forwardRef } from '@nestjs/common'

import { AssembliesModule } from '../assemblies/assemblies.module'
import { ChecksModule } from '../checks/checks.module'
import { CountersModule } from '../counters/counters.module'
import { FeaturesModule } from '../features/features.module'
import { FilesModule } from '../files/files.module'
Expand All @@ -22,6 +23,7 @@ import { OperationsService } from './operations.service'
CountersModule,
MessagesModule,
JBrowseModule,
ChecksModule,
],
providers: [OperationsService],
exports: [OperationsService],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Operation, operationRegistry } from '@apollo-annotation/common'
import {
Assembly,
AssemblyDocument,
Check,
CheckDocument,
Feature,
FeatureDocument,
File,
Expand Down Expand Up @@ -40,6 +42,8 @@ export class OperationsService {
private readonly refSeqModel: Model<RefSeqDocument>,
@InjectModel(RefSeqChunk.name)
private readonly refSeqChunkModel: Model<RefSeqChunkDocument>,
@InjectModel(Check.name)
private readonly checkModel: Model<CheckDocument>,
private readonly filesService: FilesService,
private readonly countersService: CountersService,
private readonly pluginsService: PluginsService,
Expand All @@ -53,6 +57,7 @@ export class OperationsService {
): Promise<ReturnType<T['executeOnServer']>> {
const {
assemblyModel,
checkModel,
connection,
countersService,
featureModel,
Expand All @@ -79,6 +84,7 @@ export class OperationsService {
fileModel,
userModel,
jbrowseConfigModel,
checkModel,
session,
filesService,
counterService: countersService,
Expand Down
2 changes: 2 additions & 0 deletions packages/apollo-common/src/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
RefSeqDocument,
JBrowseConfigDocument,
UserDocument,
CheckDocument,
} from '@apollo-annotation/schemas'
import type { LoggerService } from '@nestjs/common'
import type { ClientSession, Model } from 'mongoose'
Expand All @@ -36,6 +37,7 @@ export interface ServerDataStore {
assemblyModel: Model<AssemblyDocument>
refSeqModel: Model<RefSeqDocument>
refSeqChunkModel: Model<RefSeqChunkDocument>
checkModel: Model<CheckDocument>
fileModel: Model<FileDocument>
userModel: Model<UserDocument>
jbrowseConfigModel: Model<JBrowseConfigDocument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class AddAssemblyAndFeaturesFromFileChange extends FromFileBaseChange {
* @returns
*/
async executeOnServer(backend: ServerDataStore) {
const { assemblyModel, fileModel, filesService, user } = backend
const { assemblyModel, checkModel, fileModel, filesService, user } = backend
const { assembly, changes, logger } = this
for (const change of changes) {
const { assemblyName, fileIds } = change
Expand All @@ -89,9 +89,12 @@ export class AddAssemblyAndFeaturesFromFileChange extends FromFileBaseChange {
if (assemblyDoc) {
throw new Error(`Assembly "${assemblyName}" already exists`)
}
// get checks
const checkDocs = await checkModel.find({ default: true }).exec()
const checks = checkDocs.map((checkDoc) => checkDoc._id.toHexString())
// Add assembly
const [newAssemblyDoc] = await assemblyModel.create([
{ _id: assembly, name: assemblyName, user, status: -1, fileId },
{ _id: assembly, name: assemblyName, user, status: -1, fileId, checks },
])
logger.debug?.(
`Added new assembly "${assemblyName}", docId "${newAssemblyDoc._id.toHexString()}"`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class AddAssemblyFromExternalChange extends AssemblySpecificChange {
* @returns
*/
async executeOnServer(backend: ServerDataStore) {
const { assemblyModel, refSeqModel, user } = backend
const { assemblyModel, checkModel, refSeqModel, user } = backend
const { assembly, changes, logger } = this
const { CHUNK_SIZE } = process.env
const customChunkSize = CHUNK_SIZE && Number(CHUNK_SIZE)
Expand Down Expand Up @@ -97,13 +97,16 @@ export class AddAssemblyFromExternalChange extends AssemblySpecificChange {
if (assemblyDoc) {
throw new Error(`Assembly "${assemblyName}" already exists`)
}
const checkDocs = await checkModel.find({ default: true }).exec()
const checks = checkDocs.map((checkDoc) => checkDoc._id.toHexString())
const [newAssemblyDoc] = await assemblyModel.create([
{
_id: assembly,
name: assemblyName,
user,
status: -1,
externalLocation,
checks,
},
])
logger.debug?.(
Expand Down
18 changes: 15 additions & 3 deletions packages/apollo-shared/src/Changes/AddAssemblyFromFileChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ export class AddAssemblyFromFileChange extends FromFileBaseChange {
}

const { fa, fai, gzi } = fileIds
const { assemblyModel, fileModel, filesService, refSeqModel, user } =
backend
const {
assemblyModel,
checkModel,
fileModel,
filesService,
refSeqModel,
user,
} = backend

const faDoc = await fileModel.findById(fa)
const faChecksum = faDoc?.checksum
Expand Down Expand Up @@ -122,13 +128,16 @@ export class AddAssemblyFromFileChange extends FromFileBaseChange {
if (assemblyDoc) {
throw new Error(`Assembly "${assemblyName}" already exists`)
}
const checkDocs = await checkModel.find({ default: true }).exec()
const checks = checkDocs.map((checkDoc) => checkDoc._id.toHexString())
const [newAssemblyDoc] = await assemblyModel.create([
{
_id: this.assembly,
name: assemblyName,
user,
status: -1,
fileIds,
checks,
},
])
this.logger.debug?.(
Expand Down Expand Up @@ -157,7 +166,7 @@ export class AddAssemblyFromFileChange extends FromFileBaseChange {
assemblyName: string,
fileId: string,
) {
const { assemblyModel, fileModel, user } = backend
const { assemblyModel, checkModel, fileModel, user } = backend
// Get file checksum
const fileDoc = await fileModel.findById(fileId).exec()
if (!fileDoc) {
Expand All @@ -172,6 +181,8 @@ export class AddAssemblyFromFileChange extends FromFileBaseChange {
if (assemblyDoc) {
throw new Error(`Assembly "${assemblyName}" already exists`)
}
const checkDocs = await checkModel.find({ default: true }).exec()
const checks = checkDocs.map((checkDoc) => checkDoc._id.toHexString())
// Add assembly
const [newAssemblyDoc] = await assemblyModel.create([
{
Expand All @@ -180,6 +191,7 @@ export class AddAssemblyFromFileChange extends FromFileBaseChange {
user,
status: -1,
fileIds: { fa: fileId },
checks,
},
])
this.logger.debug?.(
Expand Down

0 comments on commit 144fef9

Please sign in to comment.