コード例 #1
0
    def test_to_from_json(self, structure_klifs_id):
        """
        Test if saving/loading a fingerprint to/from a json file.
        """

        fingerprint = Fingerprint.from_structure_klifs_id(
            structure_klifs_id, LOCAL)
        json_filepath = Path("fingerprint.json")

        with enter_temp_directory():

            # Save json file
            fingerprint.to_json(json_filepath)
            assert json_filepath.exists()

            # Load json file
            fingerprint_reloaded = Fingerprint.from_json(json_filepath)
            # Test if class attributes from ID and from json are the same
            assert fingerprint.structure_klifs_id == fingerprint_reloaded.structure_klifs_id
            assert np.allclose(
                fingerprint.values_array(True, True, True),
                fingerprint_reloaded.values_array(True, True, True),
                rtol=0,
                atol=0,
                equal_nan=True,
            )
            assert fingerprint.residue_ids == fingerprint_reloaded.residue_ids
            assert fingerprint.residue_ixs == fingerprint_reloaded.residue_ixs
コード例 #2
0
def test_from_file(
    distance_matrix_path,
    tree_path,
    annotation_path,
    clustering_method,
    similarity,
    node_means,
    tree_string,
):

    with enter_temp_directory():

        tree_nodes_calculated, node_means_calculated = tree.from_file(
            distance_matrix_path, tree_path, annotation_path,
            clustering_method, similarity)

        assert isinstance(tree_nodes_calculated, hierarchy.ClusterNode)
        assert node_means == pytest.approx(node_means_calculated, abs=1e-6)

        if tree_path:

            tree_path = Path(tree_path)
            # Tree file there?
            assert tree_path.exists()
            # Tree file correct?
            with open(tree_path, "r") as f:
                assert f.read() == tree_string
            tree_path.unlink()

        if annotation_path:

            annotation_path = Path(annotation_path)
            # Annotation file there?
            assert annotation_path.exists()
            annotation_path.unlink()
コード例 #3
0
ファイル: test_cli_encode.py プロジェクト: volkamerlab/kissim
def test_encode_from_cli(args):

    with enter_temp_directory():
        encode_from_cli(args)

        # Fingerprints JSON there?
        assert Path("fingerprints.json").exists()

        # Fingerprints LOG there?
        if platform.system() != "Windows":
            assert Path("fingerprints.log").exists()
コード例 #4
0
ファイル: test_api_encode.py プロジェクト: volkamerlab/kissim
def test_encode(
    structure_klifs_ids, fingerprints_json_filepath, local_klifs_download_path, n_cores
):

    with enter_temp_directory():
        fingerprint_generator = encode(
            structure_klifs_ids, fingerprints_json_filepath, local_klifs_download_path, n_cores
        )
        assert isinstance(fingerprint_generator, FingerprintGenerator)

        if fingerprints_json_filepath is not None:
            assert Path(fingerprints_json_filepath).exists()
コード例 #5
0
def test_weights(feature_distances_path, feature_weights,
                 fingerprint_distances_path):

    with enter_temp_directory():
        fingerprint_distances = weights(feature_distances_path,
                                        feature_weights,
                                        fingerprint_distances_path)
        assert isinstance(fingerprint_distances, FingerprintDistanceGenerator)

        if fingerprint_distances_path is not None:
            fingerprint_distances_path = Path(fingerprint_distances_path)
            assert fingerprint_distances_path.exists()
            assert fingerprint_distances_path.parent / f"{fingerprint_distances_path.stem}.log"
コード例 #6
0
    def test_to_from_csv(self, feature_distances_generator):

        with enter_temp_directory():

            filepath = Path("test.csv")

            feature_distances_generator.to_csv(filepath)
            assert filepath.exists()

            feature_distances_generator_from_csv = FeatureDistancesGenerator.from_csv(
                filepath)
            assert isinstance(feature_distances_generator_from_csv,
                              FeatureDistancesGenerator)
コード例 #7
0
def test_compare_from_cli(args):

    with enter_temp_directory():
        compare_from_cli(args)

        # Feature distances CSV there?
        assert Path("feature_distances.csv").exists()

        # Fingerprint distance CSV there?
        assert Path("fingerprint_distances.csv").exists()

        # Distances LOG there?
        if platform.system() != "Windows":
            assert Path("distances.log").exists()
