Skip to content

Commit

Permalink
update list of available samples from filtered query result
Browse files Browse the repository at this point in the history
part of #484.
manage-genotype.js :
  samples() : if .filterSamplesByHaplotype, return this.sampleCache.filteredByGenotype[this.lookupDatasetId] i.e. the dataset samples filtered by the most recent selected SNPs + genotype, i.e. allele / haplotype.  Add dependencies for that value.
  vcfGenotypeSamplesDataset() : if ! urlOptions.filterSelectedSamples, don't filter the selected samples.   Update .sampleCache.filteredByGenotype{,Count}.

vcf-genotype.js : (sampleCache) : add filteredByGenotype{,Count} : caches the result of vcfGenotypeSamplesDataset() when filterByHaplotype.  -Count is an efficient update dependency.
vcfGenotypeLookup.bash : bcftoolsCommand() : grep returns status 1 if there are no matches.  Ignore that and return 0 (true).  Also match end-of-line; matching either eol or tab is sufficient.
  • Loading branch information
Don-Isdale committed Feb 25, 2025
1 parent 46c97c3 commit 61c2af0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
33 changes: 27 additions & 6 deletions frontend/app/components/panel/manage-genotype.js
Original file line number Diff line number Diff line change
Expand Up @@ -1534,11 +1534,19 @@ export default class PanelManageGenotypeComponent extends Component {
'vcfGenotypeSamplesText',
'args.userSettings.samplesIntersection',
'sampleNameFilter',
/** These 4 dependencies relate to filterSamplesByHaplotype;
* possibly split this out as a separate CP samplesFilteredByHaplotype */
'args.userSettings.filterSamplesByHaplotype',
'snpsInBrushedDomain.length',
/** update when new results in sampleCache.filteredByGenotype */
'sampleCache.filteredByGenotypeCount',
'lookupDatasetId',
)
get samples() {
const
samples = this.args.userSettings.samplesIntersection ?
this.sampleNamesIntersection :
this.args.userSettings.filterSamplesByHaplotype ? this.sampleCache.filteredByGenotype[this.lookupDatasetId] :
this.samplesFromText(this.vcfGenotypeSamplesText);
return samples;
}
Expand Down Expand Up @@ -2100,12 +2108,25 @@ export default class PanelManageGenotypeComponent extends Component {
if (! filterByHaplotype) {
this.sampleCache.sampleNames[vcfDatasetId] = sampleNamesText;
this.datasetStoreSampleNames(vcfBlock, sampleNames);
} else if (this.selectedSamplesText) {
this.selectedSamples = this.selectedSamplesText
.split('\n')
.filter(sample => sampleNames.includes(sample));
this.selectedSamplesText = this.selectedSamples
.join('\n');
} else {
/** If filterSelectedSamples, this case filters the selected samples
* (.selectedSamples and .selectedSamplesText) to exclude samples
* not in the query result sampleNames. This seems to make sense
* and be ergononomic, but it probably depends on use case - perhaps
* users will want to hang on to selected samples which are filtered
* out but are of interest for them. Not filtering here would
* enable them to collate the union of a series of queries.
*/
if (this.selectedSamplesText && this.urlOptions.filterSelectedSamples) {
this.selectedSamples = this.selectedSamplesText
.split('\n')
.filter(sample => sampleNames.includes(sample));
this.selectedSamplesText = this.selectedSamples
.join('\n');
}
/** The list of available samples is filtered. */
this.sampleCache.filteredByGenotype[this.lookupDatasetId] = sampleNames;
this.sampleCache.incrementProperty('filteredByGenotypeCount');
}
this.mapSamplesToBlock(sampleNames, vcfBlock);
if ((vcfDatasetId === this.lookupDatasetId) &&
Expand Down
8 changes: 8 additions & 0 deletions frontend/app/services/data/vcf-genotype.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export default class DataVcfGenotypeService extends Service {

//----------------------------------------------------------------------------

/** Arrays of sample names, per dataset. indexed by VCF datasetId
* This caches the result of vcfGenotypeSamplesDataset() when filterByHaplotype.
*/
filteredByGenotype = {};
filteredByGenotypeCount = 0;

//----------------------------------------------------------------------------

/** Count of dataset.enableFeatureFilters true/false values.
* Used as a dependency, so the change of value matters rather than the absolute value.
* Related : enableFeatureFiltersSymbol
Expand Down
3 changes: 2 additions & 1 deletion lb4app/lb3app/scripts/vcfGenotypeLookup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ function bcftoolsCommand() {
then
2>&$F_ERR "$bcftools" query "$vcfGz" "${regionParams[@]}" "${preArgs[@]}" "${paramsForQuery[@]}" "${snpNamesInclude[@]}" \
-f '[%SAMPLE\t%GT\n]' \
| grep $'\t'"$gtMatch"
| (grep $'\t'"$gtMatch"'$' || true)
# grep returns status 1 if there are no matches. Ignore that and return 0 (true).
else
>> $serverDir/$logFile echo \#vcfGz ${#vcfGz}
# Perhaps this check should be on ${#vcfGzs[@]}, but that is equal - seems it must be 0 at this point ?
Expand Down

0 comments on commit 61c2af0

Please sign in to comment.