コード例 #1
0
def test_ls(datadir_mgr):
    """Test ls command. """
    test_file_paths = []
    test_file_paths += datadir_mgr.paths_from_scope(module="1prefixing_test")
    test_file_paths += datadir_mgr.paths_from_scope(module="2extraction_test")
    test_file_paths += datadir_mgr.paths_from_scope(module="3indexing_test")
    datadir_mgr.add_scope("prefix", module="1prefixing_test")
    datadir_mgr.add_scope("extract", module="2extraction_test")
    datadir_mgr.add_scope("index", module="3indexing_test")
    with datadir_mgr.in_tmp_dir(
            inpathlist=test_file_paths,
            save_outputs=True,
            excludepatterns=["*.log"],
    ):
        output = sh.bionorm(["ls", "--recurse", ORGANISM_DIR])
        lines_out = output.count("\n")
        assert lines_out == len(test_file_paths)
        assert not sh.bionorm(["ls", "-r", "--invalid", ORGANISM_DIR]).count(
            "\n")  # no invalid filename
        assert not sh.bionorm(["ls", "-r", "--unrecognized", ORGANISM_DIR
                               ]).count("\n")  # no unrecognized filenames
        UNREC_PATH.touch()
        assert 1 == sh.bionorm(["ls", "-ru", ORGANISM_DIR
                                ]).count("\n")  # now 1 unrecognized filename
        UNREC_PATH.unlink()
        for badname, reason in ANN_INVALID_LIST:
            badpath = ANN_PATH / badname
            badpath.touch()
            print(f"testing {reason}")
            jsondict = sh.bionorm(["ls", "-rji", ORGANISM_DIR])
            result_dict = json.loads(str(jsondict))
            assert "invalid_key" in result_dict
            assert result_dict["invalid_key"] == reason
            badpath.unlink()
コード例 #2
0
def test_install_gffread(datadir_mgr):
    """Test install gffread."""
    with datadir_mgr.in_tmp_dir():
        output = sh.bionorm([
            "install",
            "gffread",
        ])
        print(output)
コード例 #3
0
def test_install_genometools(datadir_mgr):
    """Test install genometools"""
    with datadir_mgr.in_tmp_dir():
        print("installing gffread")
        output = sh.bionorm([
            "install",
            "genometools",
        ])
        print(output)
コード例 #4
0
def test_install_samtools(datadir_mgr):
    """Test install samtools"""
    with datadir_mgr.in_tmp_dir():
        print("installing samtools")
        output = sh.bionorm([
            "install",
            "samtools",
        ])
        print(output)
コード例 #5
0
def test_version(tmp_path):
    print("testing version")
    with working_directory(tmp_path):
        try:
            output = sh.bionorm(["--version"])
        except sh.ErrorReturnCode as e:
            print(e)
            pytest.fail(e)
        print(output)
        assert "version" in output
コード例 #6
0
def test_index_gff(datadir_mgr):
    """Test index_gff."""
    datadir_mgr.add_scope("prefix", module="1prefixing_test")
    with datadir_mgr.in_tmp_dir(
            inpathlist=[GFF_PATH],
            save_outputs=True,
            excludepatterns=["*.log"],
    ):
        output = sh.bionorm(["index-gff", str(GFF_PATH)])
        print(output)
コード例 #7
0
def test_cli(tmp_path):
    print("testing basic cli function")
    with working_directory(tmp_path):
        try:
            output = sh.bionorm()
        except sh.ErrorReturnCode as e:
            print(e)
            pytest.fail(e)
        print(output)
        assert "Usage:" in output
        assert "Options:" in output
        assert "Commands:" in output
コード例 #8
0
def test_extraction(datadir_mgr):
    """Test command extract-fasta."""
    datadir_mgr.add_scope("prefix", module="1prefixing_test")
    with datadir_mgr.in_tmp_dir(inpathlist=PREFIXING_LIST,
                                save_outputs=True,
                                excludepatterns=["*.log"]):
        output = sh.bionorm(["extract-fasta", str(GFF_PATH), str(FASTA_PATH)])
        print(output)
        loglist = [fp.name for fp in (Path.cwd() / "logs").glob("*")]
        assert len(loglist) is 1
        assert "bionorm-extract-fasta_0.log" in loglist
        outfilelist = [fp.name for fp in ANN_PATH.glob("*")]
        expectedlist = [p.name for p in EXTRACTION_LIST]
        for filename in expectedlist:
            assert filename in outfilelist
        assert fasta_count(PROTEIN_PATH) == PROTEIN_COUNT
        assert fasta_count(CDS_PATH) == PROTEIN_COUNT
コード例 #9
0
def test_consistency(datadir_mgr):
    """Test consistency"""
    datadir_mgr.add_scope("prefix", module="1prefixing_test")
    datadir_mgr.add_scope("extract", module="2extraction_test")
    with datadir_mgr.in_tmp_dir(
            inpathlist=[
                CDS_PATH,
                GFF_PATH,
                FASTA_PATH,
                MRNA_PATH,
                TRANSCRIPT_PATH,
            ],
            save_outputs=True,
            excludepatterns=["*.log"],
    ):
        output = sh.bionorm(["consistency", "--help"])
        print(output)
コード例 #10
0
def test_prefix_fasta(datadir_mgr):
    """Test command prefix-fasta."""
    datadir_mgr.download(
        download_url=DOWNLOAD_URL,
        files=[RAW_FASTA_FILE],
        scope="function",
        md5_check=True,
        gunzip=True,
        progressbar=False,
    )
    with datadir_mgr.in_tmp_dir(
            inpathlist=[RAW_FASTA_FILE],
            save_outputs=True,
            excludepatterns=["*.log"],
    ):
        try:
            output = sh.bionorm([
                "prefix-fasta",
                "--genver",
                "5",
                "--genus",
                "medicago",
                "--species",
                "truncatula",
                "--infra_id",
                "jemalong_A17",
                "--key",
                "FAKE",
                RAW_FASTA_FILE,
            ])
        except sh.ErrorReturnCode as e:
            print(e)
            pytest.fail(e)
        print(output)
        loglist = list((Path.cwd() / "logs").glob("*"))
        assert len(loglist) is 1
        assert str(loglist[0].name) == "bionorm-prefix-fasta_0.log"
        outdir_path = Path(GENOME_PATH.parts[0])
        subdirname = list(outdir_path.glob("*"))[0].parts[-1]
        assert subdirname == GENOME_PATH.parts[1]
        subdir_path = outdir_path / subdirname
        outfilename = list(subdir_path.glob("*"))[0].name
        assert outfilename == FASTA_PATH.parts[2]
        assert fasta_count(Path(RAW_FASTA_FILE)) == fasta_count(FASTA_PATH)