Ejemplo n.º 1
0
 def setUp(self) -> None:
     """Test up the test cases with the third basic example."""
     msdf1 = read_sssom_table(f"{data_dir}/basic.tsv")
     msdf2 = read_sssom_table(f"{data_dir}/basic2.tsv")
     msdf3 = read_sssom_table(f"{data_dir}/basic3.tsv")
     self.msdf = msdf1
     self.msdfs = [msdf1, msdf2, msdf3]
Ejemplo n.º 2
0
    def test_merge(self):
        """Test merging two tables."""
        msdf1 = read_sssom_table(data_dir / "basic.tsv")
        msdf2 = read_sssom_table(data_dir / "basic2.tsv")
        merged_msdf = merge_msdf(msdf1, msdf2)

        self.assertEqual(71, len(merged_msdf.df))
Ejemplo n.º 3
0
    def test_merge_no_reconcile(self):
        """Test merging two tables without reconciliation."""
        msdf1 = read_sssom_table(data_dir / "basic4.tsv")
        msdf2 = read_sssom_table(data_dir / "basic5.tsv")

        merged_msdf = merge_msdf(msdf1, msdf2, reconcile=False)

        self.assertEqual(53, len(msdf1.df))
        self.assertEqual(53, len(msdf2.df))
        self.assertEqual(len(merged_msdf.df), (len(msdf1.df) + len(msdf2.df)))
Ejemplo n.º 4
0
 def test_read_sssom_table(self):
     """Test read SSSOM method to validate import of all columns."""
     input_path = os.path.join(test_data_dir, "basic3.tsv")
     msdf = read_sssom_table(input_path)
     imported_df = pd.read_csv(input_path, comment="#", sep="\t")
     imported_df = sort_df_rows_columns(imported_df)
     self.assertEqual(set(imported_df.columns), set(msdf.df.columns))
     list_cols = [
         "subject_match_field",
         "object_match_field",
         "match_string",
         "match_type",
     ]
     for idx, row in msdf.df.iterrows():
         for k, v in row.iteritems():
             if v == "":
                 self.assertTrue(math.isnan(imported_df.iloc[idx][k]))
             else:
                 if k not in list_cols:
                     if v is np.nan:
                         self.assertTrue(imported_df.iloc[idx][k] is v)
                     else:
                         self.assertEqual(imported_df.iloc[idx][k], v)
                 elif k == "match_type":
                     self.assertEqual(imported_df.iloc[idx][k], v)
                 else:
                     self.assertEqual(imported_df.iloc[idx][k], v)
Ejemplo n.º 5
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.",
     )
Ejemplo n.º 6
0
 def test_piped_element_to_list(self):
     """Test for multi-valued element (piped in SSSOM tables) to list."""
     input_path = os.path.join(test_data_dir, "basic.tsv")
     msdf = read_sssom_table(input_path)
     df = msdf.df
     msdf.df = df[df["match_type"].str.contains("\\|", na=False)].reset_index()
     old_match_type = msdf.df["match_type"]
     msdoc = to_mapping_set_document(msdf)
     new_msdf = to_mapping_set_dataframe(msdoc)
     new_match_type = new_msdf.df["match_type"]
     self.assertTrue(old_match_type.equals(new_match_type))
Ejemplo n.º 7
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.",
     )
Ejemplo n.º 8
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.",
     )
Ejemplo n.º 9
0
    def test_reconcile_prefix(self):
        """Test curie reconciliation is performing as expected."""
        msdf = read_sssom_table(data_dir / "basic3.tsv")

        with open(prefix_recon_yaml) as pref_rec:
            prefix_reconciliation = yaml.safe_load(pref_rec)

        recon_msdf = reconcile_prefix_and_data(msdf, prefix_reconciliation)

        prefix_expansion = prefix_reconciliation[
            "prefix_expansion_reconciliation"]

        for pfx, exp in prefix_expansion.items():
            if pfx in recon_msdf.prefix_map.keys():
                self.assertEqual(recon_msdf.prefix_map[pfx], exp)
Ejemplo n.º 10
0
 def setUp(self) -> None:
     """Test up the test cases with the third basic example."""
     self.msdf = read_sssom_table(f"{data_dir}/basic6.tsv")
Ejemplo n.º 11
0
 def setUp(self) -> None:
     """Set up the test case with the COB mappings et and OWL graph."""
     self.mset = read_sssom_table(data_dir / "cob-to-external.tsv")
     g = Graph()
     g.parse(os.path.join(data_dir, "cob.owl"), format="xml")
     self.graph = g
Ejemplo n.º 12
0
 def setUp(self) -> None:
     """Test up the test case with the third basic example."""
     self.msdf = read_sssom_table(data_dir / "basic3.tsv")
Ejemplo n.º 13
0
 def setUp(self) -> None:
     """Set up the test case with two tables."""
     self.msdf = read_sssom_table(data_dir / "basic.tsv")
     self.cob = read_sssom_table(data_dir / "cob-to-external.tsv")
Ejemplo n.º 14
0
 def setUp(self) -> None:
     """Set up the test case by reading the basic SSSOM example."""
     self.mset = read_sssom_table(data_dir / "basic.tsv")
Ejemplo n.º 15
0
 def setUp(self) -> None:
     """Set up the test case with a basic SSSOM example."""
     self.msdf = read_sssom_table(f"{test_data_dir}/basic.tsv")
     # self.msdf = read_sssom_table(f"{test_data_dir}/basic-simple.tsv")
     self.mapping_count = 141  # 141 for basic.tsv