Skip to content

Commit

Permalink
Merge pull request #26 from genomebridge/carlyeks/fixUnmappedReadsInS…
Browse files Browse the repository at this point in the history
…equenceDictionary

Fix unmapped reads in sequence dictionary
  • Loading branch information
massie committed Dec 12, 2013
2 parents 8dc21cd + f47aa0c commit 9b1dd16
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,31 @@ class SAMRecordConverter extends Serializable {
def convert(samRecord: SAMRecord, dict : SequenceDictionary): ADAMRecord = {

val builder: ADAMRecord.Builder = ADAMRecord.newBuilder
.setReferenceName(samRecord.getReferenceName)
.setReferenceId(samRecord.getReferenceIndex)
.setReferenceLength(dict(samRecord.getReferenceIndex).length)
.setReferenceUrl(dict(samRecord.getReferenceIndex).url)
.setReadName(samRecord.getReadName)
.setSequence(samRecord.getReadString)
.setCigar(samRecord.getCigarString)
.setQual(samRecord.getBaseQualityString)

val start: Int = samRecord.getAlignmentStart

if (start != 0) {
builder.setStart((start - 1).asInstanceOf[Long])
}
// Only set the reference information if the read is aligned, matching the mate reference
// This prevents looking up a -1 in the sequence dictionary
val readReference: Int = samRecord.getReferenceIndex
if (readReference != SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) {
builder
.setReferenceId(readReference)
.setReferenceName(samRecord.getReferenceName)
.setReferenceLength(dict(samRecord.getReferenceIndex).length)
.setReferenceUrl(dict(samRecord.getReferenceIndex).url)

val start: Int = samRecord.getAlignmentStart
if (start != 0) {
builder.setStart((start - 1).asInstanceOf[Long])
}

val mapq: Int = samRecord.getMappingQuality
val mapq: Int = samRecord.getMappingQuality

if (mapq != SAMRecord.UNKNOWN_MAPPING_QUALITY) {
builder.setMapq(mapq)
if (mapq != SAMRecord.UNKNOWN_MAPPING_QUALITY) {
builder.setMapq(mapq)
}
}

// Position of the mate/next segment
Expand Down
Loading

0 comments on commit 9b1dd16

Please sign in to comment.