[78] | 1 | package com.framsticks.examples; |
---|
| 2 | |
---|
| 3 | import com.framsticks.core.Instance; |
---|
| 4 | import com.framsticks.core.Node; |
---|
[84] | 5 | import com.framsticks.dumping.PrintWriterSink; |
---|
[78] | 6 | import com.framsticks.model.*; |
---|
| 7 | import com.framsticks.model.Package; |
---|
| 8 | import com.framsticks.params.*; |
---|
| 9 | import com.framsticks.parsers.F0Parser; |
---|
[84] | 10 | import com.framsticks.parsers.F0Writer; |
---|
[78] | 11 | import com.framsticks.parsers.Schema; |
---|
[84] | 12 | |
---|
| 13 | import org.apache.commons.configuration.Configuration; |
---|
[78] | 14 | import org.apache.log4j.Logger; |
---|
| 15 | |
---|
[84] | 16 | import java.io.PrintWriter; |
---|
| 17 | import java.io.StringWriter; |
---|
[78] | 18 | import java.util.List; |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * Author: Piotr Śniegowski |
---|
| 22 | */ |
---|
| 23 | public class GenotypeBrowser extends Instance { |
---|
| 24 | |
---|
[84] | 25 | private static final Logger log = Logger |
---|
| 26 | .getLogger(Instance.class.getName()); |
---|
[78] | 27 | protected Schema schema; |
---|
| 28 | |
---|
[84] | 29 | public GenotypeBrowser() { |
---|
| 30 | log.info("model builder created"); |
---|
[78] | 31 | } |
---|
| 32 | |
---|
| 33 | @Override |
---|
[84] | 34 | public void configure(Configuration config) { |
---|
| 35 | super.configure(config); |
---|
| 36 | try { |
---|
| 37 | schema = new Schema(Schema.getDefaultDefinitionAsStream()); |
---|
| 38 | } catch (Exception e) { |
---|
| 39 | log.error("failed to load schema: " + e); |
---|
| 40 | } |
---|
[78] | 41 | this.registry = schema.getRegistry(); |
---|
| 42 | Package.register(this.getRegistry()); |
---|
| 43 | |
---|
[87] | 44 | registry.putInfoIntoCache(FramsClass.build() |
---|
| 45 | .idAndName("ModelBuilderRoot") |
---|
| 46 | .param(Param.build().id("model").type("o Model").name("model")) |
---|
| 47 | .param(Param.build().id("genotype").type("s 1").name("genotype")) |
---|
| 48 | .finish() |
---|
[78] | 49 | ); |
---|
[87] | 50 | root = new Node(Param.build().type("o ModelBuilderRoot").id(name).name("Instance"), PropertiesAccess.createPropertiesMap()); |
---|
[78] | 51 | } |
---|
| 52 | |
---|
| 53 | @Override |
---|
| 54 | protected void run() { |
---|
| 55 | assert isActive(); |
---|
| 56 | |
---|
| 57 | try { |
---|
| 58 | List<AccessInterface> accesses = new F0Parser(schema, GenotypeBrowser.class.getResourceAsStream("/examples/f0_example.txt")).parse(); |
---|
| 59 | List<Object> objects = Util.stripAccessInterface(accesses); |
---|
[79] | 60 | Model model = Model.build(objects); |
---|
[78] | 61 | |
---|
[84] | 62 | AccessInterface rootAccess = bindAccess(this.getRootPath()); |
---|
[78] | 63 | |
---|
[79] | 64 | rootAccess.set("model", model); |
---|
[78] | 65 | |
---|
[84] | 66 | StringWriter w = new StringWriter(); |
---|
| 67 | new F0Writer(schema, model, new PrintWriterSink(new PrintWriter(w))).write(); |
---|
| 68 | rootAccess.set("genotype", w.getBuffer().toString()); |
---|
| 69 | |
---|
[78] | 70 | } catch (Exception e) { |
---|
[84] | 71 | log.error("exception caught: " + e); |
---|
[78] | 72 | } |
---|
| 73 | //done(); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | } |
---|