Пример #1
0
    def test_workflow_with_generated_task_classes(self):
        wf = specs.Workflow()

        AddTwo = spec_class_generator("AddTwo", self.add_two)
        AddThree = spec_class_generator("AddThree", self.add_three)
        Multiply = spec_class_generator("Multiply", self.multiply)

        wf.add_task(AddTwo(), "a2")
        wf.add_task(AddThree(), "a3")
        wf.add_task(Multiply(), "m")

        wf.connect_tasks("a3", "m", {"b": "in1"})
        wf.connect_tasks("a2", "m", {"b": "in2"})

        # Add default as defined in self.workflow
        wf.set_default("a3.a", {"format": "number", "data": 10})

        self.assertEquals(wf, self.workflow)
        inputs = {"a2.a": {"format": "json", "data": "1"},
                  "a3.a": {"format": "number", "data": 2}}

        ground = romanesco.run(self.workflow, inputs=inputs)
        system = romanesco.run(wf, inputs=inputs)

        self.assertEquals(system, ground)
Пример #2
0
 def test_pgls(self):
     pgls = romanesco.load(os.path.join(self.arbor_path, "pgls.json"))
     tree_file = os.path.join("data", "anolis.phy")
     table_file = os.path.join("data", "anolisDataAppended.csv")
     romanesco.run(
         pgls, {
             "tree": {
                 "format": "newick",
                 "url": "file://" + tree_file
             },
             "table": {
                 "format": "csv",
                 "url": "file://" + table_file
             },
             "correlation": {
                 "format": "text",
                 "data": "BM"
             },
             "ind_variable": {
                 "format": "text",
                 "data": "SVL"
             },
             "dep_variable": {
                 "format": "text",
                 "data": "PCI_limbs"
             }
         })
Пример #3
0
    def test_workflow_with_generated_task_classes(self):
        wf = specs.Workflow()

        AddTwo = spec_class_generator("AddTwo", self.add_two)
        AddThree = spec_class_generator("AddThree", self.add_three)
        Multiply = spec_class_generator("Multiply", self.multiply)

        wf.add_task(AddTwo(), "a2")
        wf.add_task(AddThree(), "a3")
        wf.add_task(Multiply(), "m")

        wf.connect_tasks("a3", "m", {"b": "in1"})
        wf.connect_tasks("a2", "m", {"b": "in2"})

        # Add default as defined in self.workflow
        wf.set_default("a3.a", {"format": "number", "data": 10})

        self.assertEquals(wf, self.workflow)
        inputs = {
            "a2.a": {
                "format": "json",
                "data": "1"
            },
            "a3.a": {
                "format": "number",
                "data": 2
            }
        }

        ground = romanesco.run(self.workflow, inputs=inputs)
        system = romanesco.run(wf, inputs=inputs)

        self.assertEquals(system, ground)
Пример #4
0
    def test_chaining(self):
        outputs = romanesco.run(self.analysis,
                                inputs={
                                    "a": {
                                        "format": "rows",
                                        "data": {
                                            "fields": ["a", "b"],
                                            "rows": [{
                                                "a": 1,
                                                "b": 2
                                            }]
                                        }
                                    },
                                    "b": {
                                        "format": "rows",
                                        "data": {
                                            "fields": ["a", "b"],
                                            "rows": [{
                                                "a": 3,
                                                "b": 4
                                            }]
                                        }
                                    }
                                },
                                outputs={"c": {
                                    "format": "rows"
                                }})

        outputs = romanesco.run(self.analysis,
                                inputs={
                                    "a": outputs["c"],
                                    "b": {
                                        "format": "rows",
                                        "data": {
                                            "fields": ["a", "b"],
                                            "rows": [{
                                                "a": 5,
                                                "b": 6
                                            }]
                                        }
                                    }
                                },
                                outputs={"c": {
                                    "format": "rows"
                                }})
        self.assertEqual(outputs["c"]["format"], "rows")
        self.assertEqual(
            outputs["c"]["data"], {
                "fields": ["a", "b"],
                "rows": [{
                    "a": 1,
                    "b": 2
                }, {
                    "a": 3,
                    "b": 4
                }, {
                    "a": 5,
                    "b": 6
                }]
            })
Пример #5
0
    def test_kwargs_debug(self):
        """Runs the table json test but with asserts for kwarg debugging"""
        global _tmpfiles

        romanesco.run(self.analysis, self.inputs, self.outputs, debug=True)

        # Should have generated serveral files ()
        self.assertGreater(len(_tmpfiles), 1)
