-
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-1169] Write GFF header line pragma in single file mode.
Resolves #1169.
- Loading branch information
Showing
4 changed files
with
101 additions
and
3 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
45 changes: 45 additions & 0 deletions
45
adam-core/src/main/scala/org/bdgenomics/adam/rdd/feature/GFFHeaderWriter.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,45 @@ | ||
/** | ||
* 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.feature | ||
|
||
import org.apache.hadoop.fs.Path | ||
import org.apache.spark.SparkContext | ||
|
||
/** | ||
* Writes the header for a GFF file to an otherwise empty file. | ||
*/ | ||
private[feature] object GFFHeaderWriter { | ||
|
||
val HEADER_STRING = "##gff-version 3.2.1" | ||
|
||
/** | ||
* Writes a GFF Header pragma to a file. | ||
* | ||
* @param filePath The path to write the file to. | ||
* @param sc The SparkContext, to access the Hadoop FS Configuration. | ||
*/ | ||
def apply(filePath: String, | ||
sc: SparkContext) { | ||
val path = new Path(filePath) | ||
val fs = path.getFileSystem(sc.hadoopConfiguration) | ||
val os = fs.create(path) | ||
os.write(HEADER_STRING.getBytes) | ||
os.write("\n".getBytes) | ||
os.close() | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
adam-core/src/test/scala/org/bdgenomics/adam/rdd/feature/GFFHeaderWriterSuite.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,34 @@ | ||
/** | ||
* 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.feature | ||
|
||
import org.bdgenomics.adam.util.ADAMFunSuite | ||
import scala.io.Source | ||
|
||
class GFFHeaderWriterSuite extends ADAMFunSuite { | ||
|
||
sparkTest("write gff header pragma") { | ||
val tmp = tmpFile(".gff") | ||
GFFHeaderWriter(tmp, sc) | ||
val lines = Source.fromFile(tmp) | ||
.getLines | ||
.toSeq | ||
assert(lines.size === 1) | ||
assert(lines.head === GFFHeaderWriter.HEADER_STRING) | ||
} | ||
} |