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

replacing uses of deprecated class SAMFileReader #1235

Closed
Closed
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 @@ -17,10 +17,11 @@
*/
package org.bdgenomics.adam.cli

import java.io.{ FileOutputStream, File }
import java.io.{ File, FileOutputStream }

import htsjdk.variant.utils.SAMSequenceDictionaryExtractor
import org.apache.commons.io.IOUtils
import org.bdgenomics.adam.models.SequenceDictionary
import htsjdk.samtools.SAMFileReader

trait DictionaryCommand {
private def getDictionaryFile(name: String): Option[File] = {
Expand All @@ -33,7 +34,7 @@ trait DictionaryCommand {
Some(file)
}

private def getDictionary(file: File) = Some(SequenceDictionary(SAMFileReader.getSequenceDictionary(file)))
private def getDictionary(file: File) = Some(SequenceDictionary(SAMSequenceDictionaryExtractor.extractDictionary(file)))

def loadSequenceDictionary(file: File): Option[SequenceDictionary] = {
if (file != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
*/
package org.bdgenomics.adam.models

import htsjdk.samtools.{ SAMFileHeader, SAMFileReader, SAMReadGroupRecord }
import java.util.Date

import htsjdk.samtools.{ SAMFileHeader, SAMReadGroupRecord, SamReader }
import org.bdgenomics.formats.avro.{ RecordGroupMetadata, Sample }

import scala.collection.JavaConversions._

object RecordGroupDictionary {
Expand All @@ -42,7 +44,7 @@ object RecordGroupDictionary {
* @param samReader SAM file header with attached read groups.
* @return Returns a new record group dictionary with the read groups attached to the file header.
*/
def fromSAMReader(samReader: SAMFileReader): RecordGroupDictionary = {
def fromSAMReader(samReader: SamReader): RecordGroupDictionary = {
fromSAMHeader(samReader.getFileHeader)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@
*/
package org.bdgenomics.adam.rdd.read

import htsjdk.samtools.{
SAMFileReader,
SAMRecord,
SAMRecordIterator
}
import java.io.InputStream

import htsjdk.samtools._
import org.bdgenomics.adam.converters.SAMRecordConverter
import org.bdgenomics.adam.models.{
RecordGroupDictionary,
SequenceDictionary
}
import org.bdgenomics.adam.rdd.OutFormatter
import org.bdgenomics.formats.avro.AlignmentRecord

import scala.annotation.tailrec
import scala.collection.mutable.ListBuffer

Expand All @@ -47,7 +41,7 @@ class AnySAMOutFormatter extends OutFormatter[AlignmentRecord] {
val converter = new SAMRecordConverter

// make reader
val reader = new SAMFileReader(is)
val reader = SamReaderFactory.makeDefault().open(SamInputResource.of(is))

// make iterator from said reader
val iter = reader.iterator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ package org.bdgenomics.adam.converters
import htsjdk.samtools.SAMFileReader
import htsjdk.variant.variantcontext.{ Allele, GenotypeBuilder, GenotypeType, VariantContextBuilder }
import java.io.File
import org.bdgenomics.adam.models.{ VariantContext => ADAMVariantContext, SequenceDictionary }

import htsjdk.variant.utils.SAMSequenceDictionaryExtractor
import org.bdgenomics.adam.models.{ SequenceDictionary, VariantContext => ADAMVariantContext }
import org.bdgenomics.adam.util.{ ADAMFunSuite, PhredUtils }
import org.bdgenomics.formats.avro._
import org.scalatest.FunSuite

import scala.collection.JavaConversions._

class VariantContextConverterSuite extends ADAMFunSuite {
val dictionary = {
val path = testFile("dict_with_accession.dict")
SequenceDictionary(SAMFileReader.getSequenceDictionary(new File(path)))
SequenceDictionary(SAMSequenceDictionaryExtractor.extractDictionary(new File(path)))
}

def gatkSNVBuilder: VariantContextBuilder = new VariantContextBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
*/
package org.bdgenomics.adam.models

import htsjdk.samtools.{ SAMFileReader, SAMSequenceRecord, SAMSequenceDictionary }
import htsjdk.samtools.{ SAMFileReader, SAMSequenceDictionary, SAMSequenceRecord }
import htsjdk.variant.vcf.VCFFileReader
import java.io.File

import htsjdk.variant.utils.SAMSequenceDictionaryExtractor
import org.bdgenomics.adam.util.ADAMFunSuite

import scala.collection.JavaConversions._

class SequenceDictionarySuite extends ADAMFunSuite {
Expand All @@ -41,7 +44,7 @@ class SequenceDictionarySuite extends ADAMFunSuite {

test("Convert from SAM sequence dictionary file (with extra fields)") {
val path = testFile("dict_with_accession.dict")
val ssd = SAMFileReader.getSequenceDictionary(new File(path))
val ssd = SAMSequenceDictionaryExtractor.extractDictionary(new File(path))

val chr1 = ssd.getSequence("1") // Validate that extra fields are parsed
assert(chr1 != null)
Expand All @@ -55,7 +58,7 @@ class SequenceDictionarySuite extends ADAMFunSuite {

test("merge into existing dictionary") {
val path = testFile("dict_with_accession.dict")
val ssd = SAMFileReader.getSequenceDictionary(new File(path))
val ssd = SAMSequenceDictionaryExtractor.extractDictionary(new File(path))

val asd = SequenceDictionary(ssd)
assert(asd.containsRefName("1"))
Expand All @@ -68,7 +71,7 @@ class SequenceDictionarySuite extends ADAMFunSuite {

test("Convert from SAM sequence dictionary and back") {
val path = testFile("dict_with_accession.dict")
val ssd = SAMFileReader.getSequenceDictionary(new File(path))
val ssd = SAMSequenceDictionaryExtractor.extractDictionary(new File(path))
val asd = SequenceDictionary(ssd)
ssd.assertSameDictionary(SequenceDictionary.toSAMSequenceDictionary(asd))
}
Expand Down