-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADAM-941] Automatically generate projection enums.
Resolves #941.
- Loading branch information
Showing
23 changed files
with
184 additions
and
497 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
86 changes: 86 additions & 0 deletions
86
adam-codegen/src/main/scala/org/bdgenomics/adam/codegen/DumpSchemasToProjectionEnums.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,86 @@ | ||
/** | ||
* 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.codegen | ||
|
||
import java.io.{ File, FileWriter } | ||
import org.apache.avro.Schema | ||
import org.apache.avro.reflect.ReflectData | ||
import scala.collection.JavaConversions._ | ||
|
||
object DumpSchemasToProjectionEnums { | ||
|
||
def main(args: Array[String]) { | ||
new DumpSchemasToProjectionEnums()(args) | ||
} | ||
} | ||
|
||
class DumpSchemasToProjectionEnums extends Generator { | ||
|
||
private def fields(schema: Schema): Seq[String] = { | ||
schema.getFields() | ||
.map(field => field.name) | ||
.toSeq | ||
} | ||
|
||
private def generateClassDump(className: String): String = { | ||
|
||
// get schema | ||
val schema = ReflectSchema.getSchemaByReflection(className) | ||
|
||
// get class name without package | ||
val classNameNoPackage = className.split('.').last | ||
|
||
"\n\nobject %sField extends FieldEnumeration(%s.SCHEMA$) {\n val %s = SchemaValue\n}".format( | ||
classNameNoPackage, | ||
className, | ||
fields(schema).mkString(", ")) | ||
} | ||
|
||
def apply(args: Array[String]) { | ||
|
||
if (args.length < 3) { | ||
println("DumpSchemasToProjectionEnums <package-name> <class-to-dump> ... <file-to-dump-to>") | ||
System.exit(1) | ||
} else { | ||
|
||
// drop the file to write and the package name | ||
val classesToDump = args.drop(1).dropRight(1) | ||
|
||
// open the file to write | ||
val dir = new File(args.last).getParentFile | ||
if (!dir.exists()) { | ||
dir.mkdirs() | ||
} | ||
val fw = new FileWriter(args.last) | ||
|
||
// write the header | ||
writeHeader(fw, args.head) | ||
|
||
// loop and dump the classes | ||
classesToDump.foreach(className => { | ||
val dumpString = generateClassDump(className) | ||
|
||
fw.write("\n") | ||
fw.write(dumpString) | ||
}) | ||
|
||
// we are done, so close and flush | ||
fw.close() | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
adam-codegen/src/main/scala/org/bdgenomics/adam/codegen/Generator.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,50 @@ | ||
/** | ||
* 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.codegen | ||
|
||
import java.io.FileWriter | ||
|
||
trait Generator { | ||
|
||
protected def writeHeader(fw: FileWriter, packageName: String) { | ||
val hdr = Seq( | ||
"/**", | ||
"* 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 %s".format(packageName), | ||
"", | ||
"import scala.collection.JavaConversions._", | ||
"import scala.collection.JavaConverters._").mkString("\n") | ||
|
||
fw.write(hdr) | ||
} | ||
} |
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
28 changes: 0 additions & 28 deletions
28
adam-core/src/main/scala/org/bdgenomics/adam/projections/AlignmentRecordField.scala
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
adam-core/src/main/scala/org/bdgenomics/adam/projections/ContigField.scala
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
adam-core/src/main/scala/org/bdgenomics/adam/projections/DbxrefField.scala
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
adam-core/src/main/scala/org/bdgenomics/adam/projections/FeatureField.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.