Skip to content

Commit

Permalink
Use url helper to create refget urls in refget api slice (#1116)
Browse files Browse the repository at this point in the history
Instead of generating the url to refget in useRefgetSequenceQuery, call urlHelper.refget to get the prepared url.

This fixes the inconsistency when urlHelper.refget was expecting the start coordinate in the Ensembl coordinate system
(1-based), and automatically translated the coordinate into the 0-based coordinate system used by refget; but
`useRefgetSequenceQuery` was not doing this correction.

As a result, this also fixed an off-by-one error while fetching gene and transcript sequences in genome browser drawer.
  • Loading branch information
azangru authored Apr 16, 2024
1 parent 77eb3f7 commit 70b4ac1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const useGenomicRegionData = (params: {
} = useRefgetSequenceQuery(
{
checksum: regionChecksum ?? '',
start: genomicSliceStart - 1, // translate to 0-based coordinate system that refget uses
start: genomicSliceStart,
end: genomicSliceEnd
},
{
Expand Down Expand Up @@ -270,7 +270,7 @@ const useProteinData = (params: {
} = useRefgetSequenceQuery(
{
checksum: proteinChecksum ?? '',
start: proteinSliceCoordinates.proteinSliceStart - 1, // FIXME: undo the (- 1) after useRefgetSequenceQuery hook is updated to use urlFor.refget
start: proteinSliceCoordinates.proteinSliceStart,
end: proteinSliceCoordinates.proteinSliceEnd
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const useVariantImageData = (params: {
} = useRefgetSequenceQuery(
{
checksum: regionChecksum ?? '',
start: sliceStart - 1, // translate to 0-based coordinate system that refget uses
start: sliceStart,
end: sliceEnd
},
{
Expand Down
22 changes: 4 additions & 18 deletions src/shared/state/api-slices/refgetSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import config from 'config';
import * as urlFor from 'src/shared/helpers/urlHelper';

import restApiSlice from 'src/shared/state/api-slices/restSlice';

Expand All @@ -24,7 +24,7 @@ import { Strand } from 'src/shared/types/core-api/strand';

export type SequenceQueryParams = {
checksum: string;
start?: number;
start?: number; // In Ensembl (1-based) coordinate system!
end?: number;
strand?: Strand;
};
Expand All @@ -33,23 +33,9 @@ const refgetApiSlice = restApiSlice.injectEndpoints({
endpoints: (builder) => ({
refgetSequence: builder.query<string, SequenceQueryParams>({
query: (params) => {
const { checksum, start, end } = params;
const queryParameters = new URLSearchParams();
if (start) {
queryParameters.set('start', `${start}`);
}
if (end) {
queryParameters.set('end', `${end}`);
}

const queryString = [...queryParameters].length
? `?${queryParameters.toString()}`
: '';

// FIXME:
// Use urlFor.refget helper. !!!Remember that urlFor.refget helper accepts start in Ensembl coordinates
const refgetUrl = urlFor.refget(params);
return {
url: `${config.refgetBaseUrl}/sequence/${checksum}${queryString}`,
url: refgetUrl,
responseHandler: 'text'
};
},
Expand Down

0 comments on commit 70b4ac1

Please sign in to comment.