diff --git a/latest/reference/biotest/compare_files/index.html b/latest/reference/biotest/compare_files/index.html index 985639c..9332e92 100644 --- a/latest/reference/biotest/compare_files/index.html +++ b/latest/reference/biotest/compare_files/index.html @@ -1103,7 +1103,7 @@

- 0.001 default tolerance for Orthogonal coordinates for X,Y,Z in Angstroms. """ lines1 = _read_file_or_io(file1) - lines2 = _read_file_or_io(file1) + lines2 = _read_file_or_io(file2) assert len(lines1) == len(lines2), f"{file1} and {file2} have different lengths." diff --git a/latest/search/search_index.json b/latest/search/search_index.json index c71b4a5..3f32728 100644 --- a/latest/search/search_index.json +++ b/latest/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":[" "]},"docs":[{"location":"","title":"biotest","text":"

A Python package for testing bioinformatics data. Mainly, it provides a set of functions to compare normal text/binary files, npy files, pdb files, and directories.

"},{"location":"#installation","title":"\ud83d\udee0\ufe0f Installation","text":"
pip install biotest\n
"},{"location":"#usage","title":"\ud83d\ude80 Usage","text":"

Mainly, use the API with pytest.

from biotest.compare_files import (\n    assert_two_files_equal_sha,\n    assert_two_npys_within_tolerance,\n    assert_two_pdbqt_files_within_tolerance,\n    assert_two_pdb_files_within_tolerance,\n    assert_two_dirs_within_tolerance,\n)\n\ndef assert_two_files_sha(file1: str | PathLike | IOBase, file2: str | PathLike | IOBase):\n    \"\"\"\n    Assert that two files are exactly the same.\n    \"\"\"\n    ...\n\ndef assert_two_npys_within_tolerance(\n    npy1: str | PathLike | np.ndarray, npy2: str | PathLike | np.ndarray, *, tolerance=1e-6\n):\n    \"\"\"\n    Assert that two npy files are almost the same within a tolerance.\n    \"\"\"\n    ...\n\n\ndef assert_two_pdbqt_files_within_tolerance(\n    file1: str | PathLike | IOBase, file2: str | PathLike | IOBase, *, tolerance=1e-3\n):\n    \"\"\"\n    Assert that two pdbqt files are equal under following conditions.\n\n    - ignore the trailing whitespace.\n    - 0.001 default tolerance for Orthogonal coordinates for X,Y,Z in Angstroms.\n    \"\"\"\n    ...\n\n\ndef assert_two_pdb_files_within_tolerance(\n    file1: str | PathLike | IOBase, file2: str | PathLike | IOBase, *, tolerance=1e-3\n):\n    \"\"\"\n    Assert that two pdb files are equal under following conditions.\n\n    - ignore the trailing whitespace.\n    - 0.001 default tolerance for Orthogonal coordinates for X,Y,Z in Angstroms.\n    \"\"\"\n    ...\n\n\ndef assert_two_dirs_within_tolerance(\n    dir1: str | PathLike,\n    dir2: str | PathLike,\n    *,\n    tolerance: float = 1e-3,\n    filenames_exclude: Sequence[str] | None = None,\n):\n    \"\"\"\n    Assert that two directories have the same files with almost the same content within tolerance.\n    \"\"\"\n    ...\n

Also, you can use the CLI to quickly test the functionality. These merely call the functions above, so they will print the traceback if the assertion fails.

biotest assert-two-files-equal-sha file1 file2\nbiotest assert-two-npys-within-tolerance file1.npy file2.npy\nbiotest assert-two-pdbqt-files-within-tolerance file1.pdbqt file2.pdbqt\nbiotest assert-two-pdb-files-within-tolerance file1.pdb file2.pdb\nbiotest assert-two-dirs-within-tolerance dir1 dir2\n
"},{"location":"CHANGELOG/","title":"Changelog","text":"

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

"},{"location":"CHANGELOG/#v002-2024-10-22","title":"v0.0.2 - 2024-10-22","text":""},{"location":"CHANGELOG/#refactors","title":"Refactors","text":""},{"location":"CHANGELOG/#v001-2024-10-21","title":"v0.0.1 - 2024-10-21","text":""},{"location":"CHANGELOG/#refactors_1","title":"Refactors","text":""},{"location":"reference/SUMMARY/","title":"SUMMARY","text":""},{"location":"reference/biotest/","title":"Index","text":""},{"location":"reference/biotest/compare_files/","title":" compare_files","text":""},{"location":"reference/biotest/compare_files/#biotest.compare_files.assert_two_files_equal_sha","title":"assert_two_files_equal_sha(file1, file2)","text":"

Assert that two files are exactly the same.

Source code in src/biotest/compare_files.py
def assert_two_files_equal_sha(\n    file1: str | PathLike | IOBase, file2: str | PathLike | IOBase\n):\n    \"\"\"\n    Assert that two files are exactly the same.\n    \"\"\"\n    sha1 = hashlib.sha1()\n    sha2 = hashlib.sha1()\n    sha1.update(_read_file_or_io(file1, decode=False))\n    sha2.update(_read_file_or_io(file2, decode=False))\n\n    assert (\n        sha1.hexdigest() == sha2.hexdigest()\n    ), f\"{file1} and {file2} have different SHA1 hashes.\"\n
"},{"location":"reference/biotest/compare_files/#biotest.compare_files.assert_two_npys_within_tolerance","title":"assert_two_npys_within_tolerance(npy1, npy2, *, tolerance=1e-06)","text":"

Assert that two npy files are almost the same within a tolerance.

Source code in src/biotest/compare_files.py
def assert_two_npys_within_tolerance(\n    npy1: str | PathLike | np.ndarray,\n    npy2: str | PathLike | np.ndarray,\n    *,\n    tolerance=1e-6,\n):\n    \"\"\"\n    Assert that two npy files are almost the same within a tolerance.\n    \"\"\"\n    if isinstance(npy1, str | PathLike):\n        nparray1: np.ndarray = np.load(npy1)\n    else:\n        nparray1 = npy1\n    if isinstance(npy2, str | PathLike):\n        nparray2: np.ndarray = np.load(npy2)\n    else:\n        nparray2 = npy2\n\n    assert np.allclose(nparray1, nparray2, atol=tolerance, rtol=tolerance), (\n        f\"{npy1} and {npy2} have different data.\"\n        f\" {nparray1} and {nparray2} are not close.\"\n    )\n
"},{"location":"reference/biotest/compare_files/#biotest.compare_files.assert_two_pdbqt_files_within_tolerance","title":"assert_two_pdbqt_files_within_tolerance(file1, file2, *, tolerance=0.001)","text":"

Assert that two pdbqt files are equal under following conditions.

Source code in src/biotest/compare_files.py
def assert_two_pdbqt_files_within_tolerance(\n    file1: str | PathLike | IOBase, file2: str | PathLike | IOBase, *, tolerance=1e-3\n):\n    \"\"\"\n    Assert that two pdbqt files are equal under following conditions.\n\n    - ignore the trailing whitespace.\n    - 0.001 default tolerance for Orthogonal coordinates for X,Y,Z in Angstroms.\n    \"\"\"\n    lines1 = _read_file_or_io(file1)\n    lines2 = _read_file_or_io(file1)\n\n    assert len(lines1) == len(lines2), f\"{file1} and {file2} have different lengths.\"\n\n    for line1, line2 in zip(lines1, lines2, strict=True):\n        if line1.rstrip() != line2.rstrip():\n            if line1.startswith(\"ATOM\") and line2.startswith(\"ATOM\"):\n                # Check for Orthogonal coordinates for X,Y,Z in Angstroms\n                # https://userguide.mdanalysis.org/stable/formats/reference/pdbqt.html\n                coord_1 = (\n                    float(line1[30:38]),\n                    float(line1[38:46]),\n                    float(line1[46:54]),\n                )\n                coord_2 = (\n                    float(line2[30:38]),\n                    float(line2[38:46]),\n                    float(line2[46:54]),\n                )\n\n                for c1, c2 in zip(coord_1, coord_2, strict=True):\n                    assert np.isclose(c1, c2, atol=tolerance), (\n                        f\"{file1} and {file2} have different lines.\"\n                        f\" {line1.rstrip()} and {line2.rstrip()} are not equal.\"\n                    )\n\n                line1_except_coord = line1[:30] + line1[54:]\n                line2_except_coord = line2[:30] + line2[54:]\n                assert line1_except_coord.rstrip() == line2_except_coord.rstrip(), (\n                    f\"{file1} and {file2} have different lines.\"\n                    f\" {line1.rstrip()} and {line2.rstrip()} are not equal.\"\n                )\n            else:\n                raise AssertionError(\n                    f\"{file1} and {file2} have different lines.\"\n                    f\" {line1.rstrip()} and {line2.rstrip()} are not equal.\"\n                )\n
"},{"location":"reference/biotest/compare_files/#biotest.compare_files.assert_two_pdb_files_within_tolerance","title":"assert_two_pdb_files_within_tolerance(file1, file2, *, tolerance=0.001)","text":"

Assert that two pdb files are equal under following conditions.

Note Source code in src/biotest/compare_files.py
def assert_two_pdb_files_within_tolerance(\n    file1: str | PathLike | IOBase, file2: str | PathLike | IOBase, *, tolerance=1e-3\n):\n    \"\"\"\n    Assert that two pdb files are equal under following conditions.\n\n    - ignore the trailing whitespace.\n    - 0.001 default tolerance for Orthogonal coordinates for X,Y,Z in Angstroms.\n\n    Note:\n        - Currently, the implementation is completely equal to assert_two_pdbqt_files_within_tolerance.\n        - It may change and diverge in the future, thus there are two separate functions.\n    \"\"\"\n    # ATOM    998  N   PHE B   9      18.937-159.292 -13.075  1.00 30.49           N\n    assert_two_pdbqt_files_within_tolerance(file1, file2, tolerance=tolerance)\n
"},{"location":"reference/biotest/compare_files/#biotest.compare_files.assert_two_dirs_within_tolerance","title":"assert_two_dirs_within_tolerance(dir1, dir2, *, tolerance=0.001, filenames_exclude=None)","text":"

Assert that two directories have the same files with almost the same content within tolerance.

Source code in src/biotest/compare_files.py
def assert_two_dirs_within_tolerance(\n    dir1: str | PathLike,\n    dir2: str | PathLike,\n    *,\n    tolerance: float = 1e-3,\n    filenames_exclude: set[str] | None = None,\n):\n    \"\"\"\n    Assert that two directories have the same files with almost the same content within tolerance.\n    \"\"\"\n    dir1 = Path(dir1)\n    dir2 = Path(dir2)\n    assert dir1.is_dir()\n    assert dir2.is_dir()\n\n    if filenames_exclude is None:\n        assert {path.name for path in dir1.iterdir()} == {\n            path.name for path in dir2.iterdir()\n        }\n    else:\n        assert {\n            path.name for path in dir1.iterdir() if path.name not in filenames_exclude\n        } == {\n            path.name for path in dir2.iterdir() if path.name not in filenames_exclude\n        }\n\n    for file1 in dir1.iterdir():\n        if filenames_exclude and file1.name in filenames_exclude:\n            continue\n\n        file2 = dir2 / file1.name\n\n        if file1.suffix == \".npy\":\n            assert_two_npys_within_tolerance(file1, file2, tolerance=tolerance)\n        elif file1.suffix == \".pdbqt\":\n            assert_two_pdbqt_files_within_tolerance(file1, file2, tolerance=tolerance)\n        elif file1.suffix == \".pdb\":\n            assert_two_pdb_files_within_tolerance(file1, file2, tolerance=tolerance)\n        elif file1.is_dir():\n            assert_two_dirs_within_tolerance(\n                file1, file2, tolerance=tolerance, filenames_exclude=filenames_exclude\n            )\n        else:\n            assert_two_files_equal_sha(file1, file2)\n
"},{"location":"reference/biotest/cli/","title":"Index","text":""},{"location":"reference/biotest/cli/main/","title":" main","text":""}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":[" "]},"docs":[{"location":"","title":"biotest","text":"

A Python package for testing bioinformatics data. Mainly, it provides a set of functions to compare normal text/binary files, npy files, pdb files, and directories.

"},{"location":"#installation","title":"\ud83d\udee0\ufe0f Installation","text":"
pip install biotest\n
"},{"location":"#usage","title":"\ud83d\ude80 Usage","text":"

Mainly, use the API with pytest.

from biotest.compare_files import (\n    assert_two_files_equal_sha,\n    assert_two_npys_within_tolerance,\n    assert_two_pdbqt_files_within_tolerance,\n    assert_two_pdb_files_within_tolerance,\n    assert_two_dirs_within_tolerance,\n)\n\ndef assert_two_files_sha(file1: str | PathLike | IOBase, file2: str | PathLike | IOBase):\n    \"\"\"\n    Assert that two files are exactly the same.\n    \"\"\"\n    ...\n\ndef assert_two_npys_within_tolerance(\n    npy1: str | PathLike | np.ndarray, npy2: str | PathLike | np.ndarray, *, tolerance=1e-6\n):\n    \"\"\"\n    Assert that two npy files are almost the same within a tolerance.\n    \"\"\"\n    ...\n\n\ndef assert_two_pdbqt_files_within_tolerance(\n    file1: str | PathLike | IOBase, file2: str | PathLike | IOBase, *, tolerance=1e-3\n):\n    \"\"\"\n    Assert that two pdbqt files are equal under following conditions.\n\n    - ignore the trailing whitespace.\n    - 0.001 default tolerance for Orthogonal coordinates for X,Y,Z in Angstroms.\n    \"\"\"\n    ...\n\n\ndef assert_two_pdb_files_within_tolerance(\n    file1: str | PathLike | IOBase, file2: str | PathLike | IOBase, *, tolerance=1e-3\n):\n    \"\"\"\n    Assert that two pdb files are equal under following conditions.\n\n    - ignore the trailing whitespace.\n    - 0.001 default tolerance for Orthogonal coordinates for X,Y,Z in Angstroms.\n    \"\"\"\n    ...\n\n\ndef assert_two_dirs_within_tolerance(\n    dir1: str | PathLike,\n    dir2: str | PathLike,\n    *,\n    tolerance: float = 1e-3,\n    filenames_exclude: Sequence[str] | None = None,\n):\n    \"\"\"\n    Assert that two directories have the same files with almost the same content within tolerance.\n    \"\"\"\n    ...\n

Also, you can use the CLI to quickly test the functionality. These merely call the functions above, so they will print the traceback if the assertion fails.

biotest assert-two-files-equal-sha file1 file2\nbiotest assert-two-npys-within-tolerance file1.npy file2.npy\nbiotest assert-two-pdbqt-files-within-tolerance file1.pdbqt file2.pdbqt\nbiotest assert-two-pdb-files-within-tolerance file1.pdb file2.pdb\nbiotest assert-two-dirs-within-tolerance dir1 dir2\n
"},{"location":"CHANGELOG/","title":"Changelog","text":"

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

"},{"location":"CHANGELOG/#v002-2024-10-22","title":"v0.0.2 - 2024-10-22","text":""},{"location":"CHANGELOG/#refactors","title":"Refactors","text":""},{"location":"CHANGELOG/#v001-2024-10-21","title":"v0.0.1 - 2024-10-21","text":""},{"location":"CHANGELOG/#refactors_1","title":"Refactors","text":""},{"location":"reference/SUMMARY/","title":"SUMMARY","text":""},{"location":"reference/biotest/","title":"Index","text":""},{"location":"reference/biotest/compare_files/","title":" compare_files","text":""},{"location":"reference/biotest/compare_files/#biotest.compare_files.assert_two_files_equal_sha","title":"assert_two_files_equal_sha(file1, file2)","text":"

Assert that two files are exactly the same.

Source code in src/biotest/compare_files.py
def assert_two_files_equal_sha(\n    file1: str | PathLike | IOBase, file2: str | PathLike | IOBase\n):\n    \"\"\"\n    Assert that two files are exactly the same.\n    \"\"\"\n    sha1 = hashlib.sha1()\n    sha2 = hashlib.sha1()\n    sha1.update(_read_file_or_io(file1, decode=False))\n    sha2.update(_read_file_or_io(file2, decode=False))\n\n    assert (\n        sha1.hexdigest() == sha2.hexdigest()\n    ), f\"{file1} and {file2} have different SHA1 hashes.\"\n
"},{"location":"reference/biotest/compare_files/#biotest.compare_files.assert_two_npys_within_tolerance","title":"assert_two_npys_within_tolerance(npy1, npy2, *, tolerance=1e-06)","text":"

Assert that two npy files are almost the same within a tolerance.

Source code in src/biotest/compare_files.py
def assert_two_npys_within_tolerance(\n    npy1: str | PathLike | np.ndarray,\n    npy2: str | PathLike | np.ndarray,\n    *,\n    tolerance=1e-6,\n):\n    \"\"\"\n    Assert that two npy files are almost the same within a tolerance.\n    \"\"\"\n    if isinstance(npy1, str | PathLike):\n        nparray1: np.ndarray = np.load(npy1)\n    else:\n        nparray1 = npy1\n    if isinstance(npy2, str | PathLike):\n        nparray2: np.ndarray = np.load(npy2)\n    else:\n        nparray2 = npy2\n\n    assert np.allclose(nparray1, nparray2, atol=tolerance, rtol=tolerance), (\n        f\"{npy1} and {npy2} have different data.\"\n        f\" {nparray1} and {nparray2} are not close.\"\n    )\n
"},{"location":"reference/biotest/compare_files/#biotest.compare_files.assert_two_pdbqt_files_within_tolerance","title":"assert_two_pdbqt_files_within_tolerance(file1, file2, *, tolerance=0.001)","text":"

Assert that two pdbqt files are equal under following conditions.

Source code in src/biotest/compare_files.py
def assert_two_pdbqt_files_within_tolerance(\n    file1: str | PathLike | IOBase, file2: str | PathLike | IOBase, *, tolerance=1e-3\n):\n    \"\"\"\n    Assert that two pdbqt files are equal under following conditions.\n\n    - ignore the trailing whitespace.\n    - 0.001 default tolerance for Orthogonal coordinates for X,Y,Z in Angstroms.\n    \"\"\"\n    lines1 = _read_file_or_io(file1)\n    lines2 = _read_file_or_io(file2)\n\n    assert len(lines1) == len(lines2), f\"{file1} and {file2} have different lengths.\"\n\n    for line1, line2 in zip(lines1, lines2, strict=True):\n        if line1.rstrip() != line2.rstrip():\n            if line1.startswith(\"ATOM\") and line2.startswith(\"ATOM\"):\n                # Check for Orthogonal coordinates for X,Y,Z in Angstroms\n                # https://userguide.mdanalysis.org/stable/formats/reference/pdbqt.html\n                coord_1 = (\n                    float(line1[30:38]),\n                    float(line1[38:46]),\n                    float(line1[46:54]),\n                )\n                coord_2 = (\n                    float(line2[30:38]),\n                    float(line2[38:46]),\n                    float(line2[46:54]),\n                )\n\n                for c1, c2 in zip(coord_1, coord_2, strict=True):\n                    assert np.isclose(c1, c2, atol=tolerance), (\n                        f\"{file1} and {file2} have different lines.\"\n                        f\" {line1.rstrip()} and {line2.rstrip()} are not equal.\"\n                    )\n\n                line1_except_coord = line1[:30] + line1[54:]\n                line2_except_coord = line2[:30] + line2[54:]\n                assert line1_except_coord.rstrip() == line2_except_coord.rstrip(), (\n                    f\"{file1} and {file2} have different lines.\"\n                    f\" {line1.rstrip()} and {line2.rstrip()} are not equal.\"\n                )\n            else:\n                raise AssertionError(\n                    f\"{file1} and {file2} have different lines.\"\n                    f\" {line1.rstrip()} and {line2.rstrip()} are not equal.\"\n                )\n
"},{"location":"reference/biotest/compare_files/#biotest.compare_files.assert_two_pdb_files_within_tolerance","title":"assert_two_pdb_files_within_tolerance(file1, file2, *, tolerance=0.001)","text":"

Assert that two pdb files are equal under following conditions.

Note Source code in src/biotest/compare_files.py
def assert_two_pdb_files_within_tolerance(\n    file1: str | PathLike | IOBase, file2: str | PathLike | IOBase, *, tolerance=1e-3\n):\n    \"\"\"\n    Assert that two pdb files are equal under following conditions.\n\n    - ignore the trailing whitespace.\n    - 0.001 default tolerance for Orthogonal coordinates for X,Y,Z in Angstroms.\n\n    Note:\n        - Currently, the implementation is completely equal to assert_two_pdbqt_files_within_tolerance.\n        - It may change and diverge in the future, thus there are two separate functions.\n    \"\"\"\n    # ATOM    998  N   PHE B   9      18.937-159.292 -13.075  1.00 30.49           N\n    assert_two_pdbqt_files_within_tolerance(file1, file2, tolerance=tolerance)\n
"},{"location":"reference/biotest/compare_files/#biotest.compare_files.assert_two_dirs_within_tolerance","title":"assert_two_dirs_within_tolerance(dir1, dir2, *, tolerance=0.001, filenames_exclude=None)","text":"

Assert that two directories have the same files with almost the same content within tolerance.

Source code in src/biotest/compare_files.py
def assert_two_dirs_within_tolerance(\n    dir1: str | PathLike,\n    dir2: str | PathLike,\n    *,\n    tolerance: float = 1e-3,\n    filenames_exclude: set[str] | None = None,\n):\n    \"\"\"\n    Assert that two directories have the same files with almost the same content within tolerance.\n    \"\"\"\n    dir1 = Path(dir1)\n    dir2 = Path(dir2)\n    assert dir1.is_dir()\n    assert dir2.is_dir()\n\n    if filenames_exclude is None:\n        assert {path.name for path in dir1.iterdir()} == {\n            path.name for path in dir2.iterdir()\n        }\n    else:\n        assert {\n            path.name for path in dir1.iterdir() if path.name not in filenames_exclude\n        } == {\n            path.name for path in dir2.iterdir() if path.name not in filenames_exclude\n        }\n\n    for file1 in dir1.iterdir():\n        if filenames_exclude and file1.name in filenames_exclude:\n            continue\n\n        file2 = dir2 / file1.name\n\n        if file1.suffix == \".npy\":\n            assert_two_npys_within_tolerance(file1, file2, tolerance=tolerance)\n        elif file1.suffix == \".pdbqt\":\n            assert_two_pdbqt_files_within_tolerance(file1, file2, tolerance=tolerance)\n        elif file1.suffix == \".pdb\":\n            assert_two_pdb_files_within_tolerance(file1, file2, tolerance=tolerance)\n        elif file1.is_dir():\n            assert_two_dirs_within_tolerance(\n                file1, file2, tolerance=tolerance, filenames_exclude=filenames_exclude\n            )\n        else:\n            assert_two_files_equal_sha(file1, file2)\n
"},{"location":"reference/biotest/cli/","title":"Index","text":""},{"location":"reference/biotest/cli/main/","title":" main","text":""}]} \ No newline at end of file diff --git a/latest/sitemap.xml b/latest/sitemap.xml index f4d4556..16fd815 100644 --- a/latest/sitemap.xml +++ b/latest/sitemap.xml @@ -2,30 +2,30 @@ https://deargen.github.io/biotest/latest/ - 2024-10-22 + 2024-10-23 https://deargen.github.io/biotest/latest/CHANGELOG/ - 2024-10-22 + 2024-10-23 https://deargen.github.io/biotest/latest/reference/SUMMARY/ - 2024-10-22 + 2024-10-23 https://deargen.github.io/biotest/latest/reference/biotest/ - 2024-10-22 + 2024-10-23 https://deargen.github.io/biotest/latest/reference/biotest/compare_files/ - 2024-10-22 + 2024-10-23 https://deargen.github.io/biotest/latest/reference/biotest/cli/ - 2024-10-22 + 2024-10-23 https://deargen.github.io/biotest/latest/reference/biotest/cli/main/ - 2024-10-22 + 2024-10-23 \ No newline at end of file diff --git a/latest/sitemap.xml.gz b/latest/sitemap.xml.gz index 8629c24..e4e14c5 100644 Binary files a/latest/sitemap.xml.gz and b/latest/sitemap.xml.gz differ