From 53bf816436cd128455a8733190b976842cdc852f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacobo=20Coll=20Morag=C3=B3n?= Date: Mon, 9 Sep 2024 22:54:35 +0100 Subject: [PATCH] storage: Fix junit tests. #TASK-6765 --- .../sample/SampleIndexVariantBiConverter.java | 18 ++++++------------ .../mr/VariantLocalConflictResolverTest.java | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/main/java/org/opencb/opencga/storage/hadoop/variant/index/sample/SampleIndexVariantBiConverter.java b/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/main/java/org/opencb/opencga/storage/hadoop/variant/index/sample/SampleIndexVariantBiConverter.java index d354900fa06..b3a41a9b3b8 100644 --- a/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/main/java/org/opencb/opencga/storage/hadoop/variant/index/sample/SampleIndexVariantBiConverter.java +++ b/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/main/java/org/opencb/opencga/storage/hadoop/variant/index/sample/SampleIndexVariantBiConverter.java @@ -118,17 +118,15 @@ protected int toBytes(int relativeStart, String reference, String alternate, byt } public Variant toVariant(String chromosome, int batchStart, byte[] bytes) { - return toVariant(chromosome, batchStart, bytes, 0, bytes.length); + return toVariant(chromosome, batchStart, bytes, 0); } - public Variant toVariant(String chromosome, int batchStart, byte[] bytes, int offset, int length) { + public Variant toVariant(String chromosome, int batchStart, byte[] bytes, int offset) { if (hasEncodedAlleles(bytes, offset)) { return toVariantEncodedAlleles(chromosome, batchStart, bytes, offset); } else { - int currentOffset = INT24_LENGTH; - int referenceLength = readNextSeparator(bytes, offset + currentOffset, length - currentOffset); - currentOffset += referenceLength + SEPARATOR_LENGTH; - int alternateLength = readNextSeparator(bytes, offset + currentOffset, length - currentOffset); + int referenceLength = readNextSeparator(bytes, offset + INT24_LENGTH); + int alternateLength = readNextSeparator(bytes, offset + INT24_LENGTH + referenceLength + SEPARATOR_LENGTH); return toVariant(chromosome, batchStart, bytes, offset, referenceLength, alternateLength); } } @@ -704,16 +702,12 @@ private Variant toVariant(String chromosome, int batchStart, byte[] bytes, int o } private int readNextSeparator(byte[] bytes, int offset) { - return readNextSeparator(bytes, offset, bytes.length - offset); - } - - private int readNextSeparator(byte[] bytes, int offset, int length) { - for (int i = offset; i < (offset + length); i++) { + for (int i = offset; i < bytes.length; i++) { if (bytes[i] == 0) { return i - offset; } } - return length - offset; + return bytes.length - offset; } protected int getRelativeStart(Variant variant) { diff --git a/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/test/java/org/opencb/opencga/storage/hadoop/variant/archive/mr/VariantLocalConflictResolverTest.java b/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/test/java/org/opencb/opencga/storage/hadoop/variant/archive/mr/VariantLocalConflictResolverTest.java index f716adb0110..a450c22c929 100644 --- a/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/test/java/org/opencb/opencga/storage/hadoop/variant/archive/mr/VariantLocalConflictResolverTest.java +++ b/opencga-storage/opencga-storage-hadoop/opencga-storage-hadoop-core/src/test/java/org/opencb/opencga/storage/hadoop/variant/archive/mr/VariantLocalConflictResolverTest.java @@ -169,7 +169,7 @@ public void resolveConflictIndelCase1() throws Exception { se.setSampleDataKeys(Arrays.asList(GENOTYPE_KEY, GENOTYPE_FILTER_KEY)); se.setSamplesPosition(asMap("S1", 0)); se.addSampleData("S1", Arrays.asList("1/2", "LowGQXHetDel")); - se.getSecondaryAlternates().add(new AlternateCoordinate(null, null, 328, "CTT", "CTTTC", INDEL)); + se.getSecondaryAlternates().add(new AlternateCoordinate(null, 328, 330, "CTT", "CTTTC", INDEL)); addAttribute(v1, FILTER, "LowGQXHetDel");