Skip to content

Commit

Permalink
Merge remote-tracking branch 'exrna/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
u8sand committed Sep 23, 2024
2 parents de83e7d + c951805 commit 4da2bfa
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 189 deletions.
48 changes: 47 additions & 1 deletion components/legacy/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { MetaNode } from '@/spec/metanode'
import { GeneTerm, VariantTerm } from '@/components/core/term'
import { z } from 'zod'
import { gene_icon, mygeneinfo_icon } from '@/icons'
import { gene_icon, mygeneinfo_icon, datafile_icon } from '@/icons'
import * as array from '@/utils/array'
import { z_maybe_array } from '@/utils/zod'
import { resolveVariantCaID, getMyVarintInfoLink, variantIdResolveErrorMessage, alleleRegRespErrorMessage } from '@/components/service/variantinfo/variantUtils'
import { getAlleleRegistryVariantInfo } from '@/components/service/variantinfo/variantInfoSources/alleleRegistryVariantInfo'
import { getVariantInfoFromMyVariantInfo } from '@/components/service/variantinfo/variantInfoSources/myVariantInfo'
import { MyRegulatoryElementSetInfoC } from '@/components/service/regulatoryElementInfo/reUtils'
import { Table, Cell, Column} from '@/app/components/Table'
import { downloadBlob } from '@/utils/download'

export const MyVariantInfoC = z.object({
_id: z.string(),
Expand Down Expand Up @@ -119,3 +122,46 @@ export const VariantInfoFromVariantTermMyVarintInfo = MetaNode('VariantInfoFromV
legend: `The closest gene to ${props.inputs?.variant ? props.inputs.variant : 'the variant'}, as reported by MyVariant.info [\\ref{doi:10.1186/s13059-016-0953-9}\\ref{doi:10.1093/bioinformatics/btac017}.`,
}))
.build()

export const RegulatoryElementSetInfo = MetaNode('RegulatoryElementSetInfo')
.meta({
label: 'Regulatory Element Set Info',
description: '',
icon: [datafile_icon],
hidden: true,
})
.codec(MyRegulatoryElementSetInfoC)
.view(regulatoryElementSet => {
return(
<>
<p style={{fontSize: '14px'}}><b>Note:</b> In order to view all data, if avaliable, please expand the table rows!</p>
<Table
height={500}
cellRendererDependencies={[regulatoryElementSet]}
numRows={regulatoryElementSet.length}
enableGhostCells
enableFocusedCell
downloads={{
JSON: () => downloadBlob(new Blob([JSON.stringify(regulatoryElementSet)], { type: 'application/json;charset=utf-8' }), 'data.json')
}}>
<Column
name="Entity id"
cellRenderer={row => <Cell key={row+''}>{regulatoryElementSet[row].entId}</Cell>}
/>
<Column
name="Chromosome"
cellRenderer={row => <Cell key={row+''}>{regulatoryElementSet[row].entContent.coordinates.chromosome}</Cell>}
/>
<Column
name="Start Pos."
cellRenderer={row => <Cell key={row+''}>{regulatoryElementSet[row].entContent.coordinates.start}</Cell>}
/>
<Column
name="End Pos."
cellRenderer={row => <Cell key={row+''}>{regulatoryElementSet[row].entContent.coordinates.end}</Cell>}
/>
</Table>
</>
)
})
.build()
27 changes: 18 additions & 9 deletions components/service/ldh/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { MetaNode } from '@/spec/metanode'
import { GeneTerm } from '@/components/core/term'
import { GeneSet } from '@/components/core/set'
import { RegulatoryElementSetInfo, RegulatoryElementSetForGeneSetInfo, setGenomicPositionsForRegulatoryElementSet, MyGeneToRegulatoryElementSetInfo, MyRegulatoryElementSetInfo } from '@/components/service/regulatoryElementInfo'
import { GeneSet, RegulatoryElementSet } from '@/components/core/set'
import { RegulatoryElementSetForGeneSetInfo, MyGeneToRegulatoryElementSetInfo, MyRegulatoryElementSetInfo } from '@/components/service/regulatoryElementInfo'
import { GeneInfo, GeneInfoFromGeneTerm } from '@/components/service/mygeneinfo'
import { linkeddatahub_icon } from '@/icons'
import { z } from 'zod'
import { describe } from 'node:test'

