Beispiel #1
0
def read_config(config_path, verbose=False):
    """returns ensembl release, local path, and db specifics from the provided
    config path"""
    parser = configparser.ConfigParser()
    parser.read_file(config_path)
    release = parser.get("release", "release")
    remote_path = parser.get("remote path", "path")
    local_path = parser.get("local path", "path")
    local_path = abspath(local_path)
    species_dbs = {}
    for section in parser.sections():
        if section in ("release", "remote path", "local path"):
            continue

        dbs = [db.strip() for db in parser.get(section, "db").split(",")]

        if section == "compara":
            species_dbs["compara"] = dbs
            continue

        # handle synonymns
        species = Species.get_species_name(section, level="raise")
        for synonym in Species.get_synonymns(species):
            species_dbs[synonym] = dbs

    return release, remote_path, local_path, species_dbs
Beispiel #2
0
 def test_get_name_type(self):
     """should return the (latin|common) name given a latin, common or ensembl
     db prefix names"""
     self.assertEqual(Species.get_species_name("human"), "H**o sapiens")
     self.assertEqual(Species.get_species_name("homo_sapiens"),
                      "H**o sapiens")
     self.assertEqual(Species.get_common_name("Mus musculus"), "Mouse")
     self.assertEqual(Species.get_common_name("mus_musculus"), "Mouse")
Beispiel #3
0
 def test_get_ensembl_format(self):
     """should take common or latin names and return the corresponding
     ensembl db prefix"""
     self.assertEqual(Species.get_ensembl_db_prefix("human"),
                      "homo_sapiens")
     self.assertEqual(Species.get_ensembl_db_prefix("mouse"),
                      "mus_musculus")
     self.assertEqual(Species.get_ensembl_db_prefix("Mus musculus"),
                      "mus_musculus")
Beispiel #4
0
 def test_get_synonyms(self):
     """correctly returns synonyms given either a common or latin name"""
     expect = ["Canis familiaris", "Canis lupus familiaris"]
     got = Species.get_synonymns("Canis familiaris")
     self.assertEqual(set(got), set(expect))
     got = Species.get_synonymns("Canis lupus familiaris")
     self.assertEqual(set(got), set(expect))
     got = Species.get_synonymns("dog")
     self.assertEqual(set(got), set(expect))
Beispiel #5
0
 def test_synonyms_work(self):
     """species with synonyms should allow correct lookups"""
     self.assertEqual(Species.get_species_name("Canis lupus familiaris"),
                      "Canis familiaris")
     self.assertEqual(Species.get_common_name("Canis lupus familiaris"),
                      "Dog")
     self.assertEqual(
         Species.get_ensembl_db_prefix("Canis lupus familiaris"),
         "canis_familiaris")
     self.assertEqual(Species.get_compara_name("Canis lupus familiaris"),
                      "Dog")
Beispiel #6
0
def read_config(config_path, verbose=False):
    """returns ensembl release, local path, and db specifics from the provided
    config path"""
    parser = configparser.ConfigParser()
    parser.read_file(config_path)
    release = parser.get("release", "release")
    remote_path = parser.get("remote path", "path")
    local_path = parser.get("local path", "path")
    local_path = abspath(local_path)
    species_dbs = {}
    for section in parser.sections():
        if section in ("release", "remote path", "local path"):
            continue

        if section != "compara":
            species = Species.get_species_name(section, level="raise")
        else:
            species = "compara"
        dbs = [db.strip() for db in parser.get(section, "db").split(",")]
        species_dbs[species] = dbs

    if verbose:
        click.secho("DOWNLOADING\n  ensembl release=%s" % release, fg="green")
        click.secho("\n".join(["  %s" % d for d in species_dbs]), fg="green")
        click.secho("\nWRITING to output path=%s\n" % local_path, fg="green")
    return release, remote_path, local_path, species_dbs
Beispiel #7
0
 def test_add_new_species(self):
     """should correctly add a new species/common combination and infer the
     correct ensembl prefix"""
     species_name, common_name = "Otolemur garnettii", "Bushbaby"
     Species.amend_species(species_name, common_name)
     self.assertEqual(Species.get_species_name(species_name), species_name)
     self.assertEqual(Species.get_species_name("Bushbaby"), species_name)
     self.assertEqual(Species.get_species_name(common_name), species_name)
     self.assertEqual(Species.get_common_name(species_name), common_name)
     self.assertEqual(Species.get_common_name("Bushbaby"), common_name)
     self.assertEqual(Species.get_ensembl_db_prefix("Bushbaby"),
                      "otolemur_garnettii")
     self.assertEqual(Species.get_ensembl_db_prefix(species_name),
                      "otolemur_garnettii")
     self.assertEqual(Species.get_ensembl_db_prefix(common_name),
                      "otolemur_garnettii")
Beispiel #8
0
 def test_get_compara_name(self):
     """should correctly form valid names for assignment onto objects"""
     self.assertEqual(Species.get_compara_name("pika"), "Pika")
     self.assertEqual(Species.get_compara_name("C.elegans"), "Celegans")
     self.assertEqual(Species.get_compara_name("Caenorhabditis elegans"),
                      "Celegans")
Beispiel #9
0
 def test_amend_existing(self):
     """should correctly amend an existing species"""
     species_name = "Ochotona princeps"
     common_name1 = "american pika"
     common_name2 = "pika"
     ensembl_pref = "ochotona_princeps"
     Species.amend_species(species_name, common_name1)
     self.assertEqual(Species.get_common_name(species_name), common_name1)
     Species.amend_species(species_name, common_name2)
     self.assertEqual(Species.get_species_name(common_name2), species_name)
     self.assertEqual(Species.get_species_name(ensembl_pref), species_name)
     self.assertEqual(Species.get_common_name(species_name), common_name2)
     self.assertEqual(Species.get_common_name(ensembl_pref), common_name2)
     self.assertEqual(Species.get_ensembl_db_prefix(species_name),
                      ensembl_pref)
     self.assertEqual(Species.get_ensembl_db_prefix(common_name2),
                      ensembl_pref)
Beispiel #10
0
 def test_species_attr(self):
     """gene has species attribute"""
     self.assertEqual(self.brca2.species, "H**o sapiens")
     mac = self.macaq.get_gene_by_stableid("ENSMMUG00000008639")
     sp_name = Species.get_species_name("macaque")
     self.assertEqual(mac.species, sp_name)
Beispiel #11
0
 def test_to_table(self):
     """returns a table object"""
     table = Species.to_table()
     self.assertIsInstance(table, Table)
     self.assertTrue(table.shape[0] > 20)
     self.assertEqual(table.shape[1], 5)