Skip to content

Commit 4b6035c

Browse files
authored
Linked genes filter (#186)
* Add support for distance linked params * Formatting, remove snp buffer * Infrastructure for linked genes filter * Working all but without slider * Add support for multiple genes, cleanup * Fix build error, cleanup * Cleanup
1 parent ae846d5 commit 4b6035c

File tree

11 files changed

+8699
-5957
lines changed

11 files changed

+8699
-5957
lines changed

screen2.0/src/app/about/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export default function About() {
213213
cell and tissue types are displayed here for each study.
214214
</Typography>
215215
</Grid2>
216-
{/* <Grid2 xs={12} id="tutorials">
216+
<Grid2 xs={12} id="tutorials">
217217
<Typography variant="h3">Tutorials</Typography>
218218
</Grid2>
219219
<Grid2 xs={12} id="api-documentation">
@@ -227,7 +227,7 @@ export default function About() {
227227
</Grid2>
228228
<Grid2 xs={12} id="contact-us">
229229
<Typography variant="h3">Contact Us</Typography>
230-
</Grid2> */}
230+
</Grid2>
231231
</Grid2>
232232
</main>
233233
)

screen2.0/src/app/applets/gene-expression/gene-autocomplete.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { gene } from "./types"
77
import { QueryResponse } from "../../../../types/types"
88
import { Dispatch, SetStateAction } from "react"
99
import Config from "../../../config.json"
10-
import { Search } from "@mui/icons-material"
10+
import { Add, Search } from "@mui/icons-material"
1111

1212

1313
const GENE_AUTOCOMPLETE_QUERY = `
@@ -28,6 +28,7 @@ export default function GeneAutoComplete(props: {
2828
assembly: "mm10" | "GRCh38"
2929
gene: string
3030
setGene: Dispatch<SetStateAction<any>>
31+
plusIcon?: boolean
3132
}) {
3233
const router = useRouter()
3334

@@ -173,7 +174,11 @@ export default function GeneAutoComplete(props: {
173174
}}
174175
color="primary"
175176
>
176-
<Search />
177+
{props.plusIcon ?
178+
<Add />
179+
:
180+
<Search />
181+
}
177182
</IconButton>
178183
</Stack>
179184
)

screen2.0/src/app/search/fetchRows.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22

33
import { ApolloQueryResult } from "@apollo/client"
44
import { MainQuery, linkedGenesQuery } from "../../common/lib/queries"
5-
import { passesCriteria } from "./search-helpers"
5+
import { passesCriteria, passesLinkedGenesFilter } from "./search-helpers"
66
import { MainQueryParams, cCREData, MainResultTableRows, MainResultTableRow } from "./types"
77

88
export async function fetchRows(mainQueryParams: MainQueryParams, accessions?: string[]) {
99
//Should be able to send server-side query here
1010
let mainQueryResult: ApolloQueryResult<any>
1111

1212
//This needs to be split up since the query will fail if accessions is passed and is null unlike other fields
13+
//Main Query should probably just be passed the entire mainQueryParams object, no?
1314
if (accessions) {
1415
mainQueryResult = await MainQuery(
1516
mainQueryParams.assembly,
1617
mainQueryParams.chromosome,
1718
mainQueryParams.start,
1819
mainQueryParams.end,
1920
mainQueryParams.Biosample.biosample,
21+
mainQueryParams.distanceFromcCRE,
22+
//This is the limit of distance linked gene
23+
//Default is 3, leaving null for now
24+
//TODO dynamically change this away from 3
25+
null,
2026
accessions
2127
)
2228
} else {
@@ -26,6 +32,8 @@ export async function fetchRows(mainQueryParams: MainQueryParams, accessions?: s
2632
mainQueryParams.start,
2733
mainQueryParams.end,
2834
mainQueryParams.Biosample.biosample,
35+
mainQueryParams.distanceFromcCRE,
36+
null
2937
)
3038
}
3139

@@ -51,8 +59,6 @@ export async function generateRows(QueryResult: ApolloQueryResult<any>, biosampl
5159
start: currentElement.start.toLocaleString("en-US"),
5260
end: (currentElement.start + currentElement.len).toLocaleString("en-US"),
5361
dnase: biosample ? currentElement.ctspecific.dnase_zscore : currentElement.dnase_zscore,
54-
//Need to get this data still from somewhere
55-
5662
h3k4me3: biosample ? currentElement.ctspecific.h3k4me3_zscore : currentElement.promoter_zscore,
5763
h3k27ac: biosample ? currentElement.ctspecific.h3k27ac_zscore : currentElement.enhancer_zscore,
5864
ctcf: biosample ? currentElement.ctspecific.ctcf_zscore : currentElement.ctcf_zscore,
@@ -71,13 +77,14 @@ export async function generateRows(QueryResult: ApolloQueryResult<any>, biosampl
7177

7278
genesToAdd && genesToAdd.genes.forEach(gene => {
7379
if (gene.linkedBy === "CTCF-ChIAPET") {
74-
row.linkedGenes.CTCF_ChIAPET.push({name: gene.geneName, biosample: gene.biosample})
80+
row.linkedGenes.CTCF_ChIAPET.push({ name: gene.geneName, biosample: gene.biosample })
7581
}
76-
else if (gene.linkedBy === "RNAPII-ChIAPET"){
77-
row.linkedGenes.RNAPII_ChIAPET.push({name: gene.geneName, biosample: gene.biosample})
82+
else if (gene.linkedBy === "RNAPII-ChIAPET") {
83+
row.linkedGenes.RNAPII_ChIAPET.push({ name: gene.geneName, biosample: gene.biosample })
7884
}
79-
});
85+
})
8086
})
8187

82-
return rows
88+
//Is there a better way to structure this code?
89+
return rows.filter((row) => passesLinkedGenesFilter(row, mainQueryParams))
8390
}

screen2.0/src/app/search/page.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default async function Search({
1414
//Get search parameters and define defaults.
1515
const mainQueryParams: MainQueryParams = {
1616
//Flag that user-entered accessions are to be used
17-
bed_intersect: searchParams.intersect ? checkTrueFalse(searchParams.intersect): false,
17+
bed_intersect: searchParams.intersect ? checkTrueFalse(searchParams.intersect) : false,
1818
assembly: searchParams.assembly === "GRCh38" || searchParams.assembly === "mm10" ? searchParams.assembly : "GRCh38",
1919
gene: searchParams.gene,
2020
snpid: searchParams.snpid,
@@ -48,7 +48,7 @@ export default async function Search({
4848
h3k27ac_e: searchParams.h3k27ac_e ? Number(searchParams.h3k27ac_e) : 10,
4949
ctcf_s: searchParams.ctcf_s ? Number(searchParams.ctcf_s) : -10,
5050
ctcf_e: searchParams.ctcf_e ? Number(searchParams.ctcf_e) : 10,
51-
51+
5252
atac_s: searchParams.atac_s ? Number(searchParams.atac_s) : -10,
5353
atac_e: searchParams.atac_e ? Number(searchParams.atac_e) : 10,
5454
// Classification Filters
@@ -63,11 +63,18 @@ export default async function Search({
6363
TF: searchParams.TF ? checkTrueFalse(searchParams.TF) : true,
6464
//Conservation Filter
6565
prim_s: searchParams.prim_s ? Number(searchParams.prim_s) : -2,
66-
prim_e:searchParams.prim_e ? Number(searchParams.prim_e) : 2,
66+
prim_e: searchParams.prim_e ? Number(searchParams.prim_e) : 2,
6767
mamm_s: searchParams.mamm_s ? Number(searchParams.mamm_s) : -4,
68-
mamm_e:searchParams.mamm_e ? Number(searchParams.mamm_e) : 8,
68+
mamm_e: searchParams.mamm_e ? Number(searchParams.mamm_e) : 8,
6969
vert_s: searchParams.vert_s ? Number(searchParams.vert_s) : -3,
70-
vert_e:searchParams.vert_e ? Number(searchParams.vert_e) : 8,
70+
vert_e: searchParams.vert_e ? Number(searchParams.vert_e) : 8,
71+
//Linked Genes Filter
72+
genesToFind: searchParams.genesToFind ? searchParams.genesToFind.split(",") : null,
73+
distancePC: searchParams.distancePC ? checkTrueFalse(searchParams.distancePC) : true,
74+
distanceAll: searchParams.distanceAll ? checkTrueFalse(searchParams.distanceAll) : true,
75+
distanceFromcCRE: searchParams.distanceFromcCRE ? Number(searchParams.distanceFromcCRE) : 1000000,
76+
CTCF_ChIA_PET: searchParams.CTCF_ChIA_PET ? checkTrueFalse(searchParams.CTCF_ChIA_PET) : true,
77+
RNAPII_ChIA_PET: searchParams.RNAPII_ChIA_PET ? checkTrueFalse(searchParams.RNAPII_ChIA_PET) : true
7178
}
7279

7380
//Contains cell type data of the specified assembly

screen2.0/src/app/search/search-helpers.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,30 @@ function passesClassificationFilter(currentElement: cCREData, mainQueryParams: M
113113
}
114114
}
115115

116+
export function passesLinkedGenesFilter(row: MainResultTableRow, mainQueryParams: MainQueryParams) {
117+
//If there is a gene to find a match for
118+
let found = false
119+
if (mainQueryParams.genesToFind) {
120+
const genes = row.linkedGenes
121+
//For each selected checkbox, try to find it in the corresponding spot, mark flag as found
122+
if (mainQueryParams.distancePC && genes.distancePC.find((gene) => mainQueryParams.genesToFind.find((x) => x === gene.name))) {
123+
found = true
124+
}
125+
if (mainQueryParams.distanceAll && genes.distanceAll.find((gene) => mainQueryParams.genesToFind.find((x) => x === gene.name))) {
126+
found = true
127+
}
128+
if (mainQueryParams.CTCF_ChIA_PET && genes.CTCF_ChIAPET.find((gene) => mainQueryParams.genesToFind.find((x) => x === gene.name))) {
129+
found = true
130+
}
131+
if (mainQueryParams.RNAPII_ChIA_PET && genes.RNAPII_ChIAPET.find((gene) => mainQueryParams.genesToFind.find((x) => x === gene.name))) {
132+
found = true
133+
}
134+
return found
135+
} else {
136+
return true
137+
}
138+
}
139+
116140
/**
117141
* @param experiments Array of objects containing biosample experiments for a given biosample type
118142
* @returns an object with keys dnase, atac, h3k4me3, h3k27ac, ctcf with each marked true or false
@@ -222,6 +246,7 @@ export function assayHoverInfo(assays: { dnase: boolean; h3k27ac: boolean; h3k4m
222246
*
223247
* @param newBiosample optional, use if setting Biosample State and then immediately triggering router before re-render when the new state is accessible
224248
* @returns A URL configured with filter information
249+
* @todo this function should only take in urlParams, not mainQueryParams (which should be renamed). urlParams is more like filterParams. Also this should not append things to the url unless it changes from the default value
225250
*/
226251
export function constructURL(
227252
mainQueryParams: MainQueryParams,
@@ -268,8 +293,10 @@ export function constructURL(
268293

269294
const conservationFilters = `&prim_s=${urlParams.PrimateStart}&prim_e=${urlParams.PrimateEnd}&mamm_s=${urlParams.MammalStart}&mamm_e=${urlParams.MammalEnd}&vert_s=${urlParams.VertebrateStart}&vert_e=${urlParams.VertebrateEnd}`
270295

296+
const linkedGenesFilter = `&genesToFind=${urlParams.genesToFind.join(',')}&distancePC=${outputT_or_F(urlParams.distancePC)}&distanceAll=${outputT_or_F(urlParams.distanceAll)}&distanceFromcCRE=${urlParams.distanceFromcCRE}&CTCF_ChIA_PET=${outputT_or_F(urlParams.CTCF_ChIA_PET)}&RNAPII_ChIA_PET=${outputT_or_F(urlParams.RNAPII_ChIA_PET)}`
297+
271298
const accessionsAndPage = `&accession=${urlParams.Accessions}&page=${urlParams.Page}`
272299

273-
const url = `${urlBasics}${biosampleFilters}${chromatinFilters}${classificationFilters}${conservationFilters}${accessionsAndPage}`
300+
const url = `${urlBasics}${biosampleFilters}${chromatinFilters}${classificationFilters}${conservationFilters}${urlParams.genesToFind.length > 0 ? linkedGenesFilter : ""}${accessionsAndPage}`
274301
return url
275302
}

screen2.0/src/app/search/types.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type cCREData = {
3434
intersecting_genes: { name: string }[]
3535
}
3636
}
37+
3738
}
3839

3940
export type MainQueryParams = {
@@ -79,6 +80,12 @@ export type MainQueryParams = {
7980
pELS?: boolean
8081
PLS?: boolean
8182
TF?: boolean
83+
genesToFind: string[]
84+
distancePC: boolean
85+
distanceAll: boolean
86+
distanceFromcCRE: number
87+
CTCF_ChIA_PET: boolean
88+
RNAPII_ChIA_PET: boolean
8289
}
8390

8491
export type CellTypeData = {
@@ -129,7 +136,6 @@ export type FilteredBiosampleData = [
129136
export type MainResultTableRows = MainResultTableRow[]
130137

131138
export type MainResultTableRow = {
132-
//atac will need to be changed from string to number when that data is available
133139
accession: string
134140
class: string
135141
chromosome: string
@@ -158,7 +164,7 @@ export type LinkedGenesData = {
158164
}
159165

160166
/**
161-
* Represents the state variables used by the filters and passed to the constructURL function to refresh results
167+
* I guess this is best described as the parameters that can be modified by the filters panel. Strong overlap with mainQueryParams
162168
*/
163169
export type URLParams = {
164170
Tissue: boolean
@@ -198,6 +204,12 @@ export type URLParams = {
198204
MammalEnd: number
199205
VertebrateStart: number
200206
VertebrateEnd: number
207+
genesToFind: string[]
208+
distancePC: boolean
209+
distanceAll: boolean
210+
distanceFromcCRE: number
211+
CTCF_ChIA_PET: boolean
212+
RNAPII_ChIA_PET: boolean
201213
Accessions: string
202214
Page: number
203215
}

0 commit comments

Comments
 (0)