Skip to content

Commit

Permalink
Merge pull request #362 from hpi-dhc/issue/343-rename-genephenotype
Browse files Browse the repository at this point in the history
Rename `GenePhenotype`
  • Loading branch information
jannis-baum authored Jun 20, 2022
2 parents 9d04bb1 + 5cbf0b5 commit 47e1d56
Show file tree
Hide file tree
Showing 20 changed files with 224 additions and 221 deletions.
4 changes: 2 additions & 2 deletions annotation-server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { TypeOrmModule } from '@nestjs/typeorm';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { GenePhenotypesModule } from './gene-phenotypes/gene-phenotypes.module';
import { GuidelinesModule } from './guidelines/guidelines.module';
import { MedicationsModule } from './medications/medications.module';
import { PhenotypesModule } from './phenotypes/phenotypes.module';

@Module({
imports: [
Expand All @@ -32,7 +32,7 @@ import { MedicationsModule } from './medications/medications.module';
}),
inject: [ConfigService],
}),
GenePhenotypesModule,
PhenotypesModule,
GuidelinesModule,
MedicationsModule,
ScheduleModule.forRoot(),
Expand Down
6 changes: 3 additions & 3 deletions annotation-server/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';

import { GenePhenotypesService } from './gene-phenotypes/gene-phenotypes.service';
import { GuidelinesService } from './guidelines/guidelines.service';
import { MedicationsService } from './medications/medications.service';
import { PhenotypesService } from './phenotypes/phenotypes.service';

@Injectable()
export class AppService {
constructor(
private medicationService: MedicationsService,
private guidelineService: GuidelinesService,
private genephenotypeService: GenePhenotypesService,
private phenotypesService: PhenotypesService,
) {}

@Cron('0 0 1 * *', { name: 'monthlyUpdates' })
async initializeDatabase(): Promise<void> {
await this.medicationService.fetchAllMedications();
await this.genephenotypeService.fetchGenePhenotypes();
await this.phenotypesService.fetchPhenotypes();
await this.guidelineService.fetchGuidelines();
}
}
89 changes: 0 additions & 89 deletions annotation-server/src/guidelines/caches/gene-phenotype-caches.ts

This file was deleted.

89 changes: 89 additions & 0 deletions annotation-server/src/guidelines/caches/phenotype-caches.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { ILike } from 'typeorm';

import { Phenotype } from '../../phenotypes/entities/phenotype.entity';
import { PhenotypesService } from '../../phenotypes/phenotypes.service';
import {
GuidelineError,
GuidelineErrorBlame,
GuidelineErrorType,
} from '../entities/guideline-error.entity';
import { GuidelineCacheMap } from './guideline-cache';

export class PhenotypesByGeneCache extends GuidelineCacheMap<
Array<Set<Phenotype>>
> {
private phenotypesService: PhenotypesService;
private spreadsheetGeneResultHeader: Set<string>[];

constructor(
phenotypesService: PhenotypesService,
spreadsheetGeneResultHeader: Set<string>[],
) {
super();
this.phenotypesService = phenotypesService;
this.spreadsheetGeneResultHeader = spreadsheetGeneResultHeader;
}

protected async retrieve(
...[geneSymbolName]: string[]
): Promise<Set<Phenotype>[]> {
const geneSymbol = await this.phenotypesService.findOneGeneSymbol({
where: { name: ILike(geneSymbolName) },
relations: [
'phenotypes',
'phenotypes.geneResult',
'phenotypes.geneSymbol',
],
});
const phenotypes = this.spreadsheetGeneResultHeader.map(
(geneResults) =>
new Set(
geneSymbol.phenotypes.filter((phenotype) =>
geneResults.has(
phenotype.geneResult.name.toLowerCase(),
),
),
),
);
return phenotypes;
}

protected createError(...[geneSymbolName]: string[]): GuidelineError {
const error = new GuidelineError();
error.type = GuidelineErrorType.PHENOTYPE_NOT_FOUND;
error.blame = GuidelineErrorBlame.CPIC;
error.context = geneSymbolName;
return error;
}
}

