Skip to content

Commit 6ba9463

Browse files
committed
Remove deprecated SAMRecord.format() and now-dead helpers.
SAMRecord.format() was deprecated in favor of getSAMString() because it didn't guarantee a valid SAM text representation. Now that getSAMString() is the canonical formatter (and is used by toString()), drop format() and the private helpers that supported it: addField, formatTagValue, safeEquals. Also remove the SRALazyRecord.format() override, which existed only because format() bypassed lazy attribute loading; getSAMString() goes through SRALazyRecord.getBinaryAttributes() which already handles lazy loading. And delete a couple of stale commented-out debug prints that referenced format(). BREAKING CHANGE: SAMRecord.format() has been removed. Callers should use SAMRecord.getSAMString() instead.
1 parent 83a0bb2 commit 6ba9463

4 files changed

Lines changed: 0 additions & 88 deletions

File tree

src/main/java/htsjdk/samtools/SAMRecord.java

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,82 +1840,6 @@ public int getAttributesBinarySize() {
18401840
return -1;
18411841
}
18421842

1843-
/**
1844-
*
1845-
* @return String representation of this.
1846-
* @deprecated This method is not guaranteed to return a valid SAM text representation of the SAMRecord.
1847-
* To get standard SAM text representation, {@link SAMRecord#getSAMString}.
1848-
*/
1849-
@Deprecated
1850-
public String format() {
1851-
final StringBuilder buffer = new StringBuilder();
1852-
addField(buffer, getReadName(), null, null);
1853-
addField(buffer, getFlags(), null, null);
1854-
addField(buffer, getReferenceName(), null, "*");
1855-
addField(buffer, getAlignmentStart(), 0, "*");
1856-
addField(buffer, getMappingQuality(), 0, "0");
1857-
addField(buffer, getCigarString(), null, "*");
1858-
addField(buffer, getMateReferenceName(), null, "*");
1859-
addField(buffer, getMateAlignmentStart(), 0, "*");
1860-
addField(buffer, getInferredInsertSize(), 0, "*");
1861-
addField(buffer, getReadString(), null, "*");
1862-
addField(buffer, getBaseQualityString(), null, "*");
1863-
if (mAttributes != null) {
1864-
SAMBinaryTagAndValue entry = getBinaryAttributes();
1865-
while (entry != null) {
1866-
addField(buffer, formatTagValue(entry.tag, entry.value));
1867-
entry = entry.getNext();
1868-
}
1869-
}
1870-
return buffer.toString();
1871-
}
1872-
1873-
private void addField(final StringBuilder buffer, final Object value, final Object defaultValue, final String defaultString) {
1874-
if (safeEquals(value, defaultValue)) {
1875-
addField(buffer, defaultString);
1876-
} else if (value == null) {
1877-
addField(buffer, "");
1878-
} else {
1879-
addField(buffer, value.toString());
1880-
}
1881-
}
1882-
1883-
private void addField(final StringBuilder buffer, final String field) {
1884-
if (buffer.length() > 0) {
1885-
buffer.append('\t');
1886-
}
1887-
buffer.append(field);
1888-
}
1889-
1890-
private static String formatTagValue(final short tag, final Object value) {
1891-
final String tagString = SAMTag.makeStringTag(tag);
1892-
if (value == null || value instanceof String) {
1893-
return tagString + ":Z:" + value;
1894-
} else if (value instanceof Integer || value instanceof Long ||
1895-
value instanceof Short || value instanceof Byte) {
1896-
return tagString + ":i:" + value;
1897-
} else if (value instanceof Character) {
1898-
return tagString + ":A:" + value;
1899-
} else if (value instanceof Float) {
1900-
return tagString + ":f:" + value;
1901-
} else if (value instanceof byte[]) {
1902-
return tagString + ":H:" + StringUtil.bytesToHexString((byte[]) value);
1903-
} else {
1904-
throw new RuntimeException("Unexpected value type for tag " + tagString +
1905-
": " + value + " of class " + value.getClass().getName());
1906-
}
1907-
}
1908-
1909-
private boolean safeEquals(final Object o1, final Object o2) {
1910-
if (o1 == o2) {
1911-
return true;
1912-
} else if (o1 == null || o2 == null) {
1913-
return false;
1914-
} else {
1915-
return o1.equals(o2);
1916-
}
1917-
}
1918-
19191843
/**
19201844
* Force all lazily-initialized data members to be initialized. If a subclass overrides this method,
19211845
* typically it should also call super method.

src/main/java/htsjdk/samtools/sra/SRALazyRecord.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -725,14 +725,6 @@ public Object clone() throws CloneNotSupportedException {
725725
return newObject;
726726
}
727727

728-
@Override
729-
public String format() {
730-
if (!initializedAttributes.contains(LazyAttribute.RG)) {
731-
getAttribute("RG");
732-
}
733-
return super.format();
734-
}
735-
736728
@Override
737729
public List<SAMValidationError> isValid(final boolean firstOnly) {
738730
loadFields();

src/test/java/htsjdk/samtools/BAMFileIndexTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ private int runQueryTest(final File bamFile, final String sequence, final int st
418418
record2 = iter2.next();
419419
count2++;
420420
}
421-
// System.out.println("Iteration:");
422-
// System.out.println(" Record1 = " + ((record1 == null) ? "null" : record1.format()));
423-
// System.out.println(" Record2 = " + ((record2 == null) ? "null" : record2.format()));
424421
if (record1 == null && record2 == null) {
425422
break;
426423
}

src/test/java/htsjdk/samtools/BAMRemoteFileTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ private void runLocalRemoteTest(final URL bamURL, final File bamFile, final Stri
169169
assertTrue(records1.size() > 0);
170170
assertEquals(records1.size(), records2.size());
171171
for (int i = 0; i < records1.size(); i++) {
172-
//System.out.println(records1.get(i).format());
173172
assertEquals(records1.get(i).getSAMString(), records2.get(i).getSAMString());
174173
}
175174
}

0 commit comments

Comments
 (0)