Skip to content

Commit

Permalink
Use files service to get filehandles
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Sep 18, 2024
1 parent e7bbb2f commit 3d78eeb
Showing 1 changed file with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileDocument>,
private readonly filesService: FilesService,
@InjectModel(RefSeqChunk.name)
private readonly refSeqChunkModel: Model<RefSeqChunkDocument>,
@InjectModel(RefSeq.name)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3d78eeb

Please sign in to comment.