コード例 #8
0
def test_main_outliers(args):
    """
    Test CLI for outliers using subprocesses.
    """

    output = Path("fingerprints_clean_test.json")
    args = args.split()

    with enter_temp_directory():
        subprocess.run(args, check=True)

        # Json file there?
        assert output.exists()
        # Log file there?
        assert Path(f"{output.stem}.log").exists()
コード例 #9
0
def test_main_weights(args):
    """
    Test CLI for outliers using subprocesses.
    """

    output = Path("fingerprint_distances_test.csv")  # See -o in CLI command
    args = args.split()

    with enter_temp_directory():
        subprocess.run(args, check=True)

        # Json file there?
        assert output.exists()
        # Log file there?
        assert Path(f"{output.stem}.log").exists()
コード例 #10
0
def test_outliers(
    fingerprints_path, distance_cutoff, fingerprints_wo_outliers_path, n_fingerprints_wo_outliers
):

    with enter_temp_directory():
        fingerprints = outliers(fingerprints_path, distance_cutoff, fingerprints_wo_outliers_path)
        assert isinstance(fingerprints, FingerprintGenerator)
        assert len(fingerprints.data) == n_fingerprints_wo_outliers

        if fingerprints_wo_outliers_path is not None:
            fingerprints_wo_outliers_path = Path(fingerprints_wo_outliers_path)
            assert fingerprints_wo_outliers_path.exists()
            assert (
                fingerprints_wo_outliers_path.parent / f"{fingerprints_wo_outliers_path.stem}.log"
            )
コード例 #11
0
def test_encode(args):
    """
    Test CLI for encoding using subprocesses.
    """

    tree_path = Path("kissim.tree")
    annotation_path = Path("kinase_annotation.csv")

    args = args.split()

    with enter_temp_directory():
        subprocess.run(args, check=True)

        # Tree file there?
        assert tree_path.exists()
        print(args)
        print("-a" in args)
        if "-a" in args:
            # Annotation file there?
            assert annotation_path.exists()
コード例 #12
0
ファイル: test_main_encode.py プロジェクト: AJK-dev/kissim
def test_main_encode(args):
    """
    Test CLI for encoding using subprocesses.
    """

    output = Path("fingerprints.json")
    args = args.split()

    with enter_temp_directory():
        subprocess.run(args, check=True)

        # Json file there?
        assert output.exists()
        # Log file there?
        assert Path(f"{output.stem}.log").exists()

        # Json file can be loaded as FingerprintGenerator object?
        fingerprint_generator = FingerprintGenerator.from_json(output)
        assert isinstance(fingerprint_generator, FingerprintGenerator)
        assert isinstance(list(fingerprint_generator.data.values())[0], Fingerprint)
コード例 #13
0
    def test_to_from_json(self, structure_klifs_ids, normalize,
                          values_array_sum):
        """
        Test if saving/loading a fingerprint to/from a json file.
        """

        fingerprints = FingerprintGenerator.from_structure_klifs_ids(
            structure_klifs_ids, LOCAL, 1)
        json_filepath = Path("fingerprints.json")

        with enter_temp_directory():

            # Save json file
            fingerprints.to_json(json_filepath)
            assert json_filepath.exists()

            # Load json file
            fingerprints_reloaded = FingerprintGenerator.from_json(
                json_filepath, normalize)

        assert isinstance(fingerprints_reloaded, FingerprintGenerator)
        # Attribute data
        assert list(fingerprints.data.keys()) == list(
            fingerprints_reloaded.data.keys())
        if normalize:
            assert list(fingerprints.data_normalized.keys()) == list(
                fingerprints_reloaded.data_normalized.keys())
        else:
            assert fingerprints_reloaded.data_normalized is None
        values_array_sum_calculated = sum([
            np.nansum(fingerprint.values_array(True, True, True))
            for structure_klifs_id, fingerprint in
            fingerprints_reloaded.data.items()
        ])
        assert pytest.approx(values_array_sum_calculated,
                             abs=1e-4) == values_array_sum
コード例 #14
0
ファイル: test_cli_encode.py プロジェクト: AJK-dev/kissim
def test_encode_from_cli(args):

    with enter_temp_directory():
        encode_from_cli(args)
        assert Path("fingerprints.json").exists()
        assert Path("fingerprints.log").exists()