export const MyGeneInfoByTermC = z.object({
data: z.object({
Expand Down Expand Up @@ -60,23 +61,31 @@ export const GetRegulatoryElementsInfoForGeneInfo = MetaNode('GetRegulatoryEleme
pagerank: 1,
})
.inputs({ geneInfo: GeneInfo })
.output(RegulatoryElementSetInfo)
.output(RegulatoryElementSet)
.resolve(async (props) => {
const response = await myGeneInfoFromLinkDataHub(props.inputs.geneInfo.symbol);
if(response.data == null || response.data.ld == null){
throw new Error("Unable to get data from Linked Data Hub API, please try again or wait a few minutes before the next atempt!");
}

let reObjSet: any = response.data.ld.RegulatoryElement;
let reObjSet = response.data.ld.RegulatoryElement;
if(reObjSet == null || reObjSet.length == 0){
throw new Error("Unable to get Regulatory Element data for gene "+props.inputs.geneInfo.symbol+" from Linked Data Hub API, please try again or wait a few minutes before the next atempt!");
}
let reInfoSet = getREPositionDataFromLinkDataHub(reObjSet);
if(reInfoSet == null || reInfoSet.length == 0){
throw new Error("Unable to get Regulatory Element(s) coordinates for gene "+props.inputs.geneInfo.symbol+" from Linked Data Hub API, please try again or wait a few minutes before the next atempt!");
}

return reInfoSet;
let reIdentifiersSet = [];
for(let i in reObjSet){
reIdentifiersSet.push(reObjSet[i].entId);
}
if(reIdentifiersSet.length == 0){
throw new Error("Unable to get Regulatory Element data for gene "+props.inputs.geneInfo.symbol+" from Linked Data Hub API, please try again or wait a few minutes before the next atempt!");
}

let tempObj = {
description:"Regulatory Elements Set",
set: reIdentifiersSet
}
return tempObj;
})
.story(props => ({
abstract: `Regulatory elements in 10kbps region upstream or downstream of gene ${props.inputs ? ` ${props.inputs.geneInfo.symbol}` : ''}.`
Expand Down
134 changes: 98 additions & 36 deletions components/service/regulatoryElementInfo/reUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { MetaNode } from '@/spec/metanode'
import { z } from 'zod'

//General RE info

export const RegulatoryElementInfoC = z.object({
data: z.object({
entId: z.string(),
entType: z.string(),
coordinates: z.object({
"chromosome": z.string(),
"start": z.number(),
"end": z.number()
entContent: z.object({
coordinates: z.object({
chromosome: z.string(),
start: z.number(),
end: z.number()
}),
}),
ld: z.object({
ENCODERegulatoryElementEvidence: z.array(z.object({
Expand All @@ -33,46 +34,107 @@ export const RegulatoryElementInfoC = z.object({

export type RegulatoryElementInfo = z.infer<typeof RegulatoryElementInfoC>

export async function myRegElemInfo_query(regElemId: string): Promise<RegulatoryElementInfo> {
export async function myRegElemInfoFromLDH(regElemId: string): Promise<RegulatoryElementInfo> {
const res = await fetch(`https://ldh.genome.network/cfde/ldh/RegulatoryElement/id/${encodeURIComponent(regElemId)}`)
return await res.json()
}

//positional data from Weng Lab
export const RE_PositionalDataWengLabC = z.object({
data: z.object({
cCREQuery: z.array(z.object({
coordinates: z.object({
chromosome: z.string(),
start: z.number(),
end: z.number()
})
}))
})
});
type RE_PositionalDataWengLab = z.infer<typeof RE_PositionalDataWengLabC>

//Position data
export async function getRegElemPositionDataWengLab(regElemId: string): Promise<RE_PositionalDataWengLab> {
let bodyString = '{\"query\":\"query CCRE{\\n cCREQuery(assembly: \\"GRCh38\\", accession:\\"'+encodeURIComponent(regElemId)+'\\") {\\n coordinates {\\n chromosome\\n start\\n end\\n }\\n }\\n}"}';
const res = await fetch(`https://ga.staging.wenglab.org/graphql`, {
method: 'POST',
headers: {
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Connection': 'keep-alive',
'DNT': '1',
'Origin': 'https://ga.staging.wenglab.org'
},
body: bodyString
})
return await res.json()
}

export const RE_PositionalDataC = z.object({
data: z.object({
cCREQuery: z.array(z.object({
coordinates: z.object({
chromosome: z.string(),
start: z.number(),
end: z.number()
})
}))
})
});
type RE_PositionalData = z.infer<typeof RE_PositionalDataC>

export async function getRegElemPositionData(regElemId: string): Promise<RE_PositionalData> {
let bodyString = '{\"query\":\"query CCRE{\\n cCREQuery(assembly: \\"GRCh38\\", accession:\\"'+encodeURIComponent(regElemId)+'\\") {\\n coordinates {\\n chromosome\\n start\\n end\\n }\\n }\\n}"}';
const res = await fetch(`https://ga.staging.wenglab.org/graphql`, {
method: 'POST',
headers: {
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Connection': 'keep-alive',
'DNT': '1',
'Origin': 'https://ga.staging.wenglab.org'
},
body: bodyString
})
return await res.json()
//positional data from LDH
export const RegulatoryElementPositionC = z.object({
entId: z.string(),
coordinates: z.object({
"chromosome": z.string(),
"start": z.number(),
"end": z.number()
})
})
export type RegulatoryElementPosition = z.infer<typeof RegulatoryElementPositionC>

export const RegulatoryElementSetPositionC = z.array( RegulatoryElementPositionC )
export type RegulatoryElementSetPosition = z.infer<typeof RegulatoryElementSetPositionC>

export async function getRegulatoryElementPosition(reIdentifier: string): Promise<RegulatoryElementPosition>{
const ldhResponse = await myRegElemInfoFromLDH(reIdentifier);
let coordinatesObject: any = null;
if(ldhResponse != null && ldhResponse.data != null && ldhResponse.data.entContent != null){
coordinatesObject = ldhResponse.data.entContent.coordinates
}else{
let wengLabReposne = await getRegElemPositionDataWengLab(reIdentifier);
if(wengLabReposne != null && wengLabReposne.data.cCREQuery[0].coordinates != null){
coordinatesObject = wengLabReposne.data.cCREQuery[0].coordinates;
}
}
let reCoordinatesObj = {
entId: ldhResponse.data.entId,
coordinates: coordinatesObject
};

return reCoordinatesObj;
}

//Unique Regions
export async function getRegulatoryElementsSetPosition(regElemeIdsSet: string[]): Promise<RegulatoryElementSetPosition>{
let reSetCoordinates: RegulatoryElementSetPosition = [];
for(let i in regElemeIdsSet){
let reId = regElemeIdsSet[i];
let coordinatesObjFromLDH = await getRegulatoryElementPosition(reId);
if(coordinatesObjFromLDH == null || coordinatesObjFromLDH.coordinates == null){
continue;
}
reSetCoordinates.push(coordinatesObjFromLDH);
}
return reSetCoordinates;
}

const MyRegulatoryElementC = z.object({
entId: z.string(),
ldhId: z.string(),
entContent: z.object({
coordinates: z.object({
chromosome: z.string(),
end: z.any(),
start: z.any()
})
})
})
export type MyRegulatoryElement = z.infer<typeof MyRegulatoryElementC>

export const MyRegulatoryElementSetInfoC = z.array(
MyRegulatoryElementC
)
export type MyRegulatoryElementSetInfo = z.infer<typeof MyRegulatoryElementSetInfoC>

//Unique Regions
export const RE_UniqueRegionC = z.array(
z.object({
'@id': z.string(),
Expand Down
Loading

0 comments on commit 4da2bfa

Please sign in to comment.