Skip to content

Commit

Permalink
resolving circular classloading issue and removing uses of constants …
Browse files Browse the repository at this point in the history
…in SamTagUtil
  • Loading branch information
lbergelson committed Nov 14, 2018
1 parent cf7d601 commit ef75df4
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/main/java/htsjdk/samtools/BAMRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static boolean isSentinelCigar(final Cigar cigar, final int readLength) {
* extracts the CIGAR from the CG tag and places it into the (in memory) cigar.
*/
private void extractCigarFromCGAttribute(final Cigar sentinelCigar) throws IllegalStateException {
final int[] cigarFromCG = (int[]) getAttribute(SAMTagUtil.CG);
final int[] cigarFromCG = (int[]) getAttribute(SAMTag.CG.getBinaryTag());

if (cigarFromCG == null) return;

Expand Down Expand Up @@ -353,7 +353,7 @@ private void extractCigarFromCGAttribute(final Cigar sentinelCigar) throws Illeg
initializeCigar(decodedCigar);

// remove CG attribute.
setAttribute(SAMTagUtil.CG, null);
setAttribute(SAMTag.CG.getBinaryTag(), null);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/htsjdk/samtools/SAMRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ protected void initializeCigar(final Cigar cigar) {
* @throws ClassCastException if RG tag does not have a String value.
*/
public SAMReadGroupRecord getReadGroup() {
final String rgId = (String)getAttribute(SAMTagUtil.RG);
final String rgId = (String)getAttribute(SAMTag.RG.getBinaryTag());
if (rgId == null || getHeader() == null) {
return null;
} else {
Expand Down Expand Up @@ -2063,7 +2063,7 @@ public List<SAMValidationError> isValid(final boolean firstOnly) {
*/
}
// Validate the RG ID is found in header
final String rgId = (String)getAttribute(SAMTagUtil.RG);
final String rgId = (String)getAttribute(SAMTag.RG.getBinaryTag());
if (rgId != null && getHeader() != null && getHeader().getReadGroup(rgId) == null) {
if (ret == null) ret = new ArrayList<>();
ret.add(new SAMValidationError(SAMValidationError.Type.READ_GROUP_NOT_FOUND,
Expand All @@ -2078,10 +2078,10 @@ public List<SAMValidationError> isValid(final boolean firstOnly) {
}
// TODO(mccowan): Is this asking "is this the primary alignment"?
if (this.getReadLength() == 0 && !this.isSecondaryAlignment()) {
final Object fz = getAttribute(SAMTagUtil.FZ);
final Object fz = getAttribute(SAMTag.FZ.getBinaryTag());
if (fz == null) {
final String cq = (String)getAttribute(SAMTagUtil.CQ);
final String cs = (String)getAttribute(SAMTagUtil.CS);
final String cq = (String)getAttribute(SAMTag.CQ.getBinaryTag());
final String cs = (String)getAttribute(SAMTag.CS.getBinaryTag());
if (cq == null || cq.isEmpty() || cs == null || cs.isEmpty()) {
if (ret == null) ret = new ArrayList<>();
ret.add(new SAMValidationError(SAMValidationError.Type.EMPTY_READ,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/htsjdk/samtools/SAMRecordSetBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void setHeader(final SAMFileHeader header) {
*/
public void addRecord(final SAMRecord record) {
if (record.getReadPairedFlag() && !record.getMateUnmappedFlag() &&
null == record.getAttribute(SAMTagUtil.MC)) {
null == record.getAttribute(SAMTag.MC.getBinaryTag())) {
throw new SAMException("Mate Cigar tag (MC) not found in: " + record.getReadName());
}
this.records.add(record);
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/htsjdk/samtools/SAMTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,20 @@ public enum SAMTag {
U2,
UQ;

private final short shortValue = SAMTagUtil.makeBinaryTag(this.name());
private final short shortValue = SAMTag.makeBinaryTag(this.name());;

/**
* Convert from String representation of tag name to short representation.
*
* @param tag 2-character String representation of a tag name.
* @return Tag name packed as 2 ASCII bytes in a short.
*/
static short makeBinaryTag(String tag) {
if (tag.length() != 2) {
throw new IllegalArgumentException("String tag does not have length() == 2: " + tag);
}
return (short)(tag.charAt(1) << 8 | tag.charAt(0));
}

/**
* Get the binary representation of this tag name.
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/htsjdk/samtools/SAMTagUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ public static SAMTagUtil getSingleton() {
* @return Tag name packed as 2 ASCII bytes in a short.
*/
public static short makeBinaryTag(final String tag) {
if (tag.length() != 2) {
throw new IllegalArgumentException("String tag does not have length() == 2: " + tag);
}
return (short)(tag.charAt(1) << 8 | tag.charAt(0));
return SAMTag.makeBinaryTag(tag);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/htsjdk/samtools/SAMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ public static List<SAMRecord> getOtherCanonicalAlignments(final SAMRecord record
if (record == null) throw new IllegalArgumentException("record is null");
if (record.getHeader() == null) throw new IllegalArgumentException("record.getHeader() is null");
/* extract value of SA tag */
final Object saValue = record.getAttribute(SAMTagUtil.SA);
final Object saValue = record.getAttribute(SAMTag.SA.getBinaryTag());
if (saValue == null) return Collections.emptyList();
if (!(saValue instanceof String)) throw new SAMException(
"Expected a String for attribute 'SA' but got " + saValue.getClass() + ". Record: " + record);
Expand Down Expand Up @@ -1220,7 +1220,7 @@ public static List<SAMRecord> getOtherCanonicalAlignments(final SAMRecord record
/* fill NM */
try {
if (!commaStrs[5].equals("*")) {
otherRec.setAttribute(SAMTagUtil.NM, Integer.parseInt(commaStrs[5]));
otherRec.setAttribute(SAMTag.NM.getBinaryTag(), Integer.parseInt(commaStrs[5]));
}
} catch (final NumberFormatException err) {
throw new SAMException("bad NM in " + semiColonStr + ". Record: " + record, err);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/htsjdk/samtools/SamFileValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private void validateTags(final SAMRecord record, final long recordNumber) {
addError(new SAMValidationError(Type.CG_TAG_FOUND_IN_ATTRIBUTES,
"The CG Tag should only be used in BAM format to hold a large cigar. " +
"It was found containing the value: " +
record.getAttribute(SAMTagUtil.CG), record.getReadName(), recordNumber));
record.getAttribute(SAMTag.CG.getBinaryTag()), record.getReadName(), recordNumber));
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/main/java/htsjdk/samtools/sra/SRALazyRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@
package htsjdk.samtools.sra;

import gov.nih.nlm.ncbi.ngs.NGS;
import htsjdk.samtools.SAMRecord;
import htsjdk.samtools.SAMTagUtil;
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.Cigar;
import htsjdk.samtools.SAMBinaryTagAndValue;
import htsjdk.samtools.SAMUtils;
import htsjdk.samtools.SAMValidationError;
import htsjdk.samtools.*;
import htsjdk.samtools.util.Log;
import ngs.ReadCollection;
import ngs.AlignmentIterator;
Expand Down Expand Up @@ -210,7 +204,7 @@ public String getAttribute(SRALazyRecord self) {
static
{
lazyAttributeTags = new HashMap<Short, LazyAttribute>();
lazyAttributeTags.put(SAMTagUtil.RG, LazyAttribute.RG);
lazyAttributeTags.put(SAMTag.RG.getBinaryTag(), LazyAttribute.RG);
}

public SRALazyRecord(final SAMFileHeader header, SRAAccession accession, ReadCollection run, AlignmentIterator alignmentIterator, String readId, String alignmentId) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/htsjdk/samtools/SAMUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void testOtherCanonicalAlignments() {
Assert.assertEquals(SAMUtils.getOtherCanonicalAlignments(record).size(),0);


record.setAttribute(SAMTagUtil.SA,
record.setAttribute(SAMTag.SA.getBinaryTag(),
"2,500,+,3S2=1X2=2S,60,1;" +
"1,191,-,8M2S,60,*;");

Expand Down Expand Up @@ -233,7 +233,7 @@ public void testOtherCanonicalAlignments() {
Assert.assertEquals(other.getAlignmentStart(),500);
Assert.assertFalse(other.getReadNegativeStrandFlag());
Assert.assertEquals(other.getMappingQuality(), 60);
Assert.assertEquals(other.getAttribute(SAMTagUtil.NM),1);
Assert.assertEquals(other.getAttribute(SAMTag.NM.getBinaryTag()),1);
Assert.assertEquals(other.getCigarString(),"3S2=1X2=2S");
Assert.assertEquals(other.getInferredInsertSize(),0);

Expand All @@ -244,7 +244,7 @@ public void testOtherCanonicalAlignments() {
Assert.assertEquals(other.getAlignmentStart(),191);
Assert.assertTrue(other.getReadNegativeStrandFlag());
Assert.assertEquals(other.getMappingQuality(), 60);
Assert.assertEquals(other.getAttribute(SAMTagUtil.NM),null);
Assert.assertEquals(other.getAttribute(SAMTag.NM.getBinaryTag()),null);
Assert.assertEquals(other.getCigarString(),"8M2S");
Assert.assertEquals(other.getInferredInsertSize(),-91);//100(mate) - 191(other)
}
Expand Down

0 comments on commit ef75df4

Please sign in to comment.