Last active
December 9, 2016 00:46
-
-
Save mpkocher/41f9c885125241c5541986f76c17932c to your computer and use it in GitHub Desktop.
SubreadSet Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.pacbio.secondary.analysis.datasets.io._ | |
import java.nio.file.{Paths, Path} | |
import collection.JavaConversions._ | |
import collection.JavaConverters._ | |
import com.pacbio.secondary.analysis.datasets.io._ | |
import com.pacificbiosciences.pacbiobasedatamodel.ExternalResources | |
import com.pacificbiosciences.pacbiobasedatamodel.ExternalResource | |
def getPaths(externalResources: ExternalResources): Seq[String] = { | |
Option(externalResources).map { ex => | |
ex.getExternalResource | |
.flatMap { e => Seq(e.getResourceId) ++ getPaths(e.getExternalResources)} | |
}.getOrElse(Seq.empty[String]) | |
} | |
val p = "/Users/mkocher/gh_mk_projects/smrtflow/smrt-analysis/src/test/resources/dataset-subreads/m54006_160224_002151.subreadset.xml" | |
val s = DataSetLoader.loadSubreadSetIO(Paths.get(p)) | |
val paths = getPaths(s.dataset.getExternalResources) | |
// generalize to iterate over External Resources and | |
// convert E -> T | |
// and filter specific E | |
def getFromExternalResources[T](externalResources: ExternalResources, | |
g: (ExternalResource => T), | |
f: (ExternalResource => Boolean)): Seq[T] = { | |
Option(externalResources).map { ex => | |
ex.getExternalResource | |
.filter(f) | |
.flatMap { e => Seq(g(e)) ++ getFromExternalResources[T](e.getExternalResources, g, f) } | |
}.getOrElse(Seq.empty[T]) | |
} | |
// extract/translate External resource a Type, For example, get the abspath | |
// of the DataSet via partial application. Here's a simple E -> Path | |
def fx(e: ExternalResource): Path = Paths.get(e.getResourceId) | |
// enable filtering by MetaType | |
def efilter(e: ExternalResource): Boolean = true | |
val paths = getFromExternalResources[Path](s.dataset.getExternalResources, fx, efilter) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment