SAMRecord read, String matchingString) {
List<HitInfo> bestHits = new ArrayList<HitInfo>();
contigReadStr = contigReadStr.substring(contigReadStr.indexOf('~')+1);
contigReadStr = contigReadStr.replace('~', '\t');
SAMRecord contigRead = samStringReader.getRead(contigReadStr);
int bestMismatches = SAMRecordUtils.getIntAttribute(read, "XM");
// Filter this hit if it aligns past the end of the contig
// Must use cigar length instead of read length, because the
// the contig read bases are not loaded.
if (read.getAlignmentEnd() <= contigRead.getCigar().getReadLength()) {
HitInfo hit = new HitInfo(contigRead, read.getAlignmentStart(),
read.getReadNegativeStrandFlag() ? '-' : '+', bestMismatches);
bestHits.add(hit);
}
int numBestHits = SAMRecordUtils.getIntAttribute(read, "X0");
int numSubOptimalHits = SAMRecordUtils.getIntAttribute(read, "X1");
int totalHits = numBestHits + numSubOptimalHits;
if ((totalHits > 1) && (totalHits < 1000)) {
// Look in XA tag.
String alternateHitsStr = (String) read.getAttribute("XA");
if (alternateHitsStr == null) {
String msg = "best hits = " + numBestHits + ", but no XA entry for: " + read.getSAMString();
System.out.println(msg);
} else {
String[] alternates = alternateHitsStr.split(";");
for (int i=0; i<alternates.length-1; i++) {
String[] altInfo = alternates[i].split(",");
String altContigReadStr = altInfo[0];
char strand = altInfo[1].charAt(0);
int position = Integer.parseInt(altInfo[1].substring(1));
String cigar = altInfo[2];
int mismatches = Integer.parseInt(altInfo[3]);
if ((cigar.equals(matchingString)) && (mismatches < bestMismatches)) {
System.out.println("MISMATCH_ISSUE: " + read.getSAMString());
}
if ((cigar.equals(matchingString)) && (mismatches == bestMismatches)) {
altContigReadStr = altContigReadStr.substring(altContigReadStr.indexOf('~')+1);
altContigReadStr = altContigReadStr.replace('~', '\t');
contigRead = samStringReader.getRead(altContigReadStr);
// Filter this hit if it aligns past the end of the contig
// Must use cigar length instead of read length, because the
// the contig read bases are not loaded.
if ((position + read.getReadLength()) <= contigRead.getCigar().getReadLength()) {
HitInfo hit = new HitInfo(contigRead, position, strand, mismatches);
bestHits.add(hit);
}
}
}