Created
July 18, 2014 13:57
-
-
Save soh-i/4c546c0898525899131f to your computer and use it in GitHub Desktop.
ScalaでBamファイルを読み込んでみる
This file contains 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 java.io.File | |
import net.sf.samtools.SAMFileReader | |
import net.sf.samtools.SAMFileWriter | |
import net.sf.samtools.SAMFileWriterFactory | |
import net.sf.samtools.SAMRecord | |
import net.sf.samtools.SAMRecordIterator | |
import net.sf.samtools.SAMFileReader.ValidationStringency | |
object BamReader { | |
def main(args: Array[String]): Unit = { | |
val inFile = "/Users/yukke/dev/data/testREDItools/rna.bam" | |
val inputSam: SAMFileReader = new SAMFileReader(new File(inFile)) | |
inputSam.setValidationStringency(ValidationStringency.SILENT) | |
val iter: SAMRecordIterator = inputSam.iterator() | |
while (iter.hasNext()) { | |
val rec: SAMRecord = iter.next() | |
if (!rec.getReadUnmappedFlag()) { | |
var refName = rec.getReferenceName() | |
var alignStart = rec.getAlignmentStart() | |
var alignEnd = rec.getAlignmentEnd() | |
println(f"$refName%s, $alignStart%d, $alignEnd%d") | |
} | |
} | |
iter.close() | |
inputSam.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment