Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow downloading metadata in the sequence detail view #3003

Merged
merged 15 commits into from
Oct 17, 2024
Prev Previous commit
Next Next commit
split up function for clarity and reusability
  • Loading branch information
fhennig committed Oct 17, 2024
commit ed3b69507a68206453daaa37729c3ddf452dcbc2
20 changes: 2 additions & 18 deletions website/src/pages/seq/[accessionVersion].fa/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { APIRoute } from 'astro';
import { getReferenceGenomes } from '../../../config.ts';
import { routes } from '../../../routes/routes.ts';
import { LapisClient } from '../../../services/lapisClient.ts';
import { fastaEntryToString, parseFasta } from '../../../utils/parseFasta.ts';
import { createDownloadAPIRoute } from '../sequenceDownload.ts';

export const GET: APIRoute = createDownloadAPIRoute(
Expand All @@ -17,22 +16,7 @@ export const GET: APIRoute = createDownloadAPIRoute(
const isMultiSegmented = segmentNames.length > 1;

return !isMultiSegmented
? lapisClient.getUnalignedSequences(accessionVersion)
: (await lapisClient.getUnalignedSequencesMultiSegment(accessionVersion, segmentNames)).map(
(segmentFastas) =>
segmentFastas
.map((fasta, i) => {
const parsed = parseFasta(fasta);
if (parsed.length === 0) {
return '';
}
const withSegmentSuffix = {
name: `${parsed[0].name}_${segmentNames[i]}`,
sequence: parsed[0].sequence,
};
return fastaEntryToString([withSegmentSuffix]);
})
.join(''),
);
? lapisClient.getSequenceFasta(accessionVersion)
: lapisClient.getMultiSegmentSequenceFasta(accessionVersion, segmentNames);
},
);
2 changes: 1 addition & 1 deletion website/src/pages/seq/sequenceDownload.ts
fhennig marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type DataDownloader = (accessionVersion: string, organism: string) => Pro

/**
* Given a data fetcher function and some information about the data, this will create an API route
theosanderson marked this conversation as resolved.
Show resolved Hide resolved
* That fetches the data.
* that fetches the data.
* @param contentType The content type to use in the HTTP header
* @param fileSuffix the file suffix for this data type (i.e. 'fa' or 'tsv')
* @param undefinedVersionRedirectUrl In case the accessionVersion has no version and it needs to be determined
Expand Down
29 changes: 28 additions & 1 deletion website/src/services/lapisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
type SequenceEntryHistory,
versionStatuses,
} from '../types/lapis.ts';
import { fastaEntryToString, parseFasta } from '../utils/parseFasta.ts';
import type { BaseType } from '../utils/sequenceTypeHelpers.ts';

export class LapisClient extends ZodiosWrapperClient<typeof lapisApi> {
Expand Down Expand Up @@ -53,7 +54,7 @@ export class LapisClient extends ZodiosWrapperClient<typeof lapisApi> {
});
}

public getSequenceEntryVersionDetailsTsv(accessionVersion: string) {
public getSequenceEntryVersionDetailsTsv(accessionVersion: string): Promise<Result<string, ProblemDetail>> {
return this.call('details', {
[this.schema.primaryKey]: accessionVersion,
dataFormat: 'TSV',
Expand Down Expand Up @@ -165,4 +166,30 @@ export class LapisClient extends ZodiosWrapperClient<typeof lapisApi> {
);
return Result.combine(results);
}

public getSequenceFasta(accessionVersion: string): Promise<Result<string, ProblemDetail>> {
return this.getUnalignedSequences(accessionVersion);
}

public async getMultiSegmentSequenceFasta(
accessionVersion: string,
segmentNames: string[],
): Promise<Result<string, ProblemDetail>> {
const segments = await this.getUnalignedSequencesMultiSegment(accessionVersion, segmentNames);
return segments.map((segmentFastas) =>
segmentFastas
.map((fasta, i) => {
const parsed = parseFasta(fasta);
if (parsed.length === 0) {
return '';
}
const withSegmentSuffix = {
name: `${parsed[0].name}_${segmentNames[i]}`,
sequence: parsed[0].sequence,
};
return fastaEntryToString([withSegmentSuffix]);
})
.join(''),
);
}
}