Пример #6
0
 def test_function(self):
     outputs = romanesco.run(
         self.function_out,
         inputs={},
         outputs={"output": {"format": "object"}})
     self.assertEqual(outputs["output"]["data"](3)[0], 9)
     outputs = romanesco.run(
         self.function_in, inputs={"input": outputs["output"]})
     self.assertEqual(outputs["output"]["data"], 16)
Пример #7
0
 def test_function(self):
     outputs = romanesco.run(self.function_out,
                             inputs={},
                             outputs={"output": {
                                 "format": "object"
                             }})
     self.assertEqual(outputs["output"]["data"](3)[0], 9)
     outputs = romanesco.run(self.function_in,
                             inputs={"input": outputs["output"]})
     self.assertEqual(outputs["output"]["data"], 16)
Пример #8
0
    def testInlineFilepath(self):
        task = {
            'mode': 'python',
            'script': """
fname = file
with open(file) as f:
    out = f.read()
""",
            'inputs': [{
                'id': 'file',
                'format': 'text',
                'type': 'string',
                'target': 'filepath'
            }],
            'outputs': [
                {
                    'id': 'out',
                    'format': 'text',
                    'type': 'string'
                },
                {
                    'id': 'fname',
                    'format': 'text',
                    'type': 'string'
                }
            ]
        }

        # Test filepath input
        inputs = {
            'file': {
                'data': 'a,b,c\n1,2,3\n',
                'format': 'text',
                'type': 'string'
            }
        }

        outputs = romanesco.run(task, inputs)
        self.assertEqual(outputs['out']['data'], 'a,b,c\n1,2,3\n')

        # Test filepath input with filename specified
        task['inputs'][0]['filename'] = 'file.csv'

        inputs = {
            'file': {
                'data': 'a,b,c\n1,2,3\n',
                'format': 'text',
                'type': 'string'
            }
        }

        outputs = romanesco.run(task, inputs)
        self.assertEqual(outputs['out']['data'], 'a,b,c\n1,2,3\n')
        self.assertEqual(outputs['fname']['data'][-8:], 'file.csv')
Пример #9
0
    def test_kwargs_debug(self):
        """Runs the table json test but with asserts for kwarg debugging"""
        global _tmpfiles

        romanesco.run(self.analysis,
                      self.inputs,
                      self.outputs,
                      write_script=True)

        # Should have generated serveral files ()
        self.assertGreater(len(_tmpfiles), 1)
Пример #10
0
    def test_analysis_debug(self):
        """Runs the table json test but with asserts for analysis debugging"""
        global _tmpfiles

        romanesco.run(dict(self.analysis.items() + [("write_script", 1)]),
                      inputs=self.inputs,
                      outputs=self.outputs)

        # Should have generated just one debug file
        self.assertEquals(len(_tmpfiles), 1)

        # File contents equals script
        with open(_tmpfiles[0], "r") as fh:
            self.assertEquals(fh.read(), self.script)
Пример #11
0
    def test_array(self):
        outputs = romanesco.run(
            self.array_out,
            inputs={},
            outputs={"output": {"format": "serialized"}})
        self.assertEqual('\n'.join(outputs["output"]["data"].split('\n')[3:]),
                         "131840\n14\n3\n1\n2\n3\n")

        outputs = romanesco.run(
            self.array_in,
            inputs={"input": outputs["output"]},
            outputs={"output": {"format": "serialized"}})
        self.assertEqual('\n'.join(outputs["output"]["data"].split('\n')[3:]),
                         "131840\n14\n5\n1\n2\n3\n4\n5\n")
Пример #12
0
    def test_analysis_debug(self):
        """Runs the table json test but with asserts for analysis debugging"""
        global _tmpfiles

        romanesco.run(dict(self.analysis.items() + [("debug", 1)]),
                      inputs=self.inputs,
                      outputs=self.outputs)

        # Should have generated just one debug file
        self.assertEquals(len(_tmpfiles), 1)

        # File contents equals script
        with open(_tmpfiles[0], "r") as fh:
            self.assertEquals(fh.read(), self.script)
Пример #13
0
 def test_pgls(self):
     pgls = romanesco.load(os.path.join(self.arbor_path, "pgls.json"))
     tree_file = os.path.join("data", "anolis.phy")
     table_file = os.path.join("data", "anolisDataAppended.csv")
     romanesco.run(
         pgls,
         {
             "tree": {"format": "newick", "url": "file://" + tree_file},
             "table": {"format": "csv", "url": "file://" + table_file},
             "correlation": {"format": "text", "data": "BM"},
             "ind_variable": {"format": "text", "data": "SVL"},
             "dep_variable": {"format": "text", "data": "PCI_limbs"}
         }
     )
