def test_autodownload_false(tmpdir):
    collection = GenomeCollection(data_dir=str(tmpdir))
    collection.autodownload = False

    with pytest.raises(FileNotFoundError) as excinfo:
        collection.get_taxid_infos("224308")
    assert "No infos" in str(excinfo.value)

    with pytest.raises(FileNotFoundError) as excinfo:
        collection.get_taxid_genome_data_path("224308")
    assert "No genome" in str(excinfo.value)
def test_delete_all_data_files(tmpdir):
    collection = GenomeCollection(data_dir=str(tmpdir))
    taxids = ["224308", "511145", "559292"]
    for taxid in taxids:
        collection.get_taxid_infos(taxid)

    found_taxids = collection.list_locally_available_taxids("infos")
    assert len(found_taxids) == 3
    collection.remove_all_local_data_files()

    found_taxids = collection.list_locally_available_taxids("infos")
    assert len(found_taxids) == 0
Example #3
0
def test_taxid_with_nonunique_genome(tmpdir):
    taxid = 10710  # LAMBDA PHAGE - has 2 associated assemblies on NCBI
    collection = GenomeCollection(data_dir=str(tmpdir))
    with pytest.raises(OSError) as excinfo:
        path = collection.get_taxid_infos(taxid)
    assert "You will need to download" in str(excinfo.value)
    collection.download_taxid_genome_infos_from_ncbi(taxid, assembly_id="#1")
    path = collection.datafile_path(taxid, data_type="genomic_fasta")
    assert not os.path.exists(path)
    collection.get_taxid_genome_data_path(taxid)
    assert os.path.exists(path)
def test_list_taxids(tmpdir):
    collection = GenomeCollection(data_dir=str(tmpdir))
    taxids = ["511145", "559292", PHAGE_TAXID]
    found_taxids = collection.list_locally_available_taxids("infos")
    assert len(found_taxids) == 0
    for taxid in taxids:
        collection.get_taxid_infos(taxid)

    found_taxids = collection.list_locally_available_taxids("infos")
    assert found_taxids == taxids

    found_taxids = collection.list_locally_available_taxids("genomic_fasta")
    assert len(found_taxids) == 0

    collection.get_taxid_genome_data_path(PHAGE_TAXID)
    found_taxids = collection.list_locally_available_taxids("genomic_fasta")
    assert found_taxids == [PHAGE_TAXID]

    found_taxids = collection.list_locally_available_taxids_names()
    assert len(found_taxids) == 3

    # For coverage!
    collection.list_locally_available_taxids_names(print_mode=True)