Exemplo n.º 1
0
    def test_write_ex_basic(self):
        ex_file = _resource_path("basic_vessel.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("tracing_vessels_and_markers.xml")
        data = read_xml(xml_file)

        write_ex(ex_file, data)
        self.assertTrue(os.path.exists(ex_file))
Exemplo n.º 2
0
    def test_write_ex_basic_group(self):
        ex_file = _resource_path("basic_groups.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("tree_with_anatomical_terms.xml")
        data = read_xml(xml_file)

        write_ex(ex_file, data, {'external_annotation': True})
        self.assertTrue(_is_line_in_file(ex_file, " Group name: Thorasic Sympathetic Trunk"))
Exemplo n.º 3
0
    def test_write_ex_with_multi_tree_and_annotation(self):
        ex_file = _resource_path("multi_tree_with_annotations.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("multi_tree_with_annotations.xml")
        data = read_xml(xml_file)

        write_ex(ex_file, data)
        self.assertTrue(os.path.exists(ex_file))
Exemplo n.º 4
0
    def test_write_tree_with_markers(self):
        xml_file = _resource_path("tree_with_markers.xml")
        neurolucida_data = read_xml(xml_file)

        ex_file = _resource_path("tree_with_markers.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        write_ex(ex_file, neurolucida_data)
        self.assertTrue(os.path.exists(ex_file))
        self.assertTrue(_is_line_in_file(ex_file, " Group name: marker"))
Exemplo n.º 5
0
    def test_write_ex_branch(self):
        ex_file = _resource_path("multi_tree.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        tree = MBFTree('#000000', '', '', {'points': [MBFPoint(3, 3, 4, 2), [MBFPoint(2, 1, 5, 7)], [MBFPoint(2, 4, 8, 5.7)]]}, [])
        data = MBFData()
        data.add_tree(tree)

        write_ex(ex_file, data)
        self.assertTrue(os.path.exists(ex_file))
Exemplo n.º 6
0
    def test_write_ex_basic(self):
        ex_file = _resource_path("basic_tree.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        tree = MBFTree('#000000', '', '', {'points': [MBFPoint(3, 3, 4, 2), MBFPoint(2, 1, 5, 7), MBFPoint(3, 1, 4.2, 7.1)]}, [])
        data = MBFData()
        data.add_tree(tree)

        write_ex(ex_file, data)
        self.assertTrue(os.path.exists(ex_file))
Exemplo n.º 7
0
    def test_write_puncta(self):
        ex_file = _resource_path("puncta.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("puncta.xml")
        contents = read_xml(xml_file)
        write_ex(ex_file, contents)
        self.assertTrue(os.path.exists(ex_file))
        with open(ex_file) as f:
            lines = f.readlines()
            self.assertEqual(3370, len(lines))
Exemplo n.º 8
0
    def test_write_ex_basic(self):
        ex_file = _resource_path("basic_contour.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        data = MBFData()
        contour = {'colour': '#00ff00', 'rgb': [0, 1, 0], 'closed': True, 'name': 'Heart',
                   'data': [MBFPoint(3, 3, 4, 1), MBFPoint(2, 1, 5, 1),
                            MBFPoint(3, 1, 4.2, 1)],
                   'properties': []}
        data.add_contour(contour)

        write_ex(ex_file, data)
        self.assertTrue(os.path.exists(ex_file))
Exemplo n.º 9
0
    def test_read_puncta_with_set_property(self):
        ex_file = _resource_path("puncta_with_set_prop.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("puncta_with_set_prop.xml")
        contents = read_xml(xml_file)
        write_ex(ex_file, contents)
        self.assertTrue(os.path.exists(ex_file))

        self.assertTrue(_is_line_in_file(ex_file, " Group name: inner submucosal nerve plexus"))
        with open(ex_file) as f:
            lines = f.readlines()
            self.assertEqual(1055, len(lines))
Exemplo n.º 10
0
    def test_contour_multiple_properties(self):
        ex_file = _resource_path("contour_with_multiple_set_properties.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("contour_with_multiple_set_properties.xml")
        contents = read_xml(xml_file)
        self.assertEqual(1, len(contents))

        write_ex(ex_file, contents)
        self.assertTrue(os.path.exists(ex_file))

        self.assertTrue(_is_line_in_file(ex_file, " Group name: inner submucosal nerve plexus"))
        self.assertTrue(_is_line_in_file(ex_file, " Group name: Nerve fiber connecting inner submucosal nerve plexus and outer submucosal nerve plexus"))
Exemplo n.º 11
0
def main():
    options = {}
    args = parse_args()
    if os.path.exists(args.input_xml):
        if args.output_ex is None:
            output_ex = args.input_xml + '.ex'
        else:
            output_ex = args.output_ex

        options["external_annotation"] = args.external_annotation

        contents = read_xml(args.input_xml)
        if contents is None:
            sys.exit(-2)
        else:
            write_ex(output_ex, contents, options)
    else:
        sys.exit(-1)
Exemplo n.º 12
0
    def test_tree_with_trace_association(self):
        ex_file = _resource_path("tree_with_trace_association.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("tree_with_trace_association.xml")
        neurolucida_data = read_xml(xml_file)

        self.assertEqual(0, neurolucida_data.contours_count())
        self.assertEqual(0, neurolucida_data.markers_count())
        self.assertEqual(1, neurolucida_data.trees_count())

        write_ex(ex_file, neurolucida_data)
        self.assertTrue(os.path.exists(ex_file))

        self.assertTrue(_is_line_in_file(ex_file, " Group name: http://purl.org/sig/ont/fma/fma15005"))
        with open(ex_file) as f:
            lines = f.readlines()
            self.assertEqual(180, len(lines))
Exemplo n.º 13
0
    def test_tree_with_set_property(self):
        ex_file = _resource_path("tree_with_set_property.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("tree_with_set_property.xml")
        neurolucida_data = read_xml(xml_file)

        self.assertEqual(0, neurolucida_data.contours_count())
        self.assertEqual(0, neurolucida_data.markers_count())
        self.assertEqual(1, neurolucida_data.trees_count())

        write_ex(ex_file, neurolucida_data)
        self.assertTrue(os.path.exists(ex_file))

        self.assertTrue(_is_line_in_file(ex_file, " Group name: Bob"))
        self.assertTrue(_is_line_in_file(ex_file, " Group name: Dave"))
        with open(ex_file) as f:
            lines = f.readlines()
            self.assertEqual(552, len(lines))