Пример #14
0
 def test_cont2disc(self):
     cont2disc = romanesco.load(
         os.path.join(self.arbor_path, "continuous_to_discrete.json"))
     table_file = os.path.join("data", "anolisDataAppended.csv")
     romanesco.run(
         cont2disc,
         {
             "table": {"format": "csv", "url": "file://" + table_file},
             "column": {"format": "text", "data": "SVL"},
             "thresh": {"format": "number", "data": 3.5}
         },
         {
             "newtable": {"format": "rows"}
         }
     )
Пример #15
0
    def testCreateZip(self):
        task = {
            "inputs": [{
                "id": "myArchive",
                "type": "directory",
                "format": "zip"
            }],
            "outputs": [{
                "id": "output",
                "type": "string",
                "format": "text"
            }],
            "script": "output = myArchive",
            "mode": "python"
        }

        outputs = romanesco.run(task, inputs={
            "myArchive": {
                "format": "path",
                "data": self.createFromDir
            }
        })

        path = outputs['output']['data']
        self.assertEqual(path, os.path.join(DATA_DIR, 'shapefile.zip'))
        self.assertTrue(os.path.isfile(path))
        with zipfile.ZipFile(path, 'r') as zf:
            names = zf.namelist()
            self.assertTrue('shapefile/shapefile.cpg' in names)
            self.assertTrue('shapefile/shapefile.prj' in names)
Пример #16
0
    def testJsonToSparkRdd(self):
        analysis = {
            'name': 'reduce',
            'inputs': [{
                'name': 'a',
                'type': 'collection',
                'format': 'spark.rdd'
            }],
            'outputs': [{
                'name': 'b',
                'type': 'number',
                'format': 'number'
            }],
            'mode': 'spark.python',
            'spark_conf': {
                'spark.app.name': 'test_add',
                'spark.master': os.environ['SPARK_TEST_MASTER_URL']
            }
        }

        with open('data/spark_add_script.py', 'r') as fp:
            script = fp.read()
            analysis['script'] = script

        outputs = romanesco.run(
            analysis, {'a': {
                'format': 'json',
                'data': '[1,2,3,4,5,6,7,8,9]'
            }}, {'b': {
                'format': 'number'
            }})

        expected = {'b': {'data': 45, 'format': 'number'}}
        self.assertEqual(outputs, expected)
Пример #17
0
 def test_bson(self):
     import pymongo
     outputs = romanesco.run(self.analysis,
                             inputs={
                                 "a": {
                                     "format": "objectlist.bson",
                                     "mode": "mongodb",
                                     "db": "test",
                                     "collection": "a"
                                 },
                                 "b": {
                                     "format": "objectlist.bson",
                                     "mode": "mongodb",
                                     "db": "test",
                                     "collection": "b"
                                 }
                             },
                             outputs={
                                 "c": {
                                     "format": "objectlist.bson",
                                     "mode": "mongodb",
                                     "db": "test",
                                     "collection": "temp"
                                 }
                             })
     self.assertEqual(outputs["c"]["format"], "objectlist.bson")
     coll = pymongo.MongoClient("mongodb://localhost")["test"]["temp"]
     self.assertEqual([d for d in coll.find()], [self.aobj, self.bobj])
Пример #18
0
    def test_sniffer(self):
        output = romanesco.convert(
            "table",
            {
                "format": "csv",
                "url": "file://" + os.path.join("data", "test.csv")
            },
            {"format": "rows"}
        )
        self.assertEqual(len(output["data"]["fields"]), 32)
        self.assertEqual(output["data"]["fields"][:3], [
            "FACILITY", "ADDRESS", "DATE OF INSPECTION"
        ])
        self.assertEqual(len(output["data"]["rows"]), 14)

        flu = romanesco.load(os.path.join(
            self.analysis_path, "xdata", "flu.json"))

        output = romanesco.run(
            flu,
            inputs={},
            outputs={"data": {"type": "table", "format": "rows"}}
        )
        self.assertEqual(output["data"]["data"]["fields"][:3], [
            "Date", "United States", "Alabama"
        ])
