Beispiel #1
0
 def test_exceptions(self):
     with open("KEGG/enzyme.sample") as handle:
         with self.assertRaises(ValueError) as context:
             list(Enzyme.read(handle))
         self.assertTrue("More than one record found in handle" in str(context.exception))
         records = Enzyme.parse(handle)
         for i in range(0, 6):
             next(records)
         self.assertRaises(StopIteration, next, records)
Beispiel #2
0
 def test_exceptions(self):
     with open("KEGG/enzyme.sample") as handle:
         with self.assertRaises(ValueError) as context:
             list(Enzyme.read(handle))
         self.assertIn("More than one record found in handle",
                       str(context.exception))
         records = Enzyme.parse(handle)
         for i in range(0, 6):
             next(records)
         self.assertRaises(StopIteration, next, records)
Beispiel #3
0
 def test_irregular(self):
     """enzyme.irregular tests."""
     with open("KEGG/enzyme.irregular") as handle:
         records = list(Enzyme.parse(handle))
     self.assertEqual(len(records), 2)
     self.assertEqual(records[0].entry, "1.14.18.1")
     self.assertEqual(records[-1].entry, "3.4.21.50")
Beispiel #4
0
 def test_sample(self):
     with open("KEGG/enzyme.sample") as handle:
         records = list(Enzyme.parse(handle))
     self.assertEqual(len(records), 8)
     self.assertEqual(records[0].entry, "1.1.1.1")
     self.assertEqual(records[0].name,
                      ['Alcohol dehydrogenase', 'Aldehyde reductase'])
     self.assertEqual(records[0].pathway,
                      [('PATH', 'MAP00010', 'Glycolysis / Gluconeogenesis'),
                       ('PATH', 'MAP00071', 'Fatty acid metabolism'),
                       ('PATH', 'MAP00120', 'Bile acid biosynthesis'),
                       ('PATH', 'MAP00350', 'Tyrosine metabolism'),
                       ('PATH', 'MAP00561', 'Glycerolipid metabolism')])
     self.assertEqual(records[0].structures,
                      [('PDB', ['1A4U', '1A71', '1A72', '1ADB', '1ADC',
                                '1ADF', '1ADG', '1AGN', '1AXE', '1AXG',
                                '1B14', '1B15', '1B16', '1B2L', '1BTO',
                                '1CDO', '1D1S', '1D1T', '1DDA', '1DEH',
                                '1E3E', '1E3I', '1E3L', '1EE2', '1HDX',
                                '1HDY', '1HDZ', '1HET', '1HEU', '1HF3',
                                '1HLD', '1HSO', '1HSZ', '1HT0', '1HTB',
                                '1LDE', '1LDY', '1QLH', '1QLJ', '1TEH',
                                '2OHX', '2OXI', '3BTO', '3HUD', '5ADH',
                                '6ADH', '7ADH'])])
     self.assertEqual(records[0].dblinks,
                      [('IUBMB Enzyme Nomenclature', ['1.1.1.1']),
                       ('ExPASy - ENZYME nomenclature database', ['1.1.1.1']),
                       ('WIT (What Is There) Metabolic Reconstruction', ['1.1.1.1']),
                       ('BRENDA, the Enzyme Database', ['1.1.1.1']),
                       ('SCOP (Structural Classification of Proteins)', ['1.1.1.1'])])
     self.assertEqual(records[-1].entry, "2.7.2.1")
Beispiel #5
0
 def test_4letter(self):
     with open("KEGG/enzyme.4letter") as handle:
         records = list(Enzyme.parse(handle))
         self.assertEqual(len(records), 1)
     self.assertEqual(records[0].entry, "5.4.2.2")
     self.assertEqual(records[0].genes[0], ("HSA", ["5236", "55276"]))
     self.assertEqual(records[0].genes[8],
                      ("CSAB", ["103224690", "103246223"]))
Beispiel #6
0
 def test_4letter(self):
     with open("KEGG/enzyme.4letter") as handle:
         records = list(Enzyme.parse(handle))
         self.assertEqual(len(records), 1)
     self.assertEqual(records[0].entry, "5.4.2.2")
     self.assertEqual(records[0].genes[0], ('HSA', ['5236', '55276']))
     self.assertEqual(records[0].genes[8],
                      ('CSAB', ['103224690', '103246223']))