export class PhenotypesCache extends GuidelineCacheMap<Phenotype> {
private phenotypesService: PhenotypesService;

constructor(phenotypesService: PhenotypesService) {
super();
this.phenotypesService = phenotypesService;
}

protected async retrieve(
...[geneSymbolName, geneResultName]: string[]
): Promise<Phenotype> {
return this.phenotypesService.findOne({
where: {
geneSymbol: { name: ILike(geneSymbolName) },
geneResult: { name: geneResultName },
},
relations: ['geneResult', 'geneSymbol'],
});
}

protected createError(
...[geneSymbolName, geneResultName]: string[]
): GuidelineError {
const error = new GuidelineError();
error.type = GuidelineErrorType.PHENOTYPE_NOT_FOUND;
error.blame = GuidelineErrorBlame.CPIC;
error.context = `${geneSymbolName}:${geneResultName}`;
return error;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Guideline } from './guideline.entity';
export enum GuidelineErrorType {
MEDICATION_NAME_NOT_FOUND = 'medication_name_not_found',
MEDICATION_RXCUI_NOT_FOUND = 'medication_rxcui_not_found',
GENEPHENOTYPE_NOT_FOUND = 'genephenotype_not_found',
PHENOTYPE_NOT_FOUND = 'phenotype_not_found',
GENE_NOT_FOUND = 'gene_not_found',
GUIDELINE_MISSING_FROM_SHEET = 'guideline_missing_from_sheet',
GUIDELINE_MISSING_FROM_CPIC = 'guideline_missing_from_cpic',
Expand Down
12 changes: 6 additions & 6 deletions annotation-server/src/guidelines/entities/guideline.entity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';

import { BaseEntity } from '../../common/entities/base.entity';
import { GenePhenotype } from '../../gene-phenotypes/entities/gene-phenotype.entity';
import { Medication } from '../../medications/medication.entity';
import { Phenotype } from '../../phenotypes/entities/phenotype.entity';
import { CpicRecommendationDto } from '../dtos/cpic-recommendation.dto';
import { GuidelineError } from './guideline-error.entity';

Expand Down Expand Up @@ -32,8 +32,8 @@ export class Guideline extends BaseEntity {
})
medication: Medication;

@ManyToOne(() => GenePhenotype, { onDelete: 'CASCADE' })
genePhenotype: GenePhenotype;
@ManyToOne(() => Phenotype, { onDelete: 'CASCADE' })
phenotype: Phenotype;

@Column()
cpicRecommendation: string;
Expand Down Expand Up @@ -68,18 +68,18 @@ export class Guideline extends BaseEntity {
static fromCpicRecommendation(
recommendation: CpicRecommendationDto,
medication: Medication,
genePhenotype: GenePhenotype,
phenotype: Phenotype,
): Guideline {
const guideline = new Guideline();

guideline.medication = medication;
guideline.genePhenotype = genePhenotype;
guideline.phenotype = phenotype;
guideline.cpicRecommendation = recommendation.drugrecommendation;
guideline.cpicClassification = recommendation.classification;
if (recommendation.comments.toLowerCase() !== 'n/a')
guideline.cpicComment = recommendation.comments;
guideline.cpicImplication =
recommendation.implications[genePhenotype.geneSymbol.name];
recommendation.implications[phenotype.geneSymbol.name];
guideline.cpicGuidelineId = recommendation.guidelineid;
guideline.errors = [];

Expand Down
4 changes: 2 additions & 2 deletions annotation-server/src/guidelines/guidelines.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

import { GenePhenotypesModule } from '../gene-phenotypes/gene-phenotypes.module';
import { MedicationsModule } from '../medications/medications.module';
import { PhenotypesModule } from '../phenotypes/phenotypes.module';
import { GuidelineError } from './entities/guideline-error.entity';
import { Guideline } from './entities/guideline.entity';
import { GuidelinesController } from './guidelines.controller';
Expand All @@ -12,7 +12,7 @@ import { GuidelinesService } from './guidelines.service';
@Module({
imports: [
HttpModule,
GenePhenotypesModule,
PhenotypesModule,
MedicationsModule,
TypeOrmModule.forFeature([Guideline, GuidelineError]),
],
Expand Down
Loading

0 comments on commit 47e1d56

Please sign in to comment.