Пример #19
0
    def run_basic_task(self, inputs):
        """Run a basic task with pickle types."""
        script = '''
c = a * b
d = b + b
'''
        task = {
            'inputs': [{
                'name': 'a',
                'type': 'python',
                'format': 'object'
            }, {
                'name': 'b',
                'type': 'python',
                'format': 'object'
            }],
            'outputs': [{
                'name': 'c',
                'type': 'python',
                'format': 'object'
            }, {
                'name': 'd',
                'type': 'python',
                'format': 'object'
            }],
            'script':
            script,
            'mode':
            'python'
        }
        d = run(task, inputs=inputs, outputs={'format': 'object'})
        for k, v in six.iteritems(d):
            if isinstance(v, dict):
                d[k] = v.get('data')
        return d
Пример #20
0
 def test_bson(self):
     import pymongo
     outputs = romanesco.run(
         self.analysis,
         inputs={
             "a": {
                 "format": "objectlist.bson",
                 "mode": "mongodb",
                 "db": "test",
                 "collection": "a"
             },
             "b": {
                 "format": "objectlist.bson",
                 "mode": "mongodb",
                 "db": "test",
                 "collection": "b"
             }
         },
         outputs={
             "c": {
                 "format": "objectlist.bson",
                 "mode": "mongodb",
                 "db": "test",
                 "collection": "temp"
             }
         })
     self.assertEqual(outputs["c"]["format"], "objectlist.bson")
     coll = pymongo.MongoClient("mongodb://localhost")["test"]["temp"]
     self.assertEqual([d for d in coll.find()], [self.aobj, self.bobj])
Пример #21
0
 def test_r_dataframe(self):
     outputs = romanesco.run(self.analysis_r,
                             inputs={
                                 "a": {
                                     "format": "rows",
                                     "data": {
                                         "fields": ["aa", "bb"],
                                         "rows": [{
                                             "aa": 1,
                                             "bb": 2
                                         }]
                                     }
                                 }
                             },
                             outputs={"b": {
                                 "format": "rows"
                             }})
     self.assertEqual(outputs["b"]["format"], "rows")
     self.assertEqual(outputs["b"]["data"], {
         "fields": ["aa", "bb"],
         "rows": [{
             "aa": 1,
             "bb": 2
         }]
     })
Пример #22
0
    def testDefaultInline(self):
        task = {
            'mode': 'python',
            'script': 'b = a ** 2',
            'inputs': [{
                'id': 'a',
                'format': 'number',
                'type': 'number'
            }],
            'outputs': [{
                'id': 'b',
                'format': 'number',
                'type': 'number'
            }]
        }

        # Mode should default to "inline" if data key is set
        inputs = {
            'a': {
                'data': 5,
                'format': 'number',
                'type': 'number'
            }
        }

        outputs = romanesco.run(task, inputs)
        self.assertEqual(outputs['b']['data'], 25)
Пример #23
0
    def test_array(self):
        outputs = romanesco.run(self.array_out,
                                inputs={},
                                outputs={"output": {
                                    "format": "serialized"
                                }})
        self.assertEqual('\n'.join(outputs["output"]["data"].split('\n')[3:]),
                         "131840\n14\n3\n1\n2\n3\n")

        outputs = romanesco.run(self.array_in,
                                inputs={"input": outputs["output"]},
                                outputs={"output": {
                                    "format": "serialized"
                                }})
        self.assertEqual('\n'.join(outputs["output"]["data"].split('\n')[3:]),
                         "131840\n14\n5\n1\n2\n3\n4\n5\n")
Пример #24
0
    def testCreateZip(self):
        task = {
            "inputs": [{
                "id": "myArchive",
                "type": "directory",
                "format": "zip"
            }],
            "outputs": [{
                "id": "output",
                "type": "string",
                "format": "text"
            }],
            "script": "output = myArchive",
            "mode": "python"
        }

        outputs = romanesco.run(task,
                                inputs={
                                    "myArchive": {
                                        "format": "path",
                                        "data": self.createFromDir
                                    }
                                })

        path = outputs['output']['data']
        self.assertEqual(path, os.path.join(DATA_DIR, 'shapefile.zip'))
        self.assertTrue(os.path.isfile(path))
        with zipfile.ZipFile(path, 'r') as zf:
            names = zf.namelist()
            self.assertTrue('shapefile/shapefile.cpg' in names)
            self.assertTrue('shapefile/shapefile.prj' in names)