Beispiel #7
0
def t_KEGG_Enzyme(testfiles):
    """Tests Bio.KEGG.Enzyme functionality."""
    for file in testfiles:
        fh = open(os.path.join("KEGG", file))
        print "Testing Bio.KEGG.Enzyme on " + file + "\n\n"
        records = Enzyme.parse(fh)
        for record in records:
            print record
        print "\n"
Beispiel #8
0
 def test_4letter(self):
     with open("KEGG/enzyme.4letter") as handle:
         records = list(Enzyme.parse(handle))
         self.assertEqual(len(records), 1)
     self.assertEqual(records[0].entry, "5.4.2.2")
     self.assertEqual(records[0].genes[0],
                      ('HSA', ['5236', '55276']))
     self.assertEqual(records[0].genes[8],
                      ('CSAB', ['103224690', '103246223']))
Beispiel #9
0
def t_KEGG_Enzyme(testfiles):
    """Tests Bio.KEGG.Enzyme functionality."""
    for file in testfiles:
        fh = open(os.path.join("KEGG", file))
        print("Testing Bio.KEGG.Enzyme on " + file + "\n\n")
        records = Enzyme.parse(fh)
        for record in records:
            print(record)
        print("\n")
        fh.close()
Beispiel #10
0
def get_kegg_annotation():
    """
    Get annotation ec:5.4.2.2 from kegg database and write to txt file.
    Print annotation
    :return:
    """
    request = REST.kegg_get("ec:5.4.2.2")
    open("ec_5.4.2.2.txt", "w").write(request.read())
    records = Enzyme.parse(open("ec_5.4.2.2.txt"))
    record = list(records)[0]
    print(record.classname)
def t_KEGG_Enzyme(testfiles):
    """Tests Bio.KEGG.Enzyme functionality."""
    for file in testfiles:
        fh = open(os.path.join("KEGG", file))
        print("Testing Bio.KEGG.Enzyme on " + file + "\n\n")
        records = Enzyme.parse(fh)
        for i, record in enumerate(records):
            print(record)

        fh.seek(0)
        if i == 0:
            print(Enzyme.read(fh))
        else:
            try:
                print(Enzyme.read(fh))
                assert False
            except ValueError as e:
                assert str(e) == 'More than one record found in handle'

        print("\n")
        fh.close()
Beispiel #12
0
 def test_sample(self):
     with open("KEGG/enzyme.sample") as handle:
         records = list(Enzyme.parse(handle))
     self.assertEqual(len(records), 8)
     self.assertEqual(records[0].entry, "1.1.1.1")
     self.assertEqual(records[0].name, [
         'alcohol dehydrogenase', 'aldehyde reductase', 'ADH',
         'alcohol dehydrogenase (NAD)', 'aliphatic alcohol dehydrogenase',
         'ethanol dehydrogenase', 'NAD-dependent alcohol dehydrogenase',
         'NAD-specific aromatic alcohol dehydrogenase',
         'NADH-alcohol dehydrogenase', 'NADH-aldehyde dehydrogenase',
         'primary alcohol dehydrogenase', 'yeast alcohol dehydrogenase'
     ])
     self.assertEqual(
         records[0].pathway,
         [('PATH', 'ec00010', 'Glycolysis / Gluconeogenesis'),
          ('PATH', 'ec00071', 'Fatty acid degradation'),
          ('PATH', 'ec00260', 'Glycine, serine and threonine metabolism'),
          ('PATH', 'ec00350', 'Tyrosine metabolism'),
          ('PATH', 'ec00592', 'alpha-Linolenic acid metabolism'),
          ('PATH', 'ec00625', 'Chloroalkane and chloroalkene degradation'),
          ('PATH', 'ec00626', 'Naphthalene degradation'),
          ('PATH', 'ec00830', 'Retinol metabolism'),
          ('PATH', 'ec00980',
           'Metabolism of xenobiotics by cytochrome P450'),
          ('PATH', 'ec00982', 'Drug metabolism - cytochrome P450'),
          ('PATH', 'ec01100', 'Metabolic pathways'),
          ('PATH', 'ec01110', 'Biosynthesis of secondary metabolites'),
          ('PATH', 'ec01120',
           'Microbial metabolism in diverse environments'),
          ('PATH', 'ec01130', 'Biosynthesis of antibiotics')])
     self.assertEqual(
         records[0].dblinks,
         [('ExplorEnz - The Enzyme Database', ['1.1.1.1']),
          ('IUBMB Enzyme Nomenclature', ['1.1.1.1']),
          ('ExPASy - ENZYME nomenclature database', ['1.1.1.1']),
          ('UM-BBD (Biocatalysis/Biodegradation Database)', ['1.1.1.1']),
          ('BRENDA, the Enzyme Database', ['1.1.1.1']),
          ('CAS', ['9031-72-5'])])
     self.assertEqual(records[-1].entry, "2.7.2.1")
     self.assertEqual(
         str(records[-1]).replace(" ", "").split("\n")[:10], [
             'ENTRYEC2.7.2.1', 'NAMEacetatekinase', 'acetokinase', 'AckA',
             'AK', 'acetickinase', 'acetatekinase(phosphorylating)',
             'CLASSTransferases;',
             'Transferringphosphorus-containinggroups;',
             'Phosphotransferaseswithacarboxygroupasacceptor'
         ])
