-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADAM-1768] Add InFormatter for unpaired FASTQ.
Resolves #1768.
- Loading branch information
Showing
2 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
adam-core/src/main/scala/org/bdgenomics/adam/rdd/read/FASTQInFormatter.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,67 @@ | ||
/** | ||
* 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 java.io.OutputStream | ||
import org.apache.hadoop.conf.Configuration | ||
import org.bdgenomics.adam.converters.AlignmentRecordConverter | ||
import org.bdgenomics.adam.rdd.{ InFormatter, InFormatterCompanion } | ||
import org.bdgenomics.adam.rdd.fragment.FragmentRDD | ||
import org.bdgenomics.formats.avro.AlignmentRecord | ||
import org.bdgenomics.utils.misc.Logging | ||
|
||
/** | ||
* InFormatter companion that creates an InFormatter that writes FASTQ. | ||
*/ | ||
object FASTQInFormatter extends InFormatterCompanion[AlignmentRecord, AlignmentRecordRDD, FASTQInFormatter] { | ||
|
||
/** | ||
* Builds an FASTQInFormatter to write FASTQ. | ||
* | ||
* @param gRdd GenomicRDD of AlignmentRecords. Used to get HadoopConfiguration. | ||
* @return Returns a new Single FASTQ InFormatter. | ||
*/ | ||
def apply(gRdd: AlignmentRecordRDD): FASTQInFormatter = { | ||
new FASTQInFormatter(gRdd.rdd.context.hadoopConfiguration) | ||
} | ||
} | ||
|
||
class FASTQInFormatter private ( | ||
conf: Configuration) extends InFormatter[AlignmentRecord, AlignmentRecordRDD, FASTQInFormatter] with Logging { | ||
|
||
protected val companion = FASTQInFormatter | ||
private val converter = new AlignmentRecordConverter | ||
private val writeSuffixes = conf.getBoolean(FragmentRDD.WRITE_SUFFIXES, false) | ||
private val writeOriginalQualities = conf.getBoolean(FragmentRDD.WRITE_ORIGINAL_QUALITIES, false) | ||
|
||
/** | ||
* Writes alignment records to an output stream in FASTQ format. | ||
* | ||
* @param os An OutputStream connected to a process we are piping to. | ||
* @param iter An iterator of records to write. | ||
*/ | ||
def write(os: OutputStream, iter: Iterator[AlignmentRecord]) { | ||
iter.foreach(read => { | ||
val fastqRead = converter.convertToFastq(read, | ||
maybeAddSuffix = writeSuffixes, | ||
outputOriginalBaseQualities = writeOriginalQualities) + "\n" | ||
|
||
os.write(fastqRead.getBytes) | ||
}) | ||
} | ||
} |
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