forked from bigdatagenomics/adam
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADAM-1141] Add support for saving/loading AlignmentRecords to/from C…
…RAM. Resolves bigdatagenomics#1141. Changes the signature of `AlignmentRecordRDD.saveAsSAM` to take an `Option[SAMFormat]` parameter, since `asSam` is now no longer a binary choice.
- Loading branch information
Showing
5 changed files
with
186 additions
and
56 deletions.
There are no files selected for viewing
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
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
83 changes: 83 additions & 0 deletions
83
adam-core/src/main/scala/org/bdgenomics/adam/rdd/read/ADAMCRAMOutputFormat.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Licensed to Big Data Genomics (BDG) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The BDG licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.bdgenomics.adam.rdd.read | ||
|
||
import htsjdk.samtools.SAMFileHeader | ||
import org.apache.hadoop.fs.Path | ||
import org.apache.hadoop.mapreduce.{ OutputFormat, RecordWriter, TaskAttemptContext } | ||
import org.apache.spark.rdd.InstrumentedOutputFormat | ||
import org.bdgenomics.adam.instrumentation.Timers | ||
import org.seqdoop.hadoop_bam.{ | ||
KeyIgnoringCRAMOutputFormat, | ||
KeyIgnoringCRAMRecordWriter, | ||
SAMRecordWritable | ||
} | ||
|
||
class ADAMCRAMOutputFormat[K] | ||
extends KeyIgnoringCRAMOutputFormat[K] with Serializable { | ||
|
||
setWriteHeader(true) | ||
|
||
override def getRecordWriter(context: TaskAttemptContext): RecordWriter[K, SAMRecordWritable] = { | ||
val conf = context.getConfiguration() | ||
|
||
// where is our header file? | ||
val path = new Path(conf.get("org.bdgenomics.adam.rdd.read.bam_header_path")) | ||
|
||
// read the header file | ||
readSAMHeaderFrom(path, conf) | ||
|
||
// now that we have the header set, we need to make a record reader | ||
return new KeyIgnoringCRAMRecordWriter[K](getDefaultWorkFile(context, ""), | ||
header, | ||
true, | ||
context) | ||
} | ||
} | ||
|
||
class InstrumentedADAMCRAMOutputFormat[K] extends InstrumentedOutputFormat[K, org.seqdoop.hadoop_bam.SAMRecordWritable] { | ||
override def timerName(): String = Timers.WriteCRAMRecord.timerName | ||
override def outputFormatClass(): Class[_ <: OutputFormat[K, SAMRecordWritable]] = classOf[ADAMCRAMOutputFormat[K]] | ||
} | ||
|
||
class ADAMCRAMOutputFormatHeaderLess[K] | ||
extends KeyIgnoringCRAMOutputFormat[K] with Serializable { | ||
|
||
setWriteHeader(false) | ||
|
||
override def getRecordWriter(context: TaskAttemptContext): RecordWriter[K, SAMRecordWritable] = { | ||
val conf = context.getConfiguration() | ||
|
||
// where is our header file? | ||
val path = new Path(conf.get("org.bdgenomics.adam.rdd.read.bam_header_path")) | ||
|
||
// read the header file | ||
readSAMHeaderFrom(path, conf) | ||
|
||
// now that we have the header set, we need to make a record reader | ||
return new KeyIgnoringCRAMRecordWriter[K](getDefaultWorkFile(context, ""), | ||
header, | ||
false, | ||
context) | ||
} | ||
} | ||
|
||
class InstrumentedADAMCRAMOutputFormatHeaderLess[K] extends InstrumentedOutputFormat[K, org.seqdoop.hadoop_bam.SAMRecordWritable] { | ||
override def timerName(): String = Timers.WriteCRAMRecord.timerName | ||
override def outputFormatClass(): Class[_ <: OutputFormat[K, SAMRecordWritable]] = classOf[ADAMCRAMOutputFormatHeaderLess[K]] | ||
} |
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
Oops, something went wrong.