diff --git a/packages/apollo-collaboration-server/src/sequence/sequence.service.ts b/packages/apollo-collaboration-server/src/sequence/sequence.service.ts index f7fc9fc3..a8dc0a31 100644 --- a/packages/apollo-collaboration-server/src/sequence/sequence.service.ts +++ b/packages/apollo-collaboration-server/src/sequence/sequence.service.ts @@ -13,19 +13,19 @@ import { import { BgzipIndexedFasta, IndexedFasta } from '@gmod/indexedfasta' import { Injectable, Logger } from '@nestjs/common' import { InjectModel } from '@nestjs/mongoose' -import { LocalFile, RemoteFile } from 'generic-filehandle' +import { RemoteFile } from 'generic-filehandle' import { Model } from 'mongoose' import { AssembliesService } from '../assemblies/assemblies.service' +import { FilesService } from '../files/files.service' import { GetSequenceDto } from './dto/get-sequence.dto' -import path from 'node:path' -import { LocalFileGzip } from '@apollo-annotation/shared' @Injectable() export class SequenceService { constructor( @InjectModel(File.name) private readonly fileModel: Model, + private readonly filesService: FilesService, @InjectModel(RefSeqChunk.name) private readonly refSeqChunkModel: Model, @InjectModel(RefSeq.name) @@ -72,39 +72,30 @@ export class SequenceService { this.logger.debug( `Local fasta file = ${fa}, Local fasta index file = ${fai}`, ) - const { FILE_UPLOAD_FOLDER } = process.env - if (!FILE_UPLOAD_FOLDER) { - throw new Error('No FILE_UPLOAD_FOLDER found in .env file') - } const faDoc = await this.fileModel.findById(fa) - const faChecksum = faDoc?.checksum - if (!faChecksum) { - throw new Error(`No checksum for file document ${faDoc}`) + if (!faDoc) { + throw new Error(`No checksum for file document ${fa}`) } const faiDoc = await this.fileModel.findById(fai) - const faiChecksum = faiDoc?.checksum - if (!faiChecksum) { - throw new Error(`No checksum for file document ${faiDoc}`) + if (!faiDoc) { + throw new Error(`File document not found for ${fai}`) } const gziDoc = await this.fileModel.findById(gzi) - const gziChecksum = gziDoc?.checksum - if (!gziChecksum) { - throw new Error(`No checksum for file document ${gziDoc}`) + if (!gziDoc) { + throw new Error(`File document not found for ${gzi}`) } const sequenceAdapter = gzi ? new BgzipIndexedFasta({ - fasta: new LocalFile(path.join(FILE_UPLOAD_FOLDER, faChecksum)), - fai: new LocalFileGzip(path.join(FILE_UPLOAD_FOLDER, faiChecksum), { - encoding: 'utf8', - }), - gzi: new LocalFileGzip(path.join(FILE_UPLOAD_FOLDER, gziChecksum)), + fasta: this.filesService.getFileHandle(faDoc), + fai: this.filesService.getFileHandle(faiDoc), + gzi: this.filesService.getFileHandle(gziDoc), }) : new IndexedFasta({ - fasta: new LocalFile(fa), - fai: new LocalFile(fai), + fasta: this.filesService.getFileHandle(faDoc), + fai: this.filesService.getFileHandle(faiDoc), }) const sequence = await sequenceAdapter.getSequence(name, start, end) if (sequence === undefined) {