Skip to content

Commit

Permalink
Updates branch to master changes
Browse files Browse the repository at this point in the history
  • Loading branch information
scourgemancer committed Feb 4, 2020
1 parent fc71dcb commit 23bd352
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 35 deletions.
27 changes: 5 additions & 22 deletions src/services/v1_service/service.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
import {readFileSync} from "fs";
import {resolve} from "path";
import {Errors, GET, Path, QueryParam} from "typescript-rest";
import {
AnnotationStatus,
Aspect,
ingestData,
makeAnnotationIndex, StructuredData,
UnstructuredText
} from "../../utils/ingest";
import {AnnotationStatus, Aspect, makeAnnotationIndex} from "../../utils/ingest";
import {queryAnnotated, QueryOption, Segment, Strategy} from "../../queries/queries";

// TODO use data fetcher rather than files.
console.log("Begin reading data");
const genesText = readFileSync(resolve("src/assets/gene-types.txt")).toString();
const annotationsText = readFileSync(resolve("src/assets/gene_association.tair")).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");
import {getDataset} from "../../utils/data_fetcher";

@Path("/api/v1")
export class V1Service {
Expand Down Expand Up @@ -55,17 +38,17 @@ export class V1Service {
}

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

return {annotatedGenes: queriedGenes, annotations: queriedAnnotations, unannotatedGenes: []};
}

@Path("/wgs_segments")
@GET
get_wgs() {
const totalGeneCount = Object.keys(dataset.geneIndex).length;
const totalGeneCount = Object.keys(getDataset().geneIndex).length;

const result = Object.entries(dataset.annotations.index)
const result = Object.entries(getDataset().annotations.index)
.reduce((acc, [aspect, {all, known: {all: known_all, exp, other }, unknown}]) => {
acc[aspect].all = all.size;
acc[aspect].known.all = known_all.size;
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 23bd352

Please sign in to comment.