Пример #25
0
 def test_base64(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={
             "a": {"format": "png.base64", "data": self.image},
         })
     self.assertEqual(outputs["pixels"]["format"], "number")
     self.assertEqual(outputs["pixels"]["data"], 256)
Пример #26
0
 def test_newick(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={"a": {"format": "newick", "data": self.newick}},
         outputs={"b": {"format": "newick"}}
     )
     self.assertEqual(outputs["b"]["format"], "newick")
     self.assertEqual(outputs["b"]["data"], self.newick)
Пример #27
0
 def test_newick(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={"a": {"format": "newick", "data": self.newick}},
         outputs={"b": {"format": "newick"}}
     )
     self.assertEqual(outputs["b"]["format"], "newick")
     self.assertEqual(outputs["b"]["data"], self.newick)
Пример #28
0
 def test_r_apetree(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={"a": {"format": "newick", "data": self.newick}},
         outputs={"b": {"format": "r.apetree"}},
     )
     self.assertEqual(outputs["b"]["format"], "r.apetree")
     self.assertEqual(str(outputs["b"]["data"])[:52], "\nPhylogenetic tree with 3 tips and 2 internal nodes.")
Пример #29
0
 def test_mammal_tree(self):
     mammal = romanesco.load(
         os.path.join("data", "Mammal tree extraction.json"))
     romanesco.run(
         mammal,
         {
             "table": {
                 "format": "csv",
                 "url": "file://" +
                        os.path.join("data", "mammal_lnMass_tiny.csv")
             },
             "outRowCount": {"format": "number", "data": 19}
         },
         {
             "tree": {"format": "nested"}
         }
     )
Пример #30
0
 def test_mammal_tree(self):
     mammal = romanesco.load(
         os.path.join("data", "Mammal tree extraction.json"))
     romanesco.run(
         mammal, {
             "table": {
                 "format":
                 "csv",
                 "url":
                 "file://" + os.path.join("data", "mammal_lnMass_tiny.csv")
             },
             "outRowCount": {
                 "format": "number",
                 "data": 19
             }
         }, {"tree": {
             "format": "nested"
         }})
Пример #31
0
    def test_workflow(self):
        outputs = romanesco.run(
            self.workflow,
            inputs={
                "x": {"format": "json", "data": "1"},
                "y": {"format": "number", "data": 2}
            })
        self.assertEqual(outputs["result"]["format"], "number")
        self.assertEqual(outputs["result"]["data"], (1+3)*(2+2))

        # Test using the default value for x (10).
        outputs = romanesco.run(
            self.workflow,
            inputs={
                "y": {"format": "number", "data": 2}
            })
        self.assertEqual(outputs["result"]["format"], "number")
        self.assertEqual(outputs["result"]["data"], (10+3)*(2+2))
Пример #32
0
 def test_multi_input(self):
     outputs = romanesco.run(
         self.multi_input,
         inputs={
             "x": {"format": "number", "data": 2},
             "y": {"format": "number", "data": 3}
         })
     self.assertEqual(outputs["result"]["format"], "number")
     self.assertEqual(outputs["result"]["data"], (2*2)+(3*3))
Пример #33
0
    def run(*pargs, **kwargs):
        jobInfo = kwargs.pop('jobInfo', {})
        retval = 0

        with JobManager(logPrint=jobInfo.get('logPrint', True),
                        url=jobInfo.get('url'), method=jobInfo.get('method'),
                        headers=jobInfo.get('headers')):
            retval = romanesco.run(*pargs, **kwargs)
        return retval
Пример #34
0
    def test_workflow(self):
        outputs = romanesco.run(
            self.workflow,
            inputs={
                "x": {"format": "json", "data": "1"},
                "y": {"format": "number", "data": 2}
            })
        self.assertEqual(outputs["result"]["format"], "number")
        self.assertEqual(outputs["result"]["data"], (1+3)*(2+2))

        # Test using the default value for x (10).
        outputs = romanesco.run(
            self.workflow,
            inputs={
                "y": {"format": "number", "data": 2}
            })
        self.assertEqual(outputs["result"]["format"], "number")
        self.assertEqual(outputs["result"]["data"], (10+3)*(2+2))
Пример #35
0
def run(node=None, graph=None):
    """Computes the centrality of ``node`` (given by key) within the subgraph
    represented by ``graph`` (which is in Clique-Mongo format."""

    output = romanesco.run(betweenness_centrality, inputs={'G': {'format': 'clique.json',
                                                                 'data': graph},
                                                           'node': {'format': 'text',
                                                                    'data': node}})
    return output["measure"]["data"]
