Java Code Examples for htsjdk.samtools.SAMUtils#combineMapqs()
The following examples show how to use
htsjdk.samtools.SAMUtils#combineMapqs() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MostDistantPrimaryAlignmentSelectionStrategy.java From picard with MIT License | 5 votes |
public void considerBest(final SAMRecord firstEnd, final SAMRecord secondEnd) { final int thisPairMapq = SAMUtils.combineMapqs(firstEnd.getMappingQuality(), secondEnd.getMappingQuality()); final int thisDistance = CoordMath.getLength(Math.min(firstEnd.getAlignmentStart(), secondEnd.getAlignmentStart()), Math.max(firstEnd.getAlignmentEnd(), secondEnd.getAlignmentEnd())); if (thisDistance > bestDistance || (thisDistance == bestDistance && thisPairMapq > bestPairMapq)) { bestDistance = thisDistance; bestPairMapq = thisPairMapq; bestAlignmentPairs.clear(); bestAlignmentPairs.add(new AbstractMap.SimpleEntry<SAMRecord, SAMRecord>(firstEnd, secondEnd)); } else if (thisDistance == bestDistance && thisPairMapq == bestPairMapq) { bestAlignmentPairs.add(new AbstractMap.SimpleEntry<SAMRecord, SAMRecord>(firstEnd, secondEnd)); } }
Example 2
Source File: MostDistantPrimaryAlignmentSelectionStrategy.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void considerBest(final SAMRecord firstEnd, final SAMRecord secondEnd) { final int thisPairMapq = SAMUtils.combineMapqs(firstEnd.getMappingQuality(), secondEnd.getMappingQuality()); final int thisDistance = CoordMath.getLength(Math.min(firstEnd.getAlignmentStart(), secondEnd.getAlignmentStart()), Math.max(firstEnd.getAlignmentEnd(), secondEnd.getAlignmentEnd())); if (thisDistance > bestDistance || (thisDistance == bestDistance && thisPairMapq > bestPairMapq)) { bestDistance = thisDistance; bestPairMapq = thisPairMapq; bestAlignmentPairs.clear(); bestAlignmentPairs.add(new AbstractMap.SimpleEntry<>(firstEnd, secondEnd)); } else if (thisDistance == bestDistance && thisPairMapq == bestPairMapq) { bestAlignmentPairs.add(new AbstractMap.SimpleEntry<>(firstEnd, secondEnd)); } }
Example 3
Source File: BestMapqPrimaryAlignmentSelectionStrategy.java From picard with MIT License | 4 votes |
/** * Primary alignment was filtered out. Need to select a new one. */ public void pickPrimaryAlignment(final HitsForInsert hits) { if (hits.numHits() == 0) throw new IllegalArgumentException("No alignments to pick from"); hits.coordinateByHitIndex(); // See if primary alignment is not already unambiguously determined. final NumPrimaryAlignmentState firstEndAlignmentState = hits.tallyPrimaryAlignments(true); final NumPrimaryAlignmentState secondEndAlignmentState = hits.tallyPrimaryAlignments(false); if ((firstEndAlignmentState == NumPrimaryAlignmentState.NONE && secondEndAlignmentState == NumPrimaryAlignmentState.NONE) || firstEndAlignmentState == NumPrimaryAlignmentState.MORE_THAN_ONE || secondEndAlignmentState == NumPrimaryAlignmentState.MORE_THAN_ONE) { // Need to use selected strategy for picking primary. // Find all the hits with the best MAPQ. final List<Integer> primaryAlignmentIndices = new ArrayList<Integer>(hits.numHits()); int bestMapQ = -1; for (int i = 0; i < hits.numHits(); ++i) { final int firstEndMapq; if (hits.getFirstOfPair(i) != null) { firstEndMapq = hits.getFirstOfPair(i).getMappingQuality(); } else { firstEndMapq = 0; } final int secondEndMapq; if (hits.getSecondOfPair(i) != null) { secondEndMapq = hits.getSecondOfPair(i).getMappingQuality(); } else { secondEndMapq = 0; } int thisMapQ = SAMUtils.combineMapqs(firstEndMapq, secondEndMapq); if (thisMapQ > bestMapQ) { bestMapQ = thisMapQ; primaryAlignmentIndices.clear(); } if (thisMapQ == bestMapQ) primaryAlignmentIndices.add(i); } // Of all the hits with the best MAPQ, randomly select one to be primary. final int primaryAlignmentIndex; if (primaryAlignmentIndices.size() == 1) primaryAlignmentIndex = primaryAlignmentIndices.get(0); else if (primaryAlignmentIndices.size() > 1) primaryAlignmentIndex = primaryAlignmentIndices.get(random.nextInt(primaryAlignmentIndices.size())); else throw new IllegalStateException("Never found a best MAPQ -- should never happen"); hits.setPrimaryAlignment(primaryAlignmentIndex); } }
Example 4
Source File: BestMapqPrimaryAlignmentSelectionStrategy.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Primary alignment was filtered out. Need to select a new one. */ @Override public void pickPrimaryAlignment(final HitsForInsert hits) { if (hits.numHits() == 0) throw new IllegalArgumentException("No alignments to pick from"); hits.coordinateByHitIndex(); // See if primary alignment is not already unambiguously determined. final NumPrimaryAlignmentState firstEndAlignmentState = hits.tallyPrimaryAlignments(true); final NumPrimaryAlignmentState secondEndAlignmentState = hits.tallyPrimaryAlignments(false); if ((firstEndAlignmentState == NumPrimaryAlignmentState.NONE && secondEndAlignmentState == NumPrimaryAlignmentState.NONE) || firstEndAlignmentState == NumPrimaryAlignmentState.MORE_THAN_ONE || secondEndAlignmentState == NumPrimaryAlignmentState.MORE_THAN_ONE) { // Need to use selected strategy for picking primary. // Find all the hits with the best MAPQ. final List<Integer> primaryAlignmentIndices = new ArrayList<>(hits.numHits()); int bestMapQ = -1; for (int i = 0; i < hits.numHits(); ++i) { final int firstEndMapq; if (hits.getFirstOfPair(i) != null) { firstEndMapq = hits.getFirstOfPair(i).getMappingQuality(); } else { firstEndMapq = 0; } final int secondEndMapq; if (hits.getSecondOfPair(i) != null) { secondEndMapq = hits.getSecondOfPair(i).getMappingQuality(); } else { secondEndMapq = 0; } int thisMapQ = SAMUtils.combineMapqs(firstEndMapq, secondEndMapq); if (thisMapQ > bestMapQ) { bestMapQ = thisMapQ; primaryAlignmentIndices.clear(); } if (thisMapQ == bestMapQ) primaryAlignmentIndices.add(i); } // Of all the hits with the best MAPQ, randomly select one to be primary. final int primaryAlignmentIndex; if (primaryAlignmentIndices.size() == 1) primaryAlignmentIndex = primaryAlignmentIndices.get(0); else if (primaryAlignmentIndices.size() > 1) primaryAlignmentIndex = primaryAlignmentIndices.get(random.nextInt(primaryAlignmentIndices.size())); else throw new IllegalStateException("Never found a best MAPQ -- should never happen"); hits.setPrimaryAlignment(primaryAlignmentIndex); } }