Skip to content

Commit c690ccd

Browse files
committed
Adjusted region search
Fised a bug where regions were not showing in the results improved display of values by adding commas Adjusted gene query to order by name
1 parent c984e47 commit c690ccd

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<head>
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Genome Browser</title>
7+
<title>Test Page</title>
8+
<!-- uncomment this to endable react-scan which helps visulziee component changes/renders-->
89
<!-- <script src="https://unpkg.com/react-scan/dist/auto.global.js"></script> -->
910
</head>
1011

src/components/Autocomplete/Autocomplete.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
geneResultList,
66
getCoordinates,
77
icreResultList,
8+
isDomain,
89
snpResultList,
910
} from "./utils";
1011
import {
@@ -147,7 +148,7 @@ const Search: React.FC<GenomeSearchProps> = ({
147148
...snpResultList(snpData.data.snpAutocompleteQuery, snpLimit || 3)
148149
);
149150
}
150-
if (searchCoordinate && inputValue.toLowerCase().startsWith("chr")) {
151+
if (searchCoordinate && isDomain(inputValue)) {
151152
resultsList.push(...getCoordinates(inputValue, assembly));
152153
}
153154

@@ -199,6 +200,7 @@ const Search: React.FC<GenomeSearchProps> = ({
199200
renderGroup={(params) => renderGroup(params, inputValue)}
200201
noOptionsText={noOptionsText(inputValue, isLoading, results)}
201202
renderOption={renderOptions}
203+
filterOptions={(x) => x}
202204
renderInput={(params) => {
203205
if (slots && slots.input) {
204206
return React.cloneElement(slots.input as React.ReactElement, {
@@ -254,7 +256,7 @@ const Search: React.FC<GenomeSearchProps> = ({
254256
*/
255257
function renderGroup(params: any, inputValue: string) {
256258
// Sort items within each group by title match relevance
257-
const sortedOptions = Array.isArray(params.children)
259+
const sortedOptions = Array.isArray(params.children) && !isDomain(inputValue)
258260
? params.children.sort((a: any, b: any) => {
259261
const aTitle = (
260262
a.props?.children?.props?.children?.[0]?.props?.children || ""
@@ -278,7 +280,7 @@ function renderGroup(params: any, inputValue: string) {
278280
// Alphabetical order for equal relevance
279281
return aTitle.localeCompare(bTitle);
280282
})
281-
: [];
283+
: params.children;
282284

283285
return (
284286
<div key={params.key}>

src/components/Autocomplete/queries.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const GENE_AUTOCOMPLETE_QUERY = `
3636
name_prefix: $name_prefix
3737
limit: $limit
3838
assembly: $assembly
39+
orderby: "name"
3940
) {
4041
id
4142
name

src/components/Autocomplete/utils.ts

+24-21
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,43 @@ import {
1515
*/
1616
export function getCoordinates(input: string, assembly: string): Result[] {
1717
const results: Result[] = [];
18-
input = input.replace(/,/g, '');
18+
input = input.replace(/,/g, "");
1919

20-
if (input.startsWith("chr") && input.length <= 5 && input.length > 3) {
21-
results.push({
22-
title: input.split(":")[0] + `:1-100000`,
23-
domain: {
24-
chromosome: input.split(":")[0],
25-
start: 1,
26-
end: 100000,
27-
},
28-
description: input.split(":")[0] + `:1-100000`,
29-
type: "Coordinate",
30-
});
31-
}
3220
if (input.includes(":") && input.includes("-")) {
3321
const chromosome = input.split(":")[0];
3422
const start = parseInt(input.split(":")[1].split("-")[0]) || 0;
3523
const end = parseInt(input.split(":")[1].split("-")[1]) || start + 1000;
36-
3724
const chrLength = chromosomeLengths[assembly][chromosome];
3825

3926
// Only set coordinates if end is greater than start and within chromosome length
4027
if (end > start && chrLength && end <= chrLength) {
4128
results.push({
42-
title: `${chromosome}:${start}-${end}`,
29+
title: `${chromosome}:${start.toLocaleString()}-${end.toLocaleString()}`,
4330
domain: {
4431
chromosome: chromosome,
4532
start: start,
4633
end: end,
4734
},
48-
description: `${chromosome}:${start}-${end}`,
35+
description: `${chromosome}:${start.toLocaleString()}-${end.toLocaleString()}`,
4936
type: "Coordinate",
5037
});
5138
}
52-
}
53-
if (input.includes("\t")) {
39+
} else if (input.includes("\t")) {
5440
const [chromosome, start, end] = input.split("\t");
5541
const chrLength = chromosomeLengths[assembly][chromosome];
56-
if (parseInt(end) > parseInt(start) && chrLength && parseInt(end) <= chrLength) {
42+
if (
43+
parseInt(end) > parseInt(start) &&
44+
chrLength &&
45+
parseInt(end) <= chrLength
46+
) {
5747
results.push({
58-
title: `${chromosome}:${start}-${end}`,
48+
title: `${chromosome}:${start.toLocaleString()}-${end.toLocaleString()}`,
5949
domain: {
6050
chromosome: chromosome,
6151
start: parseInt(start),
6252
end: parseInt(end),
6353
},
64-
description: `${chromosome}:${start}-${end}`,
54+
description: `${chromosome}:${start.toLocaleString()}-${end.toLocaleString()}`,
6555
type: "Coordinate",
6656
});
6757
}
@@ -202,3 +192,16 @@ const chromosomeLengths: { [key: string]: { [key: string]: number } } = {
202192
chry: 91744698,
203193
},
204194
};
195+
196+
export function isDomain(input: string) {
197+
const hasTabs = input.includes("\t");
198+
const hasHyphens = input.includes("-");
199+
const hasChromosomeNumber = input.length >= 4 && /^\d$/.test(input[3]);
200+
console.log(
201+
input,
202+
hasTabs || hasHyphens || (input.startsWith("chr") && hasChromosomeNumber)
203+
);
204+
return (
205+
(hasTabs || hasHyphens) && input.startsWith("chr") && hasChromosomeNumber
206+
);
207+
}

src/test.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ function App() {
1717
assembly="GRCh38"
1818
onSearchSubmit={(r: Result) => console.log(r)}
1919
queries={["Gene", "SNP", "iCRE", "cCRE", "Coordinate"]}
20-
style={{ width: "400px", height: "45px", paddingBottom: "30px" }}
20+
style={{ width: "400px" }}
2121
defaultResults={[]}
22+
geneLimit={5}
2223
/>
2324
</Box>
2425
);

0 commit comments

Comments
 (0)