Пример #36
0
 def test_multi_input(self):
     outputs = romanesco.run(
         self.multi_input,
         inputs={
             "x": {"format": "number", "data": 2},
             "y": {"format": "number", "data": 3}
         })
     self.assertEqual(outputs["result"]["format"], "number")
     self.assertEqual(outputs["result"]["data"], (2*2)+(3*3))
Пример #37
0
 def test_base64(self):
     outputs = romanesco.run(self.analysis,
                             inputs={
                                 "a": {
                                     "format": "png.base64",
                                     "data": self.image
                                 },
                             })
     self.assertEqual(outputs["pixels"]["format"], "number")
     self.assertEqual(outputs["pixels"]["data"], 256)
Пример #38
0
 def test_json(self):
     outputs = romanesco.run(self.analysis,
                             inputs=self.test_input,
                             outputs={"c": {
                                 "format": "rows.json"
                             }})
     self.assertEqual(outputs["c"]["format"], "rows.json")
     self.assertEqual(
         outputs["c"]["data"], '{"fields": ["aa", "bb"], '
         '"rows": [{"aa": 1, "bb": 2}, {"aa": 3, "bb": 4}]}')
Пример #39
0
    def run(*pargs, **kwargs):
        jobInfo = kwargs.pop('jobInfo', {})
        retval = 0

        with JobManager(logPrint=jobInfo.get('logPrint', True),
                        url=jobInfo.get('url'), method=jobInfo.get('method'),
                        headers=jobInfo.get('headers')) as jm:
            kwargs['_job_manager'] = jm
            retval = romanesco.run(*pargs, **kwargs)
        return retval
Пример #40
0
 def test_r_apetree(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={"a": {"format": "newick", "data": self.newick}},
         outputs={"b": {"format": "r.apetree"}}
     )
     self.assertEqual(outputs["b"]["format"], "r.apetree")
     self.assertEqual(
         str(outputs["b"]["data"])[:52],
         '\nPhylogenetic tree with 3 tips and 2 internal nodes.')
Пример #41
0
    def test_r(self):
        outputs = romanesco.run(
            self.analysis_r,
            inputs={"a": {"format": "newick", "data": self.newick}},
            outputs={"b": {"format": "newick"}},
        )
        self.assertEqual(outputs["b"]["format"], "newick")
        self.assertEqual(outputs["b"]["data"], self.newick)

        outputs = romanesco.run(
            self.analysis_r, inputs={"a": {"format": "nexus", "data": self.nexus}}, outputs={"b": {"format": "nexus"}}
        )
        self.assertEqual(outputs["b"]["format"], "nexus")

        # Ignore spaces vs. tabs, and skip timestamp comment on line 2
        out = "\n".join(outputs["b"]["data"].splitlines()[2:])
        out = " ".join(out.split())
        expected = "\n".join(self.nexus.splitlines()[2:])
        expected = " ".join(expected.split())
        self.assertEqual(out, expected)
Пример #42
0
 def test_json(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={
             "a": {"format": "json", "data": '"hi, "'},
             "b": {"format": "json", "data": '"there"'}
         },
         outputs={
             "c": {"format": "json"}
         })
     self.assertEqual(outputs["c"]["format"], "json")
     self.assertEqual(outputs["c"]["data"], '"hi, there"')
Пример #43
0
 def test_text(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={
             "a": {"format": "text", "data": "hi, "},
             "b": {"format": "text", "data": "there"}
         },
         outputs={
             "c": {"format": "text"}
         })
     self.assertEqual(outputs["c"]["format"], "text")
     self.assertEqual(outputs["c"]["data"], "hi, there")
Пример #44
0
 def test_cont2disc(self):
     cont2disc = romanesco.load(
         os.path.join(self.arbor_path, "continuous_to_discrete.json"))
     table_file = os.path.join("data", "anolisDataAppended.csv")
     romanesco.run(
         cont2disc, {
             "table": {
                 "format": "csv",
                 "url": "file://" + table_file
             },
             "column": {
                 "format": "text",
                 "data": "SVL"
             },
             "thresh": {
                 "format": "number",
                 "data": 3.5
             }
         }, {"newtable": {
             "format": "rows"
         }})
Пример #45
0
 def test_json(self):
     outputs = romanesco.run(
         self.analysis,
         inputs=self.test_input,
         outputs={
             "c": {"format": "rows.json"}
         })
     self.assertEqual(outputs["c"]["format"], "rows.json")
     self.assertEqual(
         outputs["c"]["data"],
         '{"fields": ["aa", "bb"], '
         '"rows": [{"aa": 1, "bb": 2}, {"aa": 3, "bb": 4}]}')
