Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Some to Option to check for unmapped reads #225

Merged
merged 1 commit into from
Apr 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.bdgenomics.adam.avro.{ ADAMRecord, ADAMGenotype, ADAMVariant, ADAMPil
import org.bdgenomics.adam.rdd.ADAMContext._
import com.esotericsoftware.kryo.{ Kryo, Serializer }
import com.esotericsoftware.kryo.io.{ Input, Output }
import Ordering.Option

object ReferencePositionWithOrientation {

Expand Down Expand Up @@ -80,9 +79,9 @@ object ReferencePosition {
* @return True if read is mapped and has a valid position, else false.
*/
def mappedPositionCheck(record: ADAMRecord): Boolean = {
val contig = Some(record.getContig)
val start = Some(record.getStart)
record.getReadMapped && (contig.isDefined && Some(contig.get.getContigName).isDefined) && start.isDefined
val contig = Option(record.getContig)
val start = Option(record.getStart)
record.getReadMapped && (contig.isDefined && Option(contig.get.getContigName).isDefined) && start.isDefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is Scalic (what is the Scala equivalent of pythonic?), but wouldn't it be more efficient to just directly check vs. null? I think Options are more useful when used functionally (e.g., a foreach, flatmap, etc).

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,49 @@ class ReferencePositionSuite extends FunSuite {
assert(refPosOpt.isEmpty)
}

test("create reference position from mapped read but contig not specified") {
val read = ADAMRecord.newBuilder()
.setReadMapped(true)
.setStart(1L)
.build()

val refPosOpt = ReferencePosition(read)

assert(refPosOpt.isEmpty)
}

test("create reference position from mapped read but contig is underspecified") {
val contig = ADAMContig.newBuilder
// contigName is NOT set
//.setContigName("chr1")
.build

val read = ADAMRecord.newBuilder()
.setReadMapped(true)
.setStart(1L)
.setContig(contig)
.build()

val refPosOpt = ReferencePosition(read)

assert(refPosOpt.isEmpty)
}

test("create reference position from mapped read but start not specified") {
val contig = ADAMContig.newBuilder
.setContigName("chr1")
.build

val read = ADAMRecord.newBuilder()
.setReadMapped(true)
.setContig(contig)
.build()

val refPosOpt = ReferencePosition(read)

assert(refPosOpt.isEmpty)
}

test("create reference position from pileup") {
val contig = ADAMContig.newBuilder
.setContigName("chr2")
Expand Down