Ejemplo n.º 1
0
 def test_pubmed_16381885_title(self):
     """Bio.TogoWS.entry("pubmed", "16381885", field="title")"""
     handle = TogoWS.entry("pubmed", "16381885", field="title")
     data = handle.read().strip()
     handle.close()
     self.assertEqual(data,
          'From genomics to chemical genomics: new developments in KEGG.')
Ejemplo n.º 2
0
 def test_pubmed_16381885_and_19850725(self):
     """Bio.TogoWS.entry("pubmed", "16381885,19850725")"""
     handle = TogoWS.entry("pubmed", "16381885,19850725")
     records = list(Medline.parse(handle))
     handle.close()
     self.assertEqual(len(records), 2)
     self.assertEqual(records[0]["TI"], "From genomics to chemical genomics: new developments in KEGG.")
     self.assertEqual(
         records[0]["AU"],
         [
             "Kanehisa M",
             "Goto S",
             "Hattori M",
             "Aoki-Kinoshita KF",
             "Itoh M",
             "Kawashima S",
             "Katayama T",
             "Araki M",
             "Hirakawa M",
         ],
     )
     self.assertEqual(
         records[1]["TI"],
         "DDBJ launches a new archive database with analytical tools " + "for next-generation sequence data.",
     )
     self.assertEqual(
         records[1]["AU"],
         ["Kaminuma E", "Mashima J", "Kodama Y", "Gojobori T", "Ogasawara O", "Okubo K", "Takagi T", "Nakamura Y"],
     )