Пример #46
0
 def test_float(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={
             "a": {"format": "number", "data": 1.5},
             "b": {"format": "number", "data": 2.5}
         },
         outputs={
             "c": {"format": "number"}
         })
     self.assertEqual(outputs["c"]["format"], "number")
     self.assertEqual(outputs["c"]["data"], 4)
    def testContourAnalysis(self):
        """
        Test contour analysis
        """
        inputs =  {
            'host': {
                'format': 'json',
                'data': 'localhost'
            },
            'port': {
                'format': 'json',
                'data': girder_port
            },
            'token': {
                'format': 'json',
                'data': self._client.token
            },
            'fileId': {
                'format': 'json',
                'data': self._dataset_file_id
            },
            'variable': {
                'format': 'json',
                'data': 'pr'
            },
            'timestep': {
                'format': 'number',
                'data': 0
            }
        }

        outputs =  {
            'result': {
                'format': 'json'
            }
        }

        analysis = self._analysis['meta']['analysis']
        result = romanesco.run(analysis, inputs=inputs, outputs=outputs)
        output_item_id = str(result['output_item_id']['data'])

        # Download the item and check it what we expect
        path = '/item/%s/download' % output_item_id
        response = self.request(path=path, method='GET', user=self._user)
        self.assertStatusOk(response)

        data_path = os.path.join(os.path.dirname(__file__), 'data', 'expected_contour.json' )


        with open(data_path, 'r') as fp:
            expected_result = json.load(fp)

        self.assertEquals(response.json, expected_result, 'Unexpected result')
Пример #48
0
 def test_cone(self):
     outputs = romanesco.run(
         self.cone,
         inputs={
             "resolution": {"format": "number", "data": 100},
             "radius": {"format": "number", "data": 1}
         })
     self.assertEqual(outputs["cone"]["format"], "vtkpolydata")
     cone = outputs["cone"]["data"]
     self.assertTrue(isinstance(cone, vtk.vtkPolyData))
     self.assertEqual(cone.GetNumberOfCells(), 101)
     self.assertEqual(cone.GetNumberOfPoints(), 101)
Пример #49
0
 def test_json(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={
             "a": {"format": "json", "data": "1"},
             "b": {"format": "json", "data": "2"}
         },
         outputs={
             "c": {"format": "json"}
         })
     self.assertEqual(outputs["c"]["format"], "json")
     self.assertEqual(outputs["c"]["data"], "3")
Пример #50
0
    def testMagicVariables(self):
        task = {
            'outputs': [{
                'id': '_tempdir',
                'type': 'string',
                'format': 'text'
            }],
            'script': ''
        }

        outputs = romanesco.run(task)
        self.assertTrue('_tempdir' in outputs)
        self.assertRegexpMatches(outputs['_tempdir']['data'], _tmp + '.+')
Пример #51
0
    def test_r(self):
        outputs = romanesco.run(
            self.analysis_r,
            inputs={"a": {"format": "newick", "data": self.newick}},
            outputs={"b": {"format": "newick"}}
        )
        self.assertEqual(outputs["b"]["format"], "newick")
        self.assertEqual(outputs["b"]["data"], self.newick)

        outputs = romanesco.run(
            self.analysis_r,
            inputs={"a": {"format": "nexus", "data": self.nexus}},
            outputs={"b": {"format": "nexus"}}
        )
        self.assertEqual(outputs["b"]["format"], "nexus")

        # Ignore spaces vs. tabs, and skip timestamp comment on line 2
        out = "\n".join(outputs["b"]["data"].splitlines()[2:])
        out = " ".join(out.split())
        expected = "\n".join(self.nexus.splitlines()[2:])
        expected = " ".join(expected.split())
        self.assertEqual(out, expected)
Пример #52
0
 def test_tsv(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={
             "a": {"format": "csv", "data": 'a,b,c\n1,2,3'},
             "b": {"format": "tsv", "data": 'a\tb\tc\n4\t5\t6'}
         },
         outputs={
             "c": {"format": "tsv"}
         })
     self.assertEqual(outputs["c"]["format"], "tsv")
     self.assertEqual(outputs["c"]["data"].splitlines(),
                      ["a\tb\tc", "1\t2\t3", "4\t5\t6"])