Beispiel #13
0
 def test_sample(self):
     with open("KEGG/enzyme.sample") as handle:
         records = list(Enzyme.parse(handle))
     self.assertEqual(len(records), 8)
     self.assertEqual(records[0].entry, "1.1.1.1")
     self.assertEqual(records[0].name, [
         "alcohol dehydrogenase", "aldehyde reductase", "ADH",
         "alcohol dehydrogenase (NAD)", "aliphatic alcohol dehydrogenase",
         "ethanol dehydrogenase", "NAD-dependent alcohol dehydrogenase",
         "NAD-specific aromatic alcohol dehydrogenase",
         "NADH-alcohol dehydrogenase", "NADH-aldehyde dehydrogenase",
         "primary alcohol dehydrogenase", "yeast alcohol dehydrogenase"
     ])
     self.assertEqual(
         records[0].pathway,
         [("PATH", "ec00010", "Glycolysis / Gluconeogenesis"),
          ("PATH", "ec00071", "Fatty acid degradation"),
          ("PATH", "ec00260", "Glycine, serine and threonine metabolism"),
          ("PATH", "ec00350", "Tyrosine metabolism"),
          ("PATH", "ec00592", "alpha-Linolenic acid metabolism"),
          ("PATH", "ec00625", "Chloroalkane and chloroalkene degradation"),
          ("PATH", "ec00626", "Naphthalene degradation"),
          ("PATH", "ec00830", "Retinol metabolism"),
          ("PATH", "ec00980",
           "Metabolism of xenobiotics by cytochrome P450"),
          ("PATH", "ec00982", "Drug metabolism - cytochrome P450"),
          ("PATH", "ec01100", "Metabolic pathways"),
          ("PATH", "ec01110", "Biosynthesis of secondary metabolites"),
          ("PATH", "ec01120",
           "Microbial metabolism in diverse environments"),
          ("PATH", "ec01130", "Biosynthesis of antibiotics")])
     self.assertEqual(
         records[0].dblinks,
         [("ExplorEnz - The Enzyme Database", ["1.1.1.1"]),
          ("IUBMB Enzyme Nomenclature", ["1.1.1.1"]),
          ("ExPASy - ENZYME nomenclature database", ["1.1.1.1"]),
          ("UM-BBD (Biocatalysis/Biodegradation Database)", ["1.1.1.1"]),
          ("BRENDA, the Enzyme Database", ["1.1.1.1"]),
          ("CAS", ["9031-72-5"])])
     self.assertEqual(records[-1].entry, "2.7.2.1")
     self.assertEqual(
         str(records[-1]).replace(" ", "").split("\n")[:10], [
             "ENTRYEC2.7.2.1", "NAMEacetatekinase", "acetokinase", "AckA",
             "AK", "acetickinase", "acetatekinase(phosphorylating)",
             "CLASSTransferases;",
             "Transferringphosphorus-containinggroups;",
             "Phosphotransferaseswithacarboxygroupasacceptor"
         ])
