Skip to content

Commit

Permalink
Update SamComparisonMetric.java and SamComparison.java to refactor in…
Browse files Browse the repository at this point in the history
…ts to longs (#1985)

* Update SamComparisonMetric.java to refactor ints to longs

This commit changes integers to longs to prevent possible overflowing of counters in cases such as the forum topic below.

https://gatk.broadinstitute.org/hc/en-us/community/posts/31913243796891-Negative-number-in-the-output-file-of-CompareSAMs
  • Loading branch information
gokalpcelik authored Dec 17, 2024
1 parent 306401a commit 886d5f0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
16 changes: 8 additions & 8 deletions src/main/java/picard/sam/SamComparisonMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@ public class SamComparisonMetric extends MetricBase {
* all records which are mapped in both files with mapping quality at most equal to LOW_MQ_THRESHOLD are counted as matching. If
* running with LENIENT_255_MQ_ALIGNMENT=true, all records which are mapped in both files with mapping quality 255 are counted as matches.
*/
public int MAPPINGS_MATCH;
public long MAPPINGS_MATCH;

/**
* The number of primary records which are mapped in both files but do not meet criteria to be counted in MAPPINGS_MATCH.
*/
public int MAPPINGS_DIFFER;
public long MAPPINGS_DIFFER;

/**
* The number of primary records which are not mapped in either file.
*/
public int UNMAPPED_BOTH;
public long UNMAPPED_BOTH;

/**
* The number of primary records which are mapped in right file and found but not mapped in left file
*/
public int UNMAPPED_LEFT;
public long UNMAPPED_LEFT;

/**
* The number of primary records which are mapped in left file and found but not mapped in right file
*/
public int UNMAPPED_RIGHT;
public long UNMAPPED_RIGHT;

/**
* The number of primary records which are found in right file but not found in left file
*/
public int MISSING_LEFT;
public long MISSING_LEFT;

/**
* The number of primary records which are found in left file but not found in right file
*/
public int MISSING_RIGHT;
public long MISSING_RIGHT;

/**
* The number of primary records for which duplicate markings are different. If running in strict duplicate
Expand All @@ -68,7 +68,7 @@ public class SamComparisonMetric extends MetricBase {
* metric is counted on a per read basis, so a paired end fragment which differs in duplicate marking between the two
* files will increment this metric by 2.
*/
public int DUPLICATE_MARKINGS_DIFFER;
public long DUPLICATE_MARKINGS_DIFFER;

/**
* Whether or not to consider the two input files equal. The two input files are considered equal iff
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/picard/sam/util/SamComparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ private void consumeAll(
}
}

private int countRemaining(final SecondaryOrSupplementarySkippingIterator it) {
int i;
private long countRemaining(final SecondaryOrSupplementarySkippingIterator it) {
long i;
for (i = 0; it.hasCurrent(); ++i) {
it.advance();
}
Expand Down Expand Up @@ -580,35 +580,35 @@ private static void reportDifference(Object o1, Object o2, final String label) {
reportDifference(o1.toString(), o2.toString(), label);
}

public int getMappingsMatch() {
public long getMappingsMatch() {
return comparisonMetric.MAPPINGS_MATCH;
}

public int getUnmappedBoth() {
public long getUnmappedBoth() {
return comparisonMetric.UNMAPPED_BOTH;
}

public int getUnmappedLeft() {
public long getUnmappedLeft() {
return comparisonMetric.UNMAPPED_LEFT;
}

public int getUnmappedRight() {
public long getUnmappedRight() {
return comparisonMetric.UNMAPPED_RIGHT;
}

public int getMappingsDiffer() {
public long getMappingsDiffer() {
return comparisonMetric.MAPPINGS_DIFFER;
}

public int getMissingLeft() {
public long getMissingLeft() {
return comparisonMetric.MISSING_LEFT;
}

public int getMissingRight() {
public long getMissingRight() {
return comparisonMetric.MISSING_RIGHT;
}

public int getDuplicateMarkingsDiffer() {
public long getDuplicateMarkingsDiffer() {
return comparisonMetric.DUPLICATE_MARKINGS_DIFFER;
}

Expand Down
32 changes: 16 additions & 16 deletions src/test/java/picard/sam/util/SamComparisonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public void testSamComparison(
final String f2,
final boolean lenientDup,
final boolean lenientLowMQAlignment,
final int expectedMatch,
final int expectedDiffer,
final int expectedUnmappedBoth,
final int expectedUnmappedLeft,
final int expectedUnmappedRight,
final int expectedMissingLeft,
final int expectedMissingRight,
final int expectedDupDiffer,
final long expectedMatch,
final long expectedDiffer,
final long expectedUnmappedBoth,
final long expectedUnmappedLeft,
final long expectedUnmappedRight,
final long expectedMissingLeft,
final long expectedMissingRight,
final long expectedDupDiffer,
final boolean areEqual) throws IOException
{
// compare forward
Expand All @@ -114,14 +114,14 @@ private void testHelper(
final String f2,
final boolean lenientDup,
final boolean lenientLowMQAlignment,
final int expectedMatch,
final int expectedDiffer,
final int expectedUnmappedBoth,
final int expectedUnmappedLeft,
final int expectedUnmappedRight,
final int expectedMissingLeft,
final int expectedMissingRight,
final int expectedDupDiffer,
final long expectedMatch,
final long expectedDiffer,
final long expectedUnmappedBoth,
final long expectedUnmappedLeft,
final long expectedUnmappedRight,
final long expectedMissingLeft,
final long expectedMissingRight,
final long expectedDupDiffer,
final boolean areEqual) throws IOException
{
try (final SamReader samReader1 = SamReaderFactory.makeDefault().open(new File(TEST_FILES_DIR, f1));
Expand Down

0 comments on commit 886d5f0

Please sign in to comment.