Пример #53
0
 def test_unicode(self):
     outputs = romanesco.run(
         self.analysis,
         inputs={
             "a": {"format": "text", "data": u"hi, "},
             "b": {"format": "text", "data": u"there"}
         },
         outputs={
             "c": {"format": "text"}
         })
     self.assertEqual(outputs["c"]["format"], "text")
     self.assertEqual(outputs["c"]["data"], u"hi, there")
     self.assertIsInstance(outputs["c"]["data"], unicode)
Пример #54
0
 def test_vtktable(self):
     outputs = romanesco.run(self.analysis,
                             inputs=self.test_input,
                             outputs={"c": {
                                 "format": "vtktable"
                             }})
     self.assertEqual(outputs["c"]["format"], "vtktable")
     t = outputs["c"]["data"]
     self.assertEqual(t.GetNumberOfRows(), 2)
     self.assertEqual(t.GetNumberOfColumns(), 2)
     self.assertEqual(t.GetValueByName(0, "aa"), 1)
     self.assertEqual(t.GetValueByName(1, "aa"), 3)
     self.assertEqual(t.GetValueByName(0, "bb"), 2)
     self.assertEqual(t.GetValueByName(1, "bb"), 4)
Пример #55
0
 def test_file(self):
     tmp = tempfile.mktemp()
     outputs = romanesco.run(
         self.analysis,
         inputs=self.test_input,
         outputs={"c": {
             "format": "csv",
             "path": tmp,
             "mode": "local"
         }})
     with open(tmp, 'r') as fp:
         output = fp.read()
     os.remove(tmp)
     self.assertEqual(outputs["c"]["format"], "csv")
     self.assertEqual(output.splitlines(), ["aa,bb", "1,2", "3,4"])
Пример #56
0
    def testExtractTgz(self):
        outputs = romanesco.run(
            self.extractTask,
            inputs={"myDir": {
                "format": "tgz",
                "data": self.tarFile
            }})

        self.assertEqual(set(outputs['files']['data']),
                         set(('provision.retry', 'site.retry')))
        self.assertEqual(outputs['myDir']['data'], self.tarDir)
        self.assertTrue(os.path.isdir(self.tarDir))
        self.assertTrue(os.path.isfile(os.path.join(self.tarDir,
                                                    'site.retry')))
        self.assertTrue(
            os.path.isfile(os.path.join(self.tarDir, 'provision.retry')))
Пример #57
0
 def test_json(self):
     outputs = romanesco.run(self.analysis,
                             inputs={
                                 "a": {
                                     "format": "json",
                                     "data": '"hi, "'
                                 },
                                 "b": {
                                     "format": "json",
                                     "data": '"there"'
                                 }
                             },
                             outputs={"c": {
                                 "format": "json"
                             }})
     self.assertEqual(outputs["c"]["format"], "json")
     self.assertEqual(outputs["c"]["data"], '"hi, there"')
Пример #58
0
 def test_json(self):
     outputs = romanesco.run(self.analysis,
                             inputs={
                                 "a": {
                                     "format": "json",
                                     "data": "1"
                                 },
                                 "b": {
                                     "format": "json",
                                     "data": "2"
                                 }
                             },
                             outputs={"c": {
                                 "format": "json"
                             }})
     self.assertEqual(outputs["c"]["format"], "json")
     self.assertEqual(outputs["c"]["data"], "3")
Пример #59
0
 def test_float(self):
     outputs = romanesco.run(self.analysis,
                             inputs={
                                 "a": {
                                     "format": "number",
                                     "data": 1.5
                                 },
                                 "b": {
                                     "format": "number",
                                     "data": 2.5
                                 }
                             },
                             outputs={"c": {
                                 "format": "number"
                             }})
     self.assertEqual(outputs["c"]["format"], "number")
     self.assertEqual(outputs["c"]["data"], 4)
Пример #60
0
 def test_cone(self):
     outputs = romanesco.run(self.cone,
                             inputs={
                                 "resolution": {
                                     "format": "number",
                                     "data": 100
                                 },
                                 "radius": {
                                     "format": "number",
                                     "data": 1
                                 }
                             })
     self.assertEqual(outputs["cone"]["format"], "vtkpolydata")
     cone = outputs["cone"]["data"]
     self.assertTrue(isinstance(cone, vtk.vtkPolyData))
     self.assertEqual(cone.GetNumberOfCells(), 101)
     self.assertEqual(cone.GetNumberOfPoints(), 101)