Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"!**/*.d.ts",
"!**/generated",
"!**/apps/platform/src",
"!**/packages/ui",
"!**/packages/sections",
"!**/packages/ot-config",
"!**/packages/ot-constants",
"**/packages/ot-constants",
"!**/packages/ot-constants/src/types",
"!**/packages/ot-utils"
]
},
Expand Down Expand Up @@ -70,7 +70,7 @@
"useButtonType": "error"
},
"correctness": {
"useExhaustiveDependencies": "warn",
"useExhaustiveDependencies": "off",
"noUnusedVariables": "warn"
},
"suspicious": {
Expand Down
55 changes: 27 additions & 28 deletions packages/ot-config/src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import type { Config, Environment } from "./types";

export const getEnvironmentConfig = (env: Environment): Config => {
const configs: Record<Environment, Config> = {
development: {
urlApi: "http://localhost:8080",
urlAiApi: "http://localhost:8081",
profile: {},
googleTagManagerID: null,
geneticsPortalUrl: "https://genetics.opentargets.org",
gitVersion: "",
},
production: {
urlApi: "https://api.platform.opentargets.org",
urlAiApi: "https://ai.platform.opentargets.org",
profile: {},
googleTagManagerID: "GTM-XXXXX",
geneticsPortalUrl: "https://genetics.opentargets.org",
gitVersion: "",
},
};
const configs: Record<Environment, Config> = {
development: {
urlApi: "http://localhost:8080",
urlAiApi: "http://localhost:8081",
profile: {},
googleTagManagerID: null,
geneticsPortalUrl: "https://genetics.opentargets.org",
gitVersion: "",
},
production: {
urlApi: "https://api.platform.opentargets.org",
urlAiApi: "https://ai.platform.opentargets.org",
profile: {},
googleTagManagerID: "GTM-XXXXX",
geneticsPortalUrl: "https://genetics.opentargets.org",
gitVersion: "",
},
};

return configs[env];
return configs[env];
};

// Vite environment variables
Expand All @@ -29,13 +29,12 @@ const ENV_AI_API_URL: string | undefined = import.meta.env.VITE_AI_API_URL;
const ENV_GIT_VERSION: string | undefined = import.meta.env.VITE_GIT_VERSION;

export const getConfig = (): Config => {
return {
urlApi:window.configUrlApi ?? ENV_API_URL ?? "",
urlAiApi: window.configOTAiApi ?? ENV_AI_API_URL ?? "",
gitVersion: window.gitVersion ?? ENV_GIT_VERSION ?? "",
profile: window.configProfile ?? { isPartnerPreview: false },
googleTagManagerID: window.configGoogleTagManagerID ?? null,
geneticsPortalUrl:
window.configGeneticsPortalUrl ?? "https://genetics.opentargets.org",
};
return {
urlApi: window.configUrlApi ?? ENV_API_URL ?? "",
urlAiApi: window.configOTAiApi ?? ENV_AI_API_URL ?? "",
gitVersion: window.gitVersion ?? ENV_GIT_VERSION ?? "",
profile: window.configProfile ?? { isPartnerPreview: false },
googleTagManagerID: window.configGoogleTagManagerID ?? null,
geneticsPortalUrl: window.configGeneticsPortalUrl ?? "https://genetics.opentargets.org",
};
};
2 changes: 1 addition & 1 deletion packages/ot-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./types";
export * from "./environment";
export * from "./theme";
export * from "./types";

// Add window augmentation
declare global {
Expand Down
4 changes: 2 additions & 2 deletions packages/ot-config/src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { lighten, darken } from "polished";
import { grey } from "@mui/material/colors";
import { ThemeOptions, createTheme } from "@mui/material/styles";
import { createTheme, type ThemeOptions } from "@mui/material/styles";
import { darken, lighten } from "polished";
import { getConfig } from "./environment";

const config = getConfig();
Expand Down
38 changes: 19 additions & 19 deletions packages/ot-constants/scripts/generate-graphql-types.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node

import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -148,7 +148,7 @@ function generateTypeScriptInterface(type) {

let interfaceCode = `export interface ${type.name} {\n`;

fields.forEach(field => {
for (const field of fields) {
const fieldType = graphqlTypeToTypeScript(field.type);
const isOptional = field.type.kind !== "NON_NULL";
const optionalMarker = isOptional ? "?" : "";
Expand All @@ -157,7 +157,7 @@ function generateTypeScriptInterface(type) {
interfaceCode += ` /** ${field.description} */\n`;
}
interfaceCode += ` ${field.name}${optionalMarker}: ${fieldType};\n`;
});
}

interfaceCode += "}\n\n";
return interfaceCode;
Expand All @@ -171,12 +171,12 @@ function generateTypeScriptEnum(type) {

let enumCode = `export enum ${type.name} {\n`;

type.enumValues.forEach(enumValue => {
for (const enumValue of type.enumValues) {
if (enumValue.description) {
enumCode += ` /** ${enumValue.description} */\n`;
}
enumCode += ` ${enumValue.name} = '${enumValue.name}',\n`;
});
}

enumCode += "}\n\n";
return enumCode;
Expand All @@ -188,7 +188,7 @@ function generateTypeScriptUnion(type) {
return null;
}

const possibleTypes = type.possibleTypes.map(t => t.name).join(" | ");
const possibleTypes = type.possibleTypes.map((t) => t.name).join(" | ");
return `export type ${type.name} = ${possibleTypes};\n\n`;
}

Expand All @@ -209,7 +209,7 @@ async function testEndpoint(endpoint) {

if (response.ok) {
const result = await response.json();
if (result.data && result.data.__schema) {
if (result.data?.__schema) {
console.log(`✅ Endpoint working: ${endpoint}`);
return result;
}
Expand Down Expand Up @@ -246,7 +246,7 @@ async function generateGraphQLTypes() {

const schema = result.data.__schema;
const types = schema.types.filter(
type =>
(type) =>
!type.name.startsWith("__") &&
type.name !== "Query" &&
type.name !== "Mutation" &&
Expand All @@ -263,32 +263,32 @@ async function generateGraphQLTypes() {

// Generate interfaces and input types
const objectTypes = types.filter(
type => type.kind === "OBJECT" || type.kind === "INPUT_OBJECT"
(type) => type.kind === "OBJECT" || type.kind === "INPUT_OBJECT"
);
objectTypes.forEach(type => {
for (const type of objectTypes) {
const interfaceCode = generateTypeScriptInterface(type);
if (interfaceCode) {
generatedCode += interfaceCode;
}
});
}

// Generate enums
const enumTypes = types.filter(type => type.kind === "ENUM");
enumTypes.forEach(type => {
const enumTypes = types.filter((type) => type.kind === "ENUM");
for (const type of enumTypes) {
const enumCode = generateTypeScriptEnum(type);
if (enumCode) {
generatedCode += enumCode;
}
});
}

// Generate union types
const unionTypes = types.filter(type => type.kind === "UNION");
unionTypes.forEach(type => {
const unionTypes = types.filter((type) => type.kind === "UNION");
for (const type of unionTypes) {
const unionCode = generateTypeScriptUnion(type);
if (unionCode) {
generatedCode += unionCode;
}
});
}

// Write the generated types to a file in the types folder
const outputPath = path.join(__dirname, "..", "src", "types", "graphql-types.ts");
Expand Down
16 changes: 11 additions & 5 deletions packages/ot-constants/src/alphaFold.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { scaleLinear, interpolateLab, rgb, scaleQuantize } from "d3";
import { interpolateLab, rgb, scaleLinear } from "d3";

export const alphaFoldConfidenceBands = [
{ lowerLimit: 90, label: "Very high", sublabel: "90 > pLDDT", color: "rgb(0, 83, 214)" },
Expand All @@ -12,7 +12,10 @@ export const alphaFoldConfidenceBands = [
{ lowerLimit: 0, label: "Very low ", sublabel: "50 > pLDDT", color: "rgb(255, 125, 69)" },
];

export function getAlphaFoldConfidence(atom, propertyName = "label") {
export function getAlphaFoldConfidence(
atom: { b: number },
propertyName: "label" | "sublabel" | "color" = "label"
): string {
for (const obj of alphaFoldConfidenceBands) {
if (atom.b > obj.lowerLimit) return obj[propertyName];
}
Expand All @@ -35,7 +38,10 @@ export const alphaFoldPathogenicityBands = [
{ lowerLimit: 0, label: "Likely benign", sublabel: "score < 0.34", color: "rgb(61, 84, 147)" },
];

export function getAlphaFoldPathogenicity(score, propertyName = "label") {
export function getAlphaFoldPathogenicity(
score: number,
propertyName: "label" | "sublabel" | "color" = "label"
): string {
for (const obj of alphaFoldPathogenicityBands) {
if (score > obj.lowerLimit) return obj[propertyName];
}
Expand All @@ -59,7 +65,7 @@ export const alphaFoldPathogenicityColorScale = scaleLinear()
// only some of the scale breakpoints are meaningful for the legend
alphaFoldPathogenicityColorScale._primaryDomain = [0, 0.34, 0.564, 1];

export function getAlphaFoldPathogenicityColor(score) {
export function getAlphaFoldPathogenicityColor(score: number) {
return alphaFoldPathogenicityColorScale(score);
}

Expand Down Expand Up @@ -109,4 +115,4 @@ export const aminoAcidHydrophobicity = {
GLU: { value: -31, label: "hydrophilic" },
PRO: { value: -46, label: "hydrophilic" },
ASP: { value: -55, label: "hydrophilic" },
};
};
48 changes: 28 additions & 20 deletions packages/ot-constants/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
import { faBook, faEnvelope } from "@fortawesome/free-solid-svg-icons";
import type { IconDefinition } from "@fortawesome/fontawesome-svg-core";
import {
faDiscourse,
faTwitterSquare,
faLinkedin,
faGithubSquare,
faLinkedin,
faTwitterSquare,
faYoutubeSquare,
} from "@fortawesome/free-brands-svg-icons";
import { faBook, faEnvelope } from "@fortawesome/free-solid-svg-icons";
import { getConfig } from "@ot/config";

const config = getConfig();
Expand Down Expand Up @@ -303,15 +303,17 @@ export const VIEW = {
table: "Table",
};

export const getStudyTypeDisplay = (studyType: string | null | undefined): string | null | undefined => {
export const getStudyTypeDisplay = (
studyType: string | null | undefined
): string | null | undefined => {
if (studyType) return studyType?.replace(/(qtl|gwas)/gi, (match: string) => match.toUpperCase());
return studyType;
};

export const getStudyItemMetaData = ({
studyType,
credibleSetsCount,
nSamples
nSamples,
}: {
studyType?: string;
credibleSetsCount: number;
Expand All @@ -326,26 +328,32 @@ export const getStudyItemMetaData = ({
return metaData;
};

export const getGenomicLocation = (genomicLocation: {
chromosome?: string;
start?: number;
end?: number;
strand?: number;
} | null | undefined) => {
export const getGenomicLocation = (
genomicLocation:
| {
chromosome?: string;
start?: number;
end?: number;
strand?: number;
}
| null
| undefined
) => {
/****
* TODO: add GRCh38 to this function
* check all the locations we are using this
* option 1: getGenomicLocation() -> ["GRCh38", "chromosome-string"]
* option 2: getGenomicLocation("GRCh38") -> "GRCh38|chromosome-string"
****/
return `${genomicLocation?.chromosome}:${genomicLocation?.start}-${genomicLocation?.end},${Math.sign(genomicLocation?.strand) === 1 ? "+" : "-"
}`;
return `${genomicLocation?.chromosome}:${genomicLocation?.start}-${genomicLocation?.end},${
Math.sign(genomicLocation?.strand ?? 1) === 1 ? "+" : "-"
}`;
};
export * from "./dataTypes";
export * from "./types/response";
export * from "./types/graphql-types";
export * from "./searchSuggestions";
export * from "./partnerPreviewUtils";
export * from "./alphaFold";
export * from "./dataTypes";
export * from "./particlesBackground";
export * from "./variant";
export * from "./partnerPreviewUtils";
export * from "./searchSuggestions";
export * from "./types/graphql-types";
export * from "./types/response";
export * from "./variant";
13 changes: 7 additions & 6 deletions packages/ot-constants/src/partnerPreviewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { getConfig } from "@ot/config";
const config = getConfig();

// page sections
export const isPrivateTargetSection = id => config.profile.partnerTargetSectionIds.includes(id);
export const isPrivateDiseaseSection = id => config.profile.partnerDiseaseSectionIds.includes(id);
export const isPrivateDrugSection = id => config.profile.partnerDrugSectionIds.includes(id);
export const isPrivateEvidenceSection = id => config.profile.partnerEvidenceSectionIds.includes(id);
export const isPrivateTargetSection = (id) => config.profile.partnerTargetSectionIds.includes(id);
export const isPrivateDiseaseSection = (id) => config.profile.partnerDiseaseSectionIds.includes(id);
export const isPrivateDrugSection = (id) => config.profile.partnerDrugSectionIds.includes(id);
export const isPrivateEvidenceSection = (id) =>
config.profile.partnerEvidenceSectionIds.includes(id);

// associations
export const isPrivateDataType = id => config.profile.partnerDataTypes.includes(id);
export const isPrivateDataSource = id => config.profile.partnerDataSources.includes(id);
export const isPrivateDataType = (id) => config.profile.partnerDataTypes.includes(id);
export const isPrivateDataSource = (id) => config.profile.partnerDataSources.includes(id);
19 changes: 9 additions & 10 deletions packages/ot-constants/src/types/graphql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1438,16 +1438,15 @@ export interface geneticVariation {
}

export enum StudyTypeEnum {
eqtl = 'eqtl',
gwas = 'gwas',
pqtl = 'pqtl',
sceqtl = 'sceqtl',
scpqtl = 'scpqtl',
scsqtl = 'scsqtl',
sctuqtl = 'sctuqtl',
sqtl = 'sqtl',
tuqtl = 'tuqtl',
eqtl = "eqtl",
gwas = "gwas",
pqtl = "pqtl",
sceqtl = "sceqtl",
scpqtl = "scpqtl",
scsqtl = "scsqtl",
sctuqtl = "sctuqtl",
sqtl = "sqtl",
tuqtl = "tuqtl",
}

export type EntityUnionType = Target | Drug | Disease | Variant | Study;

Loading
Loading