Ejemplo n.º 3
0
 def test_genbank_gff3(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", format="gff")"""
     # Note - Using manual URL with genbank instead of nucleotide works
     handle = TogoWS.entry("nucleotide", "X52960", format="gff")
     data = handle.read()
     handle.close()
     self.assertTrue(data.startswith("##gff-version 3\nX52960\tGenbank\t"), data)
Ejemplo n.º 4
0
 def test_ddbj_genbank(self):
     """Bio.TogoWS.entry("ddbj", "X52960")"""
     handle = TogoWS.entry("ddbj", "X52960")  # Returns "genbank" format
     record = SeqIO.read(handle, "gb")
     handle.close()
     self.assertEqual(record.id, "X52960.1")
     self.assertEqual(record.name, "X52960")
     self.assertEqual(len(record), 248)
     self.assertEqual(seguid(record.seq), "Ktxz0HgMlhQmrKTuZpOxPZJ6zGU")
Ejemplo n.º 5
0
 def test_ddbj_fasta(self):
     """Bio.TogoWS.entry("ddbj", "X52960", "fasta")"""
     handle = TogoWS.entry("ddbj", "X52960", "fasta")
     record = SeqIO.read(handle, "fasta")
     handle.close()
     self.assertTrue("X52960" in record.id, record.id)
     self.assertTrue("X52960" in record.name, record.name)
     self.assertEqual(len(record), 248)
     self.assertEqual(seguid(record.seq), "Ktxz0HgMlhQmrKTuZpOxPZJ6zGU")
Ejemplo n.º 6
0
 def test_nucleotide_fasta(self):
     """Bio.TogoWS.entry("nucleotide", "6273291", "fasta")"""
     handle = TogoWS.entry("nucleotide", "6273291", "fasta")
     record = SeqIO.read(handle, "fasta")
     handle.close()
     self.assertTrue("6273291" in record.id, record.id)
     self.assertTrue("6273291" in record.name, record.name)
     self.assertEqual(len(record), 902)
     self.assertEqual(seguid(record.seq), "bLhlq4mEFJOoS9PieOx4nhGnjAQ")
Ejemplo n.º 7
0
 def test_pubmed_16381885_au(self):
     """Bio.TogoWS.entry("pubmed", "16381885", field="au")"""
     # Gives one name per line (i.e. \n separated), no dots
     handle = TogoWS.entry("pubmed", "16381885", field="au")
     data = handle.read().strip().split("\n")
     handle.close()
     self.assertEqual(data, ['Kanehisa M', 'Goto S', 'Hattori M',
                             'Aoki-Kinoshita KF', 'Itoh M',
                             'Kawashima S', 'Katayama T', 'Araki M',
                             'Hirakawa M'])
Ejemplo n.º 8
0
 def test_pubmed_16381885_authors(self):
     """Bio.TogoWS.entry("pubmed", "16381885", field="authors")"""
     # Gives names tab separated (i.e. \t separated)
     handle = TogoWS.entry("pubmed", "16381885", field="authors")
     data = handle.read().strip().split("\t")
     handle.close()
     self.assertEqual(data, ['Kanehisa, M.', 'Goto, S.', 'Hattori, M.',
                             'Aoki-Kinoshita, K. F.', 'Itoh, M.',
                             'Kawashima, S.', 'Katayama, T.', 'Araki, M.',
                             'Hirakawa, M.'])
Ejemplo n.º 9
0
 def test_embl_AM905444(self):
     """Bio.TogoWS.entry("embl", "AM905444")"""
     handle = TogoWS.entry("embl", "AM905444")
     record = SeqIO.read(handle, "embl")
     handle.close()
     self.assertTrue("AM905444" in record.id, record.id)
     self.assertTrue("AM905444" in record.name, record.name)
     self.assertTrue("porin" in record.description, record.description)
     self.assertEqual(len(record), 1164)
     self.assertEqual(seguid(record.seq), "G0HtLpwF7i4FXUaUjDUPTjok79c")
Ejemplo n.º 10
0
 def test_protein_fasta(self):
     """Bio.TogoWS.entry("protein", "16130152", "fasta")"""
     handle = TogoWS.entry("protein", "16130152", "fasta")
     record = SeqIO.read(handle, "fasta")
     handle.close()
     #Could use assertIn but requires Python 2.7+
     self.assert_("16130152" in record.id, record.id)
     self.assert_("16130152" in record.name, record.name)
     self.assert_("porin protein" in record.description, record.description)
     self.assertEqual(len(record), 367)
     self.assertEqual(seguid(record.seq), "fCjcjMFeGIrilHAn6h+yju267lg")
Ejemplo n.º 11
0
 def test_protein_fasta(self):
     """Bio.TogoWS.entry("protein", "16130152", "fasta")"""
     handle = TogoWS.entry("protein", "16130152", "fasta")
     record = SeqIO.read(handle, "fasta")
     handle.close()
     # Could use assertIn but requires Python 2.7+
     self.assertTrue("16130152" in record.id, record.id)
     self.assertTrue("16130152" in record.name, record.name)
     self.assertTrue("porin protein" in record.description, record.description)
     self.assertEqual(len(record), 367)
     self.assertEqual(seguid(record.seq), "fCjcjMFeGIrilHAn6h+yju267lg")
Ejemplo n.º 12
0
 def test_pubmed_16381885_authors(self):
     """Bio.TogoWS.entry("pubmed", "16381885", field="authors")"""
     #Gives names tab separated (i.e. \t separated)
     handle = TogoWS.entry("pubmed", "16381885", field="authors")
     data = handle.read().strip().split("\t")
     handle.close()
     self.assertEqual(data, [
         'Kanehisa, M.', 'Goto, S.', 'Hattori, M.', 'Aoki-Kinoshita, K. F.',
         'Itoh, M.', 'Kawashima, S.', 'Katayama, T.', 'Araki, M.',
         'Hirakawa, M.'
     ])
Ejemplo n.º 13
0
 def test_nucleotide_fasta(self):
     """Bio.TogoWS.entry("nucleotide", "6273291", "fasta")."""
     handle = TogoWS.entry("nucleotide", "6273291", "fasta")
     record = SeqIO.read(handle, "fasta")
     handle.close()
     # NCBI is phasing out GI numbers, so no longer true:
     # self.assertIn("6273291", record.id)
     # self.assertIn("6273291", record.name)
     self.assertIn("AF191665.1", record.id)
     self.assertIn("AF191665.1", record.name)
     self.assertEqual(len(record), 902)
     self.assertEqual(seguid(record.seq), "bLhlq4mEFJOoS9PieOx4nhGnjAQ")
Ejemplo n.º 14
0
 def test_nucleotide_fasta(self):
     """Bio.TogoWS.entry("nucleotide", "6273291", "fasta")"""
     handle = TogoWS.entry("nucleotide", "6273291", "fasta")
     record = SeqIO.read(handle, "fasta")
     handle.close()
     # NCBI is phasing out GI numbers, so no longer true:
     # self.assertIn("6273291", record.id)
     # self.assertIn("6273291", record.name)
     self.assertIn("AF191665.1", record.id)
     self.assertIn("AF191665.1", record.name)
     self.assertEqual(len(record), 902)
     self.assertEqual(seguid(record.seq), "bLhlq4mEFJOoS9PieOx4nhGnjAQ")
Ejemplo n.º 15
0
 def test_pubmed_16381885(self):
     """Bio.TogoWS.entry("pubmed", "16381885")"""
     # Gives Medline plain text
     handle = TogoWS.entry("pubmed", "16381885")
     data = Medline.read(handle)
     handle.close()
     self.assertEqual(data["TI"],
          'From genomics to chemical genomics: new developments in KEGG.')
     self.assertEqual(data["AU"], ['Kanehisa M', 'Goto S', 'Hattori M',
                                   'Aoki-Kinoshita KF', 'Itoh M',
                                   'Kawashima S', 'Katayama T', 'Araki M',
                                   'Hirakawa M'])
Ejemplo n.º 16
0
 def test_pubmed_16381885(self):
     """Bio.TogoWS.entry("pubmed", "16381885")"""
     #Gives Medline plain text
     handle = TogoWS.entry("pubmed", "16381885")
     data = Medline.read(handle)
     handle.close()
     self.assertEqual(data["TI"],
          'From genomics to chemical genomics: new developments in KEGG.')
     self.assertEqual(data["AU"], ['Kanehisa M', 'Goto S', 'Hattori M',
                                   'Aoki-Kinoshita KF', 'Itoh M',
                                   'Kawashima S', 'Katayama T', 'Araki M',
                                   'Hirakawa M'])
Ejemplo n.º 17
0
 def test_pubmed_16381885(self):
     """Bio.TogoWS.entry("pubmed", "16381885")."""
     # Gives Medline plain text
     handle = TogoWS.entry("pubmed", "16381885")
     data = Medline.read(handle)
     handle.close()
     self.assertEqual(data["TI"],
                      "From genomics to chemical genomics: "
                      "new developments in KEGG.")
     self.assertEqual(data["AU"], ["Kanehisa M", "Goto S", "Hattori M",
                                   "Aoki-Kinoshita KF", "Itoh M",
                                   "Kawashima S", "Katayama T", "Araki M",
                                   "Hirakawa M"])
Ejemplo n.º 18
0
 def test_protein_fasta(self):
     """Bio.TogoWS.entry("protein", "16130152", "fasta")."""
     handle = TogoWS.entry("protein", "16130152", "fasta")
     record = SeqIO.read(handle, "fasta")
     handle.close()
     # NCBI is phasing out GI numbers, so no longer true:
     # self.assertIn("16130152", record.id)
     # self.assertIn("16130152", record.name)
     self.assertIn("NP_416719.1", record.id)
     self.assertIn("NP_416719.1", record.name)
     self.assertIn(" porin ", record.description)
     self.assertEqual(len(record), 367)
     self.assertEqual(seguid(record.seq), "fCjcjMFeGIrilHAn6h+yju267lg")
Ejemplo n.º 19
0
 def test_protein_fasta(self):
     """Bio.TogoWS.entry("protein", "16130152", "fasta")"""
     handle = TogoWS.entry("protein", "16130152", "fasta")
     record = SeqIO.read(handle, "fasta")
     handle.close()
     # NCBI is phasing out GI numbers, so no longer true:
     # self.assertIn("16130152", record.id)
     # self.assertIn("16130152", record.name)
     self.assertIn("NP_416719.1", record.id)
     self.assertIn("NP_416719.1", record.name)
     self.assertIn("porin protein", record.description)
     self.assertEqual(len(record), 367)
     self.assertEqual(seguid(record.seq), "fCjcjMFeGIrilHAn6h+yju267lg")
Ejemplo n.º 20
0
def retrieve_entry_info(id_name_dict, db):
    ## Grab each entry in list of ids
    id_entry_dict = {}
    for entry in tqdm(id_name_dict.keys()):

        entry_id = entry.split(":")[1]

        try:
            id_entry_dict[entry_id] = json.load(
                TogoWS.entry(db, entry_id, format="json"))[0]
        except:
            pass

    return id_entry_dict
Ejemplo n.º 21
0
    def test_uniprot_swiss(self):
        """Bio.TogoWS.entry("uniprot", ["A1AG1_HUMAN","A1AG1_MOUSE"])"""
        #Returns "swiss" format:
        handle = TogoWS.entry("uniprot", ["A1AG1_HUMAN","A1AG1_MOUSE"])
        record1, record2  = SeqIO.parse(handle, "swiss")
        handle.close()

        self.assertEqual(record1.id, "P02763")
        self.assertEqual(record1.name, "A1AG1_HUMAN")
        self.assertEqual(len(record1), 201)
        self.assertEqual(seguid(record1.seq), "LHDJJ6oC7gUXo8CC7Xn6EUeA8Gk")

        self.assertEqual(record2.id, "Q60590")
        self.assertEqual(record2.name, "A1AG1_MOUSE")
        self.assertEqual(len(record2), 207)
        self.assertEqual(seguid(record2.seq), "FGcj+RFQhP2gRusCmwPFty5PJT0")
Ejemplo n.º 22
0
    def test_uniprot_swiss(self):
        """Bio.TogoWS.entry("uniprot", ["A1AG1_HUMAN","A1AG1_MOUSE"])"""
        # Returns "swiss" format:
        handle = TogoWS.entry("uniprot", ["A1AG1_HUMAN", "A1AG1_MOUSE"])
        record1, record2 = SeqIO.parse(handle, "swiss")
        handle.close()

        self.assertEqual(record1.id, "P02763")
        self.assertEqual(record1.name, "A1AG1_HUMAN")
        self.assertEqual(len(record1), 201)
        self.assertEqual(seguid(record1.seq), "LHDJJ6oC7gUXo8CC7Xn6EUeA8Gk")

        self.assertEqual(record2.id, "Q60590")
        self.assertEqual(record2.name, "A1AG1_MOUSE")
        self.assertEqual(len(record2), 207)
        self.assertEqual(seguid(record2.seq), "FGcj+RFQhP2gRusCmwPFty5PJT0")
Ejemplo n.º 23
0
 def test_pubmed_16381885_and_19850725_authors(self):
     """Bio.TogoWS.entry("pubmed", "16381885,19850725", field="authors")"""
     handle = TogoWS.entry("pubmed", "16381885,19850725", field="authors")
     # Little hack to remove blank lines...
     # names = handle.read().replace("\n\n", "\n").strip().split("\n")
     names = handle.read().strip().split("\n")
     handle.close()
     self.assertEqual(2, len(names))
     names1, names2 = names
     self.assertEqual(names1.split("\t"),
                      ['Kanehisa, M.', 'Goto, S.', 'Hattori, M.',
                       'Aoki-Kinoshita, K. F.', 'Itoh, M.',
                       'Kawashima, S.', 'Katayama, T.',
                       'Araki, M.', 'Hirakawa, M.'])
     self.assertEqual(names2.split("\t"),
                      ['Kaminuma, E.', 'Mashima, J.', 'Kodama, Y.',
                       'Gojobori, T.', 'Ogasawara, O.', 'Okubo, K.',
                       'Takagi, T.', 'Nakamura, Y.'])
Ejemplo n.º 24
0
 def test_pubmed_16381885_and_19850725_authors(self):
     """Bio.TogoWS.entry("pubmed", "16381885,19850725", field="authors")"""
     handle = TogoWS.entry("pubmed", "16381885,19850725", field="authors")
     #Little hack to remove blank lines...
     #names = handle.read().replace("\n\n", "\n").strip().split("\n")
     names = handle.read().strip().split("\n")
     handle.close()
     self.assertEqual(2, len(names))
     names1, names2 = names
     self.assertEqual(names1.split("\t"),
                      ['Kanehisa, M.', 'Goto, S.', 'Hattori, M.',
                       'Aoki-Kinoshita, K. F.', 'Itoh, M.',
                       'Kawashima, S.', 'Katayama, T.',
                       'Araki, M.', 'Hirakawa, M.'])
     self.assertEqual(names2.split("\t"),
                      ['Kaminuma, E.', 'Mashima, J.', 'Kodama, Y.',
                       'Gojobori, T.', 'Ogasawara, O.', 'Okubo, K.',
                       'Takagi, T.', 'Nakamura, Y.'])
Ejemplo n.º 25
0
 def test_pubmed_16381885_and_19850725(self):
     """Bio.TogoWS.entry("pubmed", "16381885,19850725")."""
     handle = TogoWS.entry("pubmed", "16381885,19850725")
     records = list(Medline.parse(handle))
     handle.close()
     self.assertEqual(len(records), 2)
     self.assertEqual(
         records[0]["TI"],
         "From genomics to chemical genomics: new developments in KEGG.",
     )
     self.assertEqual(
         records[0]["AU"],
         [
             "Kanehisa M",
             "Goto S",
             "Hattori M",
             "Aoki-Kinoshita KF",
             "Itoh M",
             "Kawashima S",
             "Katayama T",
             "Araki M",
             "Hirakawa M",
         ],
     )
     self.assertEqual(
         records[1]["TI"],
         "DDBJ launches a new archive database with "
         "analytical tools for next-generation sequence data.",
     )
     self.assertEqual(
         records[1]["AU"],
         [
             "Kaminuma E",
             "Mashima J",
             "Kodama Y",
             "Gojobori T",
             "Ogasawara O",
             "Okubo K",
             "Takagi T",
             "Nakamura Y",
         ],
     )
Ejemplo n.º 26
0
 def test_pubmed_16381885_and_19850725(self):
     """Bio.TogoWS.entry("pubmed", "16381885,19850725")"""
     handle = TogoWS.entry("pubmed", "16381885,19850725")
     records = list(Medline.parse(handle))
     handle.close()
     self.assertEqual(len(records), 2)
     self.assertEqual(records[0]["TI"],
          'From genomics to chemical genomics: new developments in KEGG.')
     self.assertEqual(records[0]["AU"], ['Kanehisa M', 'Goto S',
                                         'Hattori M', 'Aoki-Kinoshita KF',
                                         'Itoh M', 'Kawashima S',
                                         'Katayama T', 'Araki M',
                                         'Hirakawa M'])
     self.assertEqual(records[1]["TI"],
          'DDBJ launches a new archive database with analytical tools ' + \
          'for next-generation sequence data.')
     self.assertEqual(records[1]["AU"], ['Kaminuma E', 'Mashima J',
                                         'Kodama Y', 'Gojobori T',
                                         'Ogasawara O', 'Okubo K',
                                         'Takagi T', 'Nakamura Y'])
Ejemplo n.º 27
0
 def test_pubmed_16381885_and_19850725(self):
     """Bio.TogoWS.entry("pubmed", "16381885,19850725")"""
     handle = TogoWS.entry("pubmed", "16381885,19850725")
     records = list(Medline.parse(handle))
     handle.close()
     self.assertEqual(len(records), 2)
     self.assertEqual(records[0]["TI"],
          'From genomics to chemical genomics: new developments in KEGG.')
     self.assertEqual(records[0]["AU"], ['Kanehisa M', 'Goto S',
                                         'Hattori M', 'Aoki-Kinoshita KF',
                                         'Itoh M', 'Kawashima S',
                                         'Katayama T', 'Araki M',
                                         'Hirakawa M'])
     self.assertEqual(records[1]["TI"],
          'DDBJ launches a new archive database with analytical tools ' +
          'for next-generation sequence data.')
     self.assertEqual(records[1]["AU"], ['Kaminuma E', 'Mashima J',
                                         'Kodama Y', 'Gojobori T',
                                         'Ogasawara O', 'Okubo K',
                                         'Takagi T', 'Nakamura Y'])
Ejemplo n.º 28
0
 def test_pubmed_16381885_au(self):
     """Bio.TogoWS.entry("pubmed", "16381885", field="au")."""
     # Gives one name per line (i.e. \n separated), no dots
     handle = TogoWS.entry("pubmed", "16381885", field="au")
     data = handle.read().strip().split("\n")
     handle.close()
     self.assertEqual(
         data,
         [
             "Kanehisa M",
             "Goto S",
             "Hattori M",
             "Aoki-Kinoshita KF",
             "Itoh M",
             "Kawashima S",
             "Katayama T",
             "Araki M",
             "Hirakawa M",
         ],
     )
Ejemplo n.º 29
0
def _download_entries(path, dbs=["reaction", "compound"]):
    """
    Returns jsons of entries of dbs (default: rn, cpd).
    """

    ## Create dir to store entries in
    entries_path = os.path.join(path, "entries")
    if not os.path.exists(entries_path):
        os.makedirs(entries_path)

    ## Get entries on all kegg types
    for db in dbs:

        print("Downloading %s entries..." % db)

        ## Read list of all kegg ids
        list_path = os.path.join(path, "lists", db + ".json")
        with open(list_path) as f:
            list_data = json.load(f)  #[0]

        ## Grab each entry in list
        entries = dict()
        for entry in tqdm(list_data):

            entry_id = entry.split(":")[1]
            # entry_fname = entry_id+".json"
            # entry_path = os.path.join(entries_path, entry_fname)

            while entry_id not in entries:
                try:
                    handle = TogoWS.entry(
                        db, entry_id, format="json"
                    )  ## Will always return something, even if entry doesn't exist
                    entries[entry_id] = json.loads(handle.read())[0]
                    # with open(entry_path, 'a') as f:
                    #     f.write(handle.read())
                except:
                    pass

        with open(os.path.join(entries_path, db + ".json"), 'w') as f:
            json.dump(entries, f, indent=2)
Ejemplo n.º 30
0
 def test_pubmed_16381885(self):
     """Bio.TogoWS.entry("pubmed", "16381885")"""
     # Gives Medline plain text
     handle = TogoWS.entry("pubmed", "16381885")
     data = Medline.read(handle)
     handle.close()
     self.assertEqual(data["TI"], "From genomics to chemical genomics: new developments in KEGG.")
     self.assertEqual(
         data["AU"],
         [
             "Kanehisa M",
             "Goto S",
             "Hattori M",
             "Aoki-Kinoshita KF",
             "Itoh M",
             "Kawashima S",
             "Katayama T",
             "Araki M",
             "Hirakawa M",
         ],
     )
Ejemplo n.º 31
0
 def test_nucleotide_genbank_length(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", field="length")"""
     handle = TogoWS.entry("nucleotide", "X52960", field="length")
     data = handle.read().strip() #ignore trailing \n
     handle.close()
     self.assertEqual(data, "248")
Ejemplo n.º 32
0
 def test_nucleotide_genbank_seq(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", field="seq")"""
     handle = TogoWS.entry("nucleotide", "X52960", field="seq")
     data = handle.read().strip() #ignore trailing \n
     handle.close()
     self.assertEqual(seguid(data), "Ktxz0HgMlhQmrKTuZpOxPZJ6zGU")
Ejemplo n.º 33
0
 def test_nucleotide_genbank_length(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", field="length")"""
     handle = TogoWS.entry("nucleotide", "X52960", field="length")
     data = handle.read().strip()  # ignore trailing \n
     handle.close()
     self.assertEqual(data, "248")
Ejemplo n.º 34
0
 def test_ddbj_genbank_length(self):
     """Bio.TogoWS.entry("genbank", "NC_000913.2", field="length")"""
     handle = TogoWS.entry("genbank", "NC_000913.2", field="length")
     data = handle.read().strip()  #ignore trailing \n
     handle.close()
     self.assertEqual(data, "4639675")
Ejemplo n.º 35
0
 def test_ddbj_genbank_length(self):
     """Bio.TogoWS.entry("genbank", "NC_000913.2", field="length")"""
     handle = TogoWS.entry("genbank", "NC_000913.2", field="length")
     data = handle.read().strip() #ignore trailing \n
     handle.close()
     self.assertEqual(data, "4639675")
Ejemplo n.º 36
0
Archivo: kegg.py Proyecto: bkaras1/ecg
    def update(self, metadata=True):
        warnings.warn("""
                        Updating will NOT reflect changes made to invdividual
                        entries' fields, and it will NOT remove entries which
                        have been removed from KEGG. It will only add entries
                        which have been added. To guarantee the most
                        up-to-date KEGG database, a full re-download is
                        necessary.
                        """)

        release_change = False
        list_change = False
        dbs = list(self.lists.keys())

        ## Check short_release differences
        old_release_short = self.version["current"]["release_short"]
        new_release = self.__retrieve_info(dbs)
        new_release_short = new_release["release_short"]

        if old_release_short != new_release_short:

            print("Release change identified")
            release_change = True

        ## Check list differences
        new_release["added"] = dict()
        new_release["removed"] = dict()

        old_lists = self.lists
        new_lists = self.__retrieve_lists(dbs)

        for db in dbs:
            old_keys = set(old_lists[db])
            new_keys = set(new_lists[db])
            if old_keys != new_keys:
                list_change = True
                print("Database list content change identified")
                new_release["added"][db] = list(new_keys - old_keys)
                new_release["removed"][db] = list(old_keys - new_keys)

        ## Update counts based on the lists
        counts = dict()
        for db in new_lists:
            counts[db] = len(new_lists[db])
        new_release["count_lists"] = counts

        ## Execute updating
        if release_change or list_change:
            print("Updating local kegg database...")

            ## Update version["updates"]
            self.version["updates"].append(
                copy.copy(new_release))  #prevents lists from being written
            # Includes the following keys:
            # added
            # removed
            # count_lists
            # count_info
            # release_short
            # release_long

            ## Update version["current"]
            # Adds the key for `lists`
            self.lists = new_lists
            new_release[
                "lists"] = self.lists  # this won't include entries which
            # have been removed but are still
            # in the entries dir
            self.version["current"] = new_release

            # print(type(new_release))
            # print(new_release)

            ## Rewrite version.json
            version_path = os.path.join(self.path, "version.json")
            with open(version_path, 'w') as f:
                json.dump(self.version, f, indent=2)

            ## Rewrite list jsons (fast)
            lists_path = os.path.join(self.path, "lists")
            for db in dbs:
                list_path = os.path.join(lists_path, db + ".json")
                with open(list_path, 'w') as f:
                    json.dump(self.lists[db], f, indent=2)

            ## Rewrite link jsons (fast)
            self._download_links(dbs)

            ## Add to entries jsons (does not remove `removed` entries)
            for db in new_release["added"]:
                entries_path = os.path.join(self.path, "entries", db)
                for entry in tqdm(new_release["added"][db]):

                    entry_id = entry.split(":")[1]
                    entry_fname = entry_id + ".json"
                    entry_path = os.path.join(entries_path, entry_fname)

                    while entry_fname not in os.listdir(entries_path):
                        try:
                            handle = TogoWS.entry(db, entry_id, format="json")
                            with open(entry_path, 'a') as f:
                                f.write(handle.read())
                        except:
                            pass

            ## Rewrite master json
            self._write_master(metadata)

            print("Done.")

        else:
            print(
                "No release or database list changes identified. \nNo updates available."
            )
Ejemplo n.º 37
0
 def test_embl_AM905444_gff3(self):
     """Bio.TogoWS.entry("embl", "AM905444", format="gff")"""
     handle = TogoWS.entry("embl", "AM905444", format="gff")
     data = handle.read()
     handle.close()
     self.assertTrue(data.startswith("##gff-version 3\nAM905444\tembl\t"), data)
Ejemplo n.º 38
0
 def test_nucleotide_genbank_acc_version(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", field="acc_version")"""
     handle = TogoWS.entry("nucleotide", "X52960", field="acc_version")
     data = handle.read().strip()  # ignore trailing \n
     handle.close()
     self.assertEqual(data, "X52960.1")
Ejemplo n.º 39
0
 def test_nucleotide_genbank_organism(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", field="organism")"""
     handle = TogoWS.entry("nucleotide", "X52960", field="organism")
     data = handle.read().strip() #ignore trailing \n
     handle.close()
     self.assertEqual(data, "Coleus blumei viroid 1")
Ejemplo n.º 40
0
 def test_embl_AM905444_seq(self):
     """Bio.TogoWS.entry("embl", "AM905444", field="seq")"""
     handle = TogoWS.entry("embl", "AM905444", field="seq")
     data = handle.read().strip() #ignore any trailing \n
     handle.close()
     self.assertEqual(seguid(data), "G0HtLpwF7i4FXUaUjDUPTjok79c")
Ejemplo n.º 41
0
 def test_nucleotide_genbank_seq(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", field="seq")"""
     handle = TogoWS.entry("nucleotide", "X52960", field="seq")
     data = handle.read().strip()  # ignore trailing \n
     handle.close()
     self.assertEqual(seguid(data), "Ktxz0HgMlhQmrKTuZpOxPZJ6zGU")
Ejemplo n.º 42
0
 def test_ddbj_gff3(self):
     """Bio.TogoWS.entry("ddbj", "X52960", format="gff")"""
     handle = TogoWS.entry("ddbj", "X52960", format="gff")
     data = handle.read()
     handle.close()
     self.assertTrue(data.startswith("##gff-version 3\nX52960\tDDBJ\t"), data)
Ejemplo n.º 43
0
 def test_nucleotide_genbank_organism(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", field="organism")"""
     handle = TogoWS.entry("nucleotide", "X52960", field="organism")
     data = handle.read().strip()  # ignore trailing \n
     handle.close()
     self.assertEqual(data, "Coleus blumei viroid 1")
Ejemplo n.º 44
0
 def test_nucleotide_genbank_definition(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", field="definition")"""
     handle = TogoWS.entry("nucleotide", "X52960", field="definition")
     data = handle.read().strip() #ignore trailing \n
     handle.close()
     self.assertEqual(data, "Coleus blumei viroid 1 (CbVd) RNA.")
Ejemplo n.º 45
0
 def test_ddbj_genbank_accession(self):
     """Bio.TogoWS.entry("ddbj", "X52960", field="version")"""
     handle = TogoWS.entry("ddbj", "X52960", field="version")
     data = handle.read().strip()  #ignore trailing \n
     handle.close()
     self.assertEqual(data, "1")
Ejemplo n.º 46
0
 def test_nucleotide_genbank_acc_version(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", field="acc_version")"""
     handle = TogoWS.entry("nucleotide", "X52960", field="acc_version")
     data = handle.read().strip() #ignore trailing \n
     handle.close()
     self.assertEqual(data, "X52960.1")
Ejemplo n.º 47
0
 def test_nucleotide_genbank_definition(self):
     """Bio.TogoWS.entry("nucleotide", "X52960", field="definition")"""
     handle = TogoWS.entry("nucleotide", "X52960", field="definition")
     data = handle.read().strip()  # ignore trailing \n
     handle.close()
     self.assertEqual(data, "Coleus blumei viroid 1 (CbVd) RNA.")
Ejemplo n.º 48
0
 def test_embl_AM905444_gff3(self):
     """Bio.TogoWS.entry("embl", "AM905444", format="gff")"""
     handle = TogoWS.entry("embl", "AM905444", format="gff")
     data = handle.read()
     handle.close()
     self.assert_(data.startswith("##gff-version 3\nAM905444\tembl\t"), data)
Ejemplo n.º 49
0
 def test_embl_AM905444_seq(self):
     """Bio.TogoWS.entry("embl", "AM905444", field="seq")"""
     handle = TogoWS.entry("embl", "AM905444", field="seq")
     data = handle.read().strip()  # ignore any trailing \n
     handle.close()
     self.assertEqual(seguid(data), "G0HtLpwF7i4FXUaUjDUPTjok79c")
Ejemplo n.º 50
0
 def test_embl_AM905444_definition(self):
     """Bio.TogoWS.entry("embl", "AM905444", field="definition")"""
     handle = TogoWS.entry("embl", "AM905444", field="definition")
     data = handle.read().strip() #ignore any trailing \n
     handle.close()
     self.assertEqual(data, "Herbaspirillum seropedicae locus tag HS193.0074 for porin")
Ejemplo n.º 51
0
 def test_ddbj_genbank_accession(self):
     """Bio.TogoWS.entry("ddbj", "X52960", field="version")"""
     handle = TogoWS.entry("ddbj", "X52960", field="version")
     data = handle.read().strip() #ignore trailing \n
     handle.close()
     self.assertEqual(data, "1")
Ejemplo n.º 52
0
 def test_embl_AM905444_definition(self):
     """Bio.TogoWS.entry("embl", "AM905444", field="definition")"""
     handle = TogoWS.entry("embl", "AM905444", field="definition")
     data = handle.read().strip()  # ignore any trailing \n
     handle.close()
     self.assertEqual(data, "Herbaspirillum seropedicae locus tag HS193.0074 for porin")
Ejemplo n.º 53
0
 def test_ddbj_gff3(self):
     """Bio.TogoWS.entry("ddbj", "X52960", format="gff")"""
     handle = TogoWS.entry("ddbj", "X52960", format="gff")
     data = handle.read()
     handle.close()
     self.assertTrue(data.startswith("##gff-version 3\nX52960\tDDBJ\t"), data)