Beispiel #14
0
 def test_sample(self):
     with open("KEGG/enzyme.sample") as handle:
         records = list(Enzyme.parse(handle))
     self.assertEqual(len(records), 8)
     self.assertEqual(records[0].entry, "1.1.1.1")
     self.assertEqual(records[0].name,
                      ['alcohol dehydrogenase',
                       'aldehyde reductase',
                       'ADH',
                       'alcohol dehydrogenase (NAD)',
                       'aliphatic alcohol dehydrogenase',
                       'ethanol dehydrogenase',
                       'NAD-dependent alcohol dehydrogenase',
                       'NAD-specific aromatic alcohol dehydrogenase',
                       'NADH-alcohol dehydrogenase',
                       'NADH-aldehyde dehydrogenase',
                       'primary alcohol dehydrogenase',
                       'yeast alcohol dehydrogenase'])
     self.assertEqual(records[0].pathway,
                      [('PATH', 'ec00010', 'Glycolysis / Gluconeogenesis'),
                       ('PATH', 'ec00071', 'Fatty acid degradation'),
                       ('PATH', 'ec00260', 'Glycine, serine and threonine metabolism'),
                       ('PATH', 'ec00350', 'Tyrosine metabolism'),
                       ('PATH', 'ec00592', 'alpha-Linolenic acid metabolism'),
                       ('PATH', 'ec00625', 'Chloroalkane and chloroalkene degradation'),
                       ('PATH', 'ec00626', 'Naphthalene degradation'),
                       ('PATH', 'ec00830', 'Retinol metabolism'),
                       ('PATH', 'ec00980', 'Metabolism of xenobiotics by cytochrome P450'),
                       ('PATH', 'ec00982', 'Drug metabolism - cytochrome P450'),
                       ('PATH', 'ec01100', 'Metabolic pathways'),
                       ('PATH', 'ec01110', 'Biosynthesis of secondary metabolites'),
                       ('PATH', 'ec01120', 'Microbial metabolism in diverse environments'),
                       ('PATH', 'ec01130', 'Biosynthesis of antibiotics')])
     self.assertEqual(records[0].dblinks,
                      [('ExplorEnz - The Enzyme Database', ['1.1.1.1']),
                       ('IUBMB Enzyme Nomenclature', ['1.1.1.1']),
                       ('ExPASy - ENZYME nomenclature database', ['1.1.1.1']),
                       ('UM-BBD (Biocatalysis/Biodegradation Database)', ['1.1.1.1']),
                       ('BRENDA, the Enzyme Database', ['1.1.1.1']),
                       ('CAS', ['9031-72-5'])])
     self.assertEqual(records[-1].entry, "2.7.2.1")
     self.assertEqual(str(records[-1]).replace(" ", "").split("\n")[:10],
                      ['ENTRYEC2.7.2.1', 'NAMEacetatekinase', 'acetokinase',
                       'AckA', 'AK', 'acetickinase', 'acetatekinase(phosphorylating)',
                       'CLASSTransferases;', 'Transferringphosphorus-containinggroups;',
                       'Phosphotransferaseswithacarboxygroupasacceptor'])
Beispiel #15
0
def create_enzyme_df(path_to_file):
    """
    input:path_to_file. file.gz format
    output:enzyme dataframe
    """

    enzyme_fields = [
        method for method in dir(Enzyme.Record()) if not method.startswith('_')
    ]
    data_matrix = []

    with gzip.open(path_to_file, 'rt') as file:
        for record in enzyme.parse(file):
            data_matrix.append(
                [getattr(record, field) for field in enzyme_fields])

    enzyme_df = pd.DataFrame(data_matrix, columns=enzyme_fields)
    return enzyme_df
def convert(id):
    """Fetches an EC ID from the KEGG REST API, parses it, and writes a GO record."""

    # this is a dumb way of doing it, too much of a python noob to figure a better way
    txt = fetch(id)
    fn = "target/"+id+".kml"
    fh = open(fn, "w")
    fh.write(str(txt))
    fh.close()
    fh = open(fn)

    records = Enzyme.parse(fh)
    n = 0
    for record in records:
        write_obo(record)
        n=n+1
    if n==0:
        print("FAIL")
    fh.close()
Beispiel #17
0
def convert(id):
    """Fetches an EC ID from the KEGG REST API, parses it, and writes a GO record."""

    # this is a dumb way of doing it, too much of a python noob to figure a better way
    txt = fetch(id)
    fn = "target/" + id + ".kml"
    fh = open(fn, "w")
    fh.write(str(txt))
    fh.close()
    fh = open(fn)

    records = Enzyme.parse(fh)
    n = 0
    for record in records:
        write_obo(record)
        n = n + 1
    if n == 0:
        print("FAIL")
    fh.close()
Beispiel #18
0
from Bio.KEGG import REST
from Bio.KEGG import Enzyme

request = REST.kegg_get("ec:7.1.2.2")
# 참고: ATP synthase의 EC번호이다
open("ec_7.1.2.2.txt", "w").write(request.read())
records = Enzyme.parse(open("ec_7.1.2.2.txt"))
record = list(records)[0]
print(record.classname)
from Bio.KEGG import Enzyme
records = Enzyme.parse(open("/home/koreanraichu/ec_5.4.2.2.txt"))
record = list(records)[0]
print(record.classname)
Beispiel #20
0
#!/usr/bin/env python3
from Bio.KEGG import REST
from Bio.KEGG import Enzyme

