diff --git a/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/query/VariantQueryUtils.java b/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/query/VariantQueryUtils.java index b4e2e7819d3..f8c361be415 100644 --- a/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/query/VariantQueryUtils.java +++ b/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/query/VariantQueryUtils.java @@ -1542,6 +1542,13 @@ public static String printQuery(Query query) { query.put(ANNOT_GENE_REGIONS.key(), "numGeneRegions : " + ((Collection) geneRegions).size()); } } + if (isValidParam(query, ID_INTERSECT)) { + query = new Query(query); + Object idIntersect = query.get(ID_INTERSECT.key()); + if (idIntersect instanceof Collection) { + query.put(ID_INTERSECT.key(), "numIdIntersect : " + ((Collection) idIntersect).size()); + } + } try { return QUERY_MAPPER.writeValueAsString(query); } catch (JsonProcessingException e) { diff --git a/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/query/projection/VariantQueryProjectionParser.java b/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/query/projection/VariantQueryProjectionParser.java index 90fe6464641..3ec0c32c08a 100644 --- a/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/query/projection/VariantQueryProjectionParser.java +++ b/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/variant/query/projection/VariantQueryProjectionParser.java @@ -137,13 +137,15 @@ public VariantQueryProjection parseVariantQueryProjection(Query query, QueryOpti for (CohortMetadata cohort : metadataManager.getCalculatedOrInvalidCohorts(studyId)) { cohorts.add(cohort.getId()); if (cohort.isInvalid()) { - String message = "Cohort '" + cohort.getName() + "' has outdated variant stats."; + String message = "Please note that the Cohort Stats for " + + "'" + study.getName() + ":" + cohort.getName() + "' are currently outdated."; int numSampmles = cohort.getSamples().size(); int invalidStatsNumSamples = cohort.getAttributes().getInt(CohortMetadata.INVALID_STATS_NUM_SAMPLES, -1); if (invalidStatsNumSamples > 0) { - message += " Existing stats are calculated with " + invalidStatsNumSamples + " samples, " - + "but the cohort currently has " + numSampmles + " samples."; + message += " The statistics have been calculated with " + invalidStatsNumSamples + " samples, " + + "while the total number of samples in the cohort is " + numSampmles + "."; } + message += " To display updated statistics, please execute variant-stats-index."; events.add(new Event(Event.Type.WARNING, message)); } } diff --git a/opencga-storage/opencga-storage-core/src/test/java/org/opencb/opencga/storage/core/variant/stats/VariantStatisticsManagerTest.java b/opencga-storage/opencga-storage-core/src/test/java/org/opencb/opencga/storage/core/variant/stats/VariantStatisticsManagerTest.java index f9b0faa97f8..baafe7d0ad6 100644 --- a/opencga-storage/opencga-storage-core/src/test/java/org/opencb/opencga/storage/core/variant/stats/VariantStatisticsManagerTest.java +++ b/opencga-storage/opencga-storage-core/src/test/java/org/opencb/opencga/storage/core/variant/stats/VariantStatisticsManagerTest.java @@ -146,7 +146,9 @@ public void queryInvalidStats() throws Exception { VariantQueryResult result = variantStorageEngine.get(new Query(), new QueryOptions(QueryOptions.LIMIT, 1)); assertEquals(1, result.getEvents().size()); - assertEquals("Cohort 'cohort2' has outdated variant stats", result.getEvents().get(0).getMessage()); + assertEquals("Please note that the Cohort Stats for '1000g:cohort2' are currently outdated." + + " The statistics have been calculated with 2 samples, while the total number of samples in the cohort is 4." + + " To display updated statistics, please execute variant-stats-index.", result.getEvents().get(0).getMessage()); } @Test diff --git a/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/main/java/org/opencb/opencga/storage/hadoop/variant/adaptors/phoenix/VariantSqlQueryParser.java b/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/main/java/org/opencb/opencga/storage/hadoop/variant/adaptors/phoenix/VariantSqlQueryParser.java index 7750583e0b8..7cc9dd77bf4 100644 --- a/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/main/java/org/opencb/opencga/storage/hadoop/variant/adaptors/phoenix/VariantSqlQueryParser.java +++ b/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/main/java/org/opencb/opencga/storage/hadoop/variant/adaptors/phoenix/VariantSqlQueryParser.java @@ -974,7 +974,8 @@ protected void addVariantFilters(ParsedVariantQuery variantQuery, QueryOptions o sampleFiles.addAll(fileIdsFromSampleId); } else { for (Pair fileIdPair : fileIds) { - if (fileIdPair.getKey().equals(studyId)) { + if (fileIdPair.getKey().equals(studyId) + && sampleMetadata.getFiles().contains(fileIdPair.getValue())) { sampleFiles.add(fileIdPair.getValue()); } } @@ -1231,27 +1232,24 @@ private void addSampleDataFilter(ParsedVariantQuery query, List filters, SampleMetadata sampleMetadata = sampleDataFilter.getKey(); boolean multiFileSample = VariantStorageEngine.SplitData.MULTI.equals(sampleMetadata.getSplitData()); + // First file does not have the fileID in the column name + Integer firstSampleFile = sampleMetadata.getFiles().get(0); List sampleFiles = new ArrayList<>(); if (multiFileSample) { if (fileIds.isEmpty()) { - sampleFiles.add(null); // First file does not have the fileID in the column name List fileIdsFromSampleId = sampleMetadata.getFiles(); - sampleFiles.addAll(fileIdsFromSampleId.subList(1, fileIdsFromSampleId.size())); + sampleFiles.addAll(fileIdsFromSampleId); } else { for (Pair fileIdPair : fileIds) { - if (fileIdPair.getKey().equals(sampleMetadata.getStudyId())) { - Integer fileId = fileIdPair.getValue(); - int idx = sampleMetadata.getFiles().indexOf(fileId); - if (idx == 0) { - sampleFiles.add(null); // First file does not have the fileID in the column name - } else if (idx > 0) { - sampleFiles.add(fileId); // First file does not have the fileID in the column name - } + if (fileIdPair.getKey().equals(sampleMetadata.getStudyId()) + && sampleMetadata.getFiles().contains(fileIdPair.getValue())) { + sampleFiles.add(fileIdPair.getValue()); } } } } else { - sampleFiles.add(null); // First file does not have the fileID in the column name + // Non multi file sample + sampleFiles.add(firstSampleFile); } for (Integer sampleFile : sampleFiles) { List sampleFileFilters = new LinkedList<>(); @@ -1271,10 +1269,11 @@ private void addSampleDataFilter(ParsedVariantQuery query, List filters, sb.append("TO_NUMBER("); } sb.append('"'); - if (sampleFile != null) { - buildSampleColumnKey(sampleMetadata.getStudyId(), sampleMetadata.getId(), sampleFile, sb); - } else { + if (Objects.equals(sampleFile, firstSampleFile)) { + // Special scenario for the first file. Column name does not contain the fileId buildSampleColumnKey(sampleMetadata.getStudyId(), sampleMetadata.getId(), sb); + } else { + buildSampleColumnKey(sampleMetadata.getStudyId(), sampleMetadata.getId(), sampleFile, sb); } sb.append('"'); @@ -1288,10 +1287,11 @@ private void addSampleDataFilter(ParsedVariantQuery query, List filters, if (op.startsWith(">>") || op.startsWith("<<")) { sb.append(" OR \""); - if (sampleFile != null) { - buildSampleColumnKey(sampleMetadata.getStudyId(), sampleMetadata.getId(), sampleFile, sb); - } else { + if (Objects.equals(sampleFile, firstSampleFile)) { + // Special scenario for the first file. Column name does not contain the fileId buildSampleColumnKey(sampleMetadata.getStudyId(), sampleMetadata.getId(), sb); + } else { + buildSampleColumnKey(sampleMetadata.getStudyId(), sampleMetadata.getId(), sampleFile, sb); } sb.append('"'); @@ -1308,8 +1308,8 @@ private void addSampleDataFilter(ParsedVariantQuery query, List filters, if (multiFileSample) { // The first file is null. Get the actual fileId Integer actualFileId; - if (sampleFile == null) { - actualFileId = sampleMetadata.getFiles().get(0); + if (Objects.equals(sampleFile, firstSampleFile)) { + actualFileId = firstSampleFile; } else { actualFileId = sampleFile; } diff --git a/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/test/java/org/opencb/opencga/storage/hadoop/variant/index/sample/SampleIndexTest.java b/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/test/java/org/opencb/opencga/storage/hadoop/variant/index/sample/SampleIndexTest.java index 1ee4944733e..e15cb6ae4bb 100644 --- a/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/test/java/org/opencb/opencga/storage/hadoop/variant/index/sample/SampleIndexTest.java +++ b/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/test/java/org/opencb/opencga/storage/hadoop/variant/index/sample/SampleIndexTest.java @@ -369,8 +369,8 @@ public void regenerateSampleIndex() throws Exception { } public VariantQueryResult dbAdaptorQuery(Query query, QueryOptions options) { - query = variantStorageEngine.preProcessQuery(query, options); - return dbAdaptor.get(query, options); + ParsedVariantQuery variantQuery = variantStorageEngine.parseQuery(query, options); + return dbAdaptor.get(variantQuery); } @Test