/** * Determines whether a SAMRecord matches this filter * * @param record the SAMRecord to evaluate * @return true if the SAMRecord matches the filter, and should be filtered out, * otherwise false */ @Override public boolean filterOut(final SAMRecord record) { return record.getAttribute(ReservedTagConstants.XT) != null && (Integer)record.getAttribute(ReservedTagConstants.XT) == 1; }
/** * @return {@code true} if the SAM record has the requested attribute set, {@code false} otherwise. */ public boolean hasAttribute(final String tag) { return getAttribute(tag)!=null; }
/** * Determines whether a SAMRecord matches this filter * * @param record the SAMRecord to evaluate * @return true if the SAMRecord matches the filter, and should be filtered out, * otherwise false */ @Override public boolean filterOut(final SAMRecord record) { return record.getAttribute(ReservedTagConstants.XT) != null && (Integer)record.getAttribute(ReservedTagConstants.XT) == 1; }
/** * Determines whether a SAMRecord matches this filter * * @param record the SAMRecord to evaluate * @return the XOR of SAMRecord matches the filter and includeReads. */ @Override public boolean filterOut(SAMRecord record) { return values.contains(record.getAttribute(tag)) != includeReads; }
/** * Get the value for a SAM tag. * WARNING: Some value types (e.g. byte[]) are mutable. It is dangerous to change one of these values in * place, because some SAMRecord implementations keep track of when attributes have been changed. If you * want to change an attribute value, call setAttribute() to replace the value. * * @param tag Two-character tag name. * @return Appropriately typed tag value, or null if the requested tag is not present. */ public Object getAttribute(final String tag) { return getAttribute(SAMTag.makeBinaryTag(tag)); }
public String getStringAttribute(final String tag) { final Object val = getAttribute(tag); if (val == null) return null; if (val instanceof String) { return (String)val; } throw new SAMException("Value for tag " + tag + " is not a String: " + val.getClass()); }
/** Will work for signed byte array, unsigned byte array, or old-style hex array */ public byte[] getByteArrayAttribute(final String tag) { final Object val = getAttribute(tag); if (val == null) return null; if (val instanceof byte[]) { return (byte[])val; } throw new SAMException("Value for tag " + tag + " is not a byte[]: " + val.getClass()); }
public float[] getFloatArrayAttribute(final String tag) { final Object val = getAttribute(tag); if (val != null && !(val instanceof float[])) { throw new SAMException("Value for tag " + tag + " is not a float[]: " + val.getClass()); } return (float[]) val; }
/** * See if any tags pertaining to original mapping information have been set. */ public static boolean hasOriginalMappingInformation(final SAMRecord rec) { return rec.getAttribute(SAMTag.OP.name()) != null || rec.getAttribute(SAMTag.OC.name()) != null || rec.getAttribute(SAMTag.OF.name()) != null || rec.getAttribute(SAMTag.OR.name()) != null; }
@Override public Object getAttribute(final short tag) { if (!mAttributesDecoded) { decodeAttributes(); } return super.getAttribute(tag); }
@Override public Object getAttribute(final short tag) { if (!mAttributesDecoded) { decodeAttributes(); } return super.getAttribute(tag); }
public Character getCharacterAttribute(final String tag) { final Object val = getAttribute(tag); if (val == null) return null; if (val instanceof Character) { return (Character)val; } throw new SAMException("Value for tag " + tag + " is not a Character: " + val.getClass()); }
public short[] getUnsignedShortArrayAttribute(final String tag) { final Object val = getAttribute(tag); if (val == null) return null; if (val instanceof short[]) { requireUnsigned(tag); return (short[]) val; } throw new SAMException("Value for tag " + tag + " is not a short[]: " + val.getClass()); }
public int[] getUnsignedIntArrayAttribute(final String tag) { final Object val = getAttribute(tag); if (val == null) return null; if (val instanceof int[]) { requireUnsigned(tag); return (int[]) val; } throw new SAMException("Value for tag " + tag + " is not a int[]: " + val.getClass()); }
public static final SAMRecord simplifyRead(SAMRecord read) { // the only attribute we keep is the RG Object rg = read.getAttribute("RG"); read.clearAttributes(); read.setAttribute("RG", rg); return read; }
@Test public void testSAM() throws Exception { final SAMRecord rec = writeAndReadSamRecord("sam"); Assert.assertTrue(rec.getAttribute(BYTE_TAG) instanceof Integer); Assert.assertEquals(((Number) rec.getAttribute(BYTE_TAG)).intValue(), 1); Assert.assertTrue(rec.getAttribute(SHORT_TAG) instanceof Integer); Assert.assertEquals(((Number) rec.getAttribute(SHORT_TAG)).intValue(), 1); Assert.assertTrue(rec.getAttribute(INTEGER_TAG) instanceof Integer); Assert.assertEquals(((Number) rec.getAttribute(INTEGER_TAG)).intValue(), 1); }
/** * The record should already have the DS and MC tags computed */ public void addRecord(final SAMRecord record) { if (record.getReadPairedFlag() && !record.getMateUnmappedFlag() && null == record.getAttribute(SAMTag.MC.getBinaryTag())) { throw new SAMException("Mate Cigar tag (MC) not found in: " + record.getReadName()); } this.records.add(record); }
private static boolean checkHasReadGroup(final SAMRecord read) { if ( read.getReadGroup() == null ) { // there are 2 possibilities: either the RG tag is missing or it is not defined in the header final String rgID = (String)read.getAttribute(SAMTagUtil.getSingleton().RG); if ( rgID == null ) throw new UserException.ReadMissingReadGroup(read); throw new UserException.ReadHasUndefinedReadGroup(read, rgID); } return true; }
private void validateUq(final File input, final File reference) { final SamReader reader = SamReaderFactory.makeDefault().referenceSequence(reference).open(input); final SAMRecordIterator iterator = reader.iterator(); while (iterator.hasNext()){ SAMRecord rec = iterator.next(); if (!rec.getReadUnmappedFlag()) Assert.assertNotNull(rec.getAttribute("UQ")); } }
public void timeExtractTag(int reps) throws IOException { for(int i = 0; i < reps; i++) { final SamReader reader = SamReaderFactory.makeDefault().open(inputFile); CloseableIterator<SAMRecord> iterator = reader.iterator(); while(iterator.hasNext()) { SAMRecord read = iterator.next(); read.getAttribute("OQ"); } iterator.close(); reader.close(); } }