file = open("entries", "r")

lines = file.readlines()
lines = list(map(str.strip, lines))
from pprint import pprint


for line in lines:
    request = REST.kegg_get(line)
    a = request.read()
    open("temp.txt", "w").write(a)
    records = Enzyme.parse(open("temp.txt"))
    try:
        record = list(records)[0]
    except:
        print(f"nie udalo sie znalezc {line}")
        continue

    res = ""
    for x in record.name:
        res += x

    # to make it work you need to add parsing description in biopython
    record.description = "DUMMY"

    print(line, res, record.description) # record.classname, record.sysname)
    # pprint(vars(record))
Beispiel #21
0
from Bio.KEGG import REST
from Bio.KEGG import Enzyme

request = REST.kegg_get("ec:2.7.7.9")
open("ec_2.7.7.9.txt", "w").write(request.read())
records = Enzyme.parse(open("ec_2.7.7.9.txt"))
record = list(records)[0]
record.classname
record.entry
Beispiel #22
0
 def test_new(self):
     with open("KEGG/enzyme.new") as handle:
         records = list(Enzyme.parse(handle))
     self.assertEqual(len(records), 1)
     self.assertEqual(records[0].entry, "6.2.1.25")
Beispiel #23
0
 def test_irregular(self):
     with open("KEGG/enzyme.irregular") as handle:
         records = list(Enzyme.parse(handle))
     self.assertEqual(len(records), 2)
     self.assertEqual(records[0].entry, "1.14.18.1")
     self.assertEqual(records[-1].entry, "3.4.21.50")
Beispiel #24
0
 def test_sample(self):
     with open("KEGG/enzyme.sample") as handle:
         records = list(Enzyme.parse(handle))
     self.assertEqual(len(records), 8)
     self.assertEqual(records[0].entry, "1.1.1.1")
     self.assertEqual(records[-1].entry, "2.7.2.1")
Beispiel #25
0
#12.3.KEGG_Enzyme_example.py

from Bio.KEGG import Enzyme

records = Enzyme.parse(open("ec_2.7.1.40.txt"))
record = list(records)[0]
print("classname:", record.classname)
print("sysname:", record.sysname)
print("subtrate:", record.substrate)
print("product:", record.product)

Beispiel #26
0
 def test_new(self):
     with open("KEGG/enzyme.new") as handle:
         records = list(Enzyme.parse(handle))
     self.assertEqual(len(records), 1)
     self.assertEqual(records[0].entry, "6.2.1.25")
def KEGG(input1, input2):
    # Perform the query
    result = REST.kegg_info("kegg").read()

    # Print overview
    if input1 == "info" and input2 == "alt":
        return print(result)

    # Get all entries in the PATHWAY database as a dataframe
    elif input1 == "pathway_overview" and input2 == "alle":
        result = REST.kegg_list("pathway").read()
        return to_df(result)

    #Print alle biosynteseveje
    elif input1 == "print_pathway":
        if input2 == "alle":
            result = REST.kegg_get("map01100", "image").read()
            img = Image(result, width=1500, height=1000)
        else:
            result = REST.kegg_get(input2, "image").read()
            img = Image(result)
        return img

    #Find the compund vanillin
    elif input1 == "find_molekyle" and input2 != None:
        result = REST.kegg_find("compound", input2).read()  #cpd:C00755
        return print(result)

    elif input1 == "info_molekyle" and input2 != None:  #cpd:C00755
        # Get the entry information for vanillin
        result = REST.kegg_get(input2).read()
        return print(result)

    # Display molekylær struktur for cpd:C00051 (vanillin)
    elif input1 == "molekyle billede" and input2 != None:
        result = REST.kegg_get(input2, "image").read()  #"cpd:C00755"
        return Image(result)

    elif input1 == "Enzyme molekyle" and input2 != None:
        result = REST.kegg_find("enzyme", input2).read()
        return to_df(result)

    #Enzym delen
    from Bio.KEGG import Enzyme
    request = REST.kegg_get(input1)
    records = Enzyme.parse(request)
    record = list(records)[0]

    if input2 == "reaction":
        return record.reaction

    elif input2 == "classname":
        return record.classname

    elif input2 == "genes":
        genes = list()
        for g in record.genes:
            gene_id, gene_symbol = g
            genes.append(gene_id)
        return genes
    else:
        print("Du har indskrevet nogget der ikke er gældende. Prøv igen")