def _test_to_dataframe(self, mdoc, test):
     msdf = to_mapping_set_dataframe(mdoc)
     df = to_dataframe(msdf)
     self.assertEqual(
         len(df),
         test.ct_data_frame_rows,
         f"The pandas data frame has less elements than the orginal one for {test.filename}",
     )
     df.to_csv(test.get_out_file("roundtrip.tsv"), sep="\t")
     # data = pd.read_csv(test.get_out_file("roundtrip.tsv"), sep="\t")
     data = read_pandas(test.get_out_file("roundtrip.tsv"))
     self.assertEqual(
         len(data),
         test.ct_data_frame_rows,
         f"The re-serialised pandas data frame has less elements than the orginal one for {test.filename}",
     )
     path = test.get_out_file("tsv")
     with open(path, "w") as file:
         write_table(msdf, file)
     # self._test_files_equal(test.get_out_file("tsv"), test.get_validate_file("tsv"))
     df = read_pandas(path)
     self.assertEqual(
         len(df),
         test.ct_data_frame_rows,
         f"The exported pandas data frame has less elements than the orginal one for {test.filename}",
     )
Beispiel #2
0
 def test_parse_sssom_dataframe_url(self):
     """Test parsing a TSV from a URL."""
     msdf = read_sssom_table(self.df_url)
     output_path = os.path.join(test_out_dir, "test_parse_sssom_dataframe_url.tsv")
     with open(output_path, "w") as file:
         write_table(msdf, file)
     self.assertEqual(
         len(msdf.df),
         141,
         f"{self.df_url} has the wrong number of mappings.",
     )
Beispiel #3
0
 def test_write_sssom_dataframe(self):
     """Test writing as a dataframe."""
     tmp_path = os.path.join(test_out_dir, "test_write_sssom_dataframe.tsv")
     with open(tmp_path, "w") as tmp_file:
         write_table(self.msdf, tmp_file)
     msdf = read_sssom_table(tmp_path)
     self.assertEqual(
         len(msdf.df),
         self.mapping_count,
         f"{tmp_file} has the wrong number of mappings.",
     )
Beispiel #4
0
 def test_parse_sssom_dataframe(self):
     """Test parsing a TSV."""
     input_path = f"{test_data_dir}/basic.tsv"
     msdf = read_sssom_table(input_path)
     output_path = os.path.join(test_out_dir, "test_parse_sssom_dataframe.tsv")
     with open(output_path, "w") as file:
         write_table(msdf, file)
     self.assertEqual(
         len(msdf.df),
         141,
         f"{input_path} has the wrong number of mappings.",
     )
Beispiel #5
0
 def test_parse_sssom_rdf(self):
     """Test parsing RDF."""
     msdf = from_sssom_rdf(
         g=self.rdf_graph, prefix_map=self.df_prefix_map, meta=self.metadata
     )
     path = os.path.join(test_out_dir, "test_parse_sssom_rdf.tsv")
     with open(path, "w") as file:
         write_table(msdf, file)
     self.assertEqual(
         len(msdf.df),
         136,
         f"{self.rdf_graph_file} has the wrong number of mappings.",
     )
Beispiel #6
0
 def test_parse_tsv(self):
     """Test parsing TSV."""
     msdf = from_sssom_dataframe(
         df=self.df, prefix_map=self.df_prefix_map, meta=self.df_meta
     )
     path = os.path.join(test_out_dir, "test_parse_tsv.tsv")
     with open(path, "w") as file:
         write_table(msdf, file)
     self.assertEqual(
         len(msdf.df),
         141,
         f"{self.df_file} has the wrong number of mappings.",
     )
Beispiel #7
0
 def test_parse_obographs(self):
     """Test parsing OBO Graph JSON."""
     msdf = from_obographs(
         jsondoc=self.obographs,
         prefix_map=self.prefix_map,
         meta=self.metadata,
     )
     path = os.path.join(test_out_dir, "test_parse_obographs.tsv")
     with open(path, "w") as file:
         write_table(msdf, file)
     self.assertEqual(
         len(msdf.df),
         9878,
         f"{self.obographs_file} has the wrong number of mappings.",
     )
Beispiel #8
0
 def test_parse_sssom_json(self):
     """Test parsing JSON."""
     msdf = from_sssom_json(
         jsondoc=self.json,
         prefix_map=self.df_prefix_map,
         meta=self.metadata,
     )
     path = os.path.join(test_out_dir, "test_parse_sssom_json.tsv")
     with open(path, "w") as file:
         write_table(msdf, file)
     self.assertEqual(
         len(msdf.df),
         141,
         f"{self.json_file} has the wrong number of mappings.",
     )
Beispiel #9
0
 def test_parse_alignment_minidom(self):
     """Test parsing an alignment XML."""
     msdf = from_alignment_minidom(
         dom=self.alignmentxml,
         prefix_map=self.prefix_map,
         meta=self.metadata,
     )
     path = os.path.join(test_out_dir, "test_parse_alignment_minidom.tsv")
     with open(path, "w") as file:
         write_table(msdf, file)
     self.assertEqual(
         len(msdf.df),
         646,
         f"{self.alignmentxml_file} has the wrong number of mappings.",
     )
Beispiel #10
0
    def test_write_sssom_rdf(self):
        """Test writing as RDF."""
        path_1 = os.path.join(test_out_dir, "test_write_sssom_rdf.rdf")
        with open(path_1, "w") as file:
            write_rdf(self.msdf, file)
        msdf = read_sssom_rdf(path_1, self.msdf.prefix_map)
        self.assertEqual(
            len(msdf.df),
            self.mapping_count,
            f"{path_1} has the wrong number of mappings.",
        )

        # TODO this test doesn't make sense
        path_2 = os.path.join(test_out_dir, "test_write_sssom_rdf.rdf.tsv")
        with open(path_2, "w") as file:
            write_table(self.msdf, file)