Skip to content

Commit

Permalink
Accomodates refactored service
Browse files Browse the repository at this point in the history
  • Loading branch information
scourgemancer authored and nicholastmosher committed Feb 19, 2020
1 parent aae859e commit aeb9166
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
25 changes: 5 additions & 20 deletions src/services/v1_service/service.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
import {readFileSync} from "fs";
import {resolve} from "path";
import {Errors, GET, Path, QueryParam, Return, ContextResponse} from "typescript-rest";
import {AnnotationStatus, Aspect, makeAnnotationIndex} from "../../utils/ingest";
import {queryAnnotated, QueryOption, Segment, Strategy} from "../../queries/queries";
import {
AnnotationStatus,
Aspect,
ingestData,
makeAnnotationIndex,
StructuredData,
UnstructuredText
} from "../../utils/ingest";
import {annotationsToGAF, genesToCSV} from '../../utils/exporters';
import { getDataset } from '../../utils/data_fetcher';
import express from "express";

// TODO use data fetcher rather than files.
console.log("Begin reading data");
const genesText = readFileSync(process.env["GENES_FILE"] || resolve("src/assets/gene-types.txt")).toString();
const annotationsText = readFileSync(process.env["ANNOTATIONS_FILE"] || resolve("src/assets/tair.gaf")).toString();
const unstructuredText: UnstructuredText = {genesText, annotationsText};
const maybeDataset = ingestData(unstructuredText);
if (!maybeDataset) throw new Error("failed to parse data");
const dataset: StructuredData = maybeDataset;
console.log("Finished parsing data");

type Format = "gaf" | "gene-csv" | "json";

type QueryStatus = "EXP" | "OTHER" | "UNKNOWN" | "UNANNOTATED";
Expand Down Expand Up @@ -69,6 +51,8 @@ export class V1Service {
query = {tag: "QueryWith", strategy, segments};
}

const dataset = getDataset();

// TODO include unannotated genes
const [queriedGenes, queriedAnnotations] = queryAnnotated(dataset, query);

Expand Down Expand Up @@ -97,6 +81,7 @@ export class V1Service {
@Path("/wgs_segments")
@GET
get_wgs() {
const dataset = getDataset();
const totalGeneCount = Object.keys(dataset.genes.index).length;

const result = Object.entries(dataset.annotations.index)
Expand Down
27 changes: 14 additions & 13 deletions src/utils/data_fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import {GeneMap, IAnnotation, GroupedAnnotations, IGene, readData} from "./ingest";
import {readFileSync} from "fs";
import {resolve} from "path";
import {ingestData, StructuredData, UnstructuredText} from "../utils/ingest";

let mostRecentGeneMap: GeneMap;
let mostRecentAnnotations: IAnnotation[];
let mostRecentGroupedAnnotations: GroupedAnnotations<Set<IGene>>;
let mostRecentDataset: StructuredData;

export const getGeneMap = (): GeneMap => { return mostRecentGeneMap; };

export const getAnnotations = (): IAnnotation[] => { return mostRecentAnnotations; };

export const getGroupedAnnotations = (): GroupedAnnotations<Set<IGene>> => { return mostRecentGroupedAnnotations; };
export const getDataset = (): StructuredData => { return mostRecentDataset; };

export const downloadData = (dataUrl: string = "http://current.geneontology.org/annotations/tair.gaf.gz") => {
const { execSync } = require("child_process");
Expand All @@ -17,10 +13,15 @@ export const downloadData = (dataUrl: string = "http://current.geneontology.org/

export const updateData = () => {
downloadData();
const { geneMap, annotations, groupedAnnotations } = readData();
mostRecentGeneMap = geneMap;
mostRecentAnnotations = annotations;
mostRecentGroupedAnnotations = groupedAnnotations;
console.log("Begin reading data");
const genesText = readFileSync(resolve("src/assets/gene-types.txt")).toString();
const annotationsText = readFileSync(resolve("src/assets/tair.gaf")).toString();
const unstructuredText: UnstructuredText = {genesText, annotationsText};
const maybeDataset = ingestData(unstructuredText);
if (!maybeDataset) throw new Error("failed to parse data");
const dataset: StructuredData = maybeDataset;
mostRecentDataset = dataset;
console.log("Finished parsing data");
};

export const startPeriodicallyCalling = (fn: (...args: any[]) => void, interval: number = (1000 * 60 * 60 * 24), startDate: Date = getTomorrowMorning()) => {
Expand Down

0 comments on commit aeb9166

Please sign in to comment.