Skip to content

Commit

Permalink
Major improvements in visualization
Browse files Browse the repository at this point in the history
KOs now converted to EC numbers directly to the maps
No more gray outline boxes
Exception for loading metabolic map improved
  • Loading branch information
iquasere committed Sep 8, 2020
1 parent fce16cf commit 0eb18a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions kegg_charter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from io import StringIO
from matplotlib import colors, cm
import argparse, pandas as pd, numpy as np, os, pathlib, PIL, re, sys, subprocess
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt, traceback

__version__ = "0.1.0"
__version__ = "0.1.1"

class KEGGCharter:

Expand Down Expand Up @@ -506,6 +506,7 @@ def main(self):
differential_no_kos.append(metabolic_map)
plt.close()
except Exception as e:
print(traceback.format_exc())
print('[{}/{}] Representation of pathway [{}] has failed!'.format(
str(i), str(len(metabolic_maps)), metabolic_map))
print(e)
Expand Down
19 changes: 10 additions & 9 deletions kegg_pathway_map.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

from Bio.KEGG.KGML import KGML_parser, KGML_pathway
from Bio.KEGG.REST import kegg_get
from Bio.KEGG.REST import kegg_get, kegg_link
from Bio.Graphics.KGML_vis import KGMLCanvas
from matplotlib import colors, cm

Expand Down Expand Up @@ -86,7 +86,7 @@ def set_pathway(self, data, pathway_ID, ko_column, ec_column):
self.ko_boxes = dict()
for i in range(len(self.pathway.orthologs)):
self.set_bgcolor(self.pathway.orthologs[i], "#ffffff") # set all boxes to white
self.set_fgcolor(self.pathway.orthologs[i], "#ffffff") # ditto
#self.set_fgcolor(self.pathway.orthologs[i], "#ffffff") # This might be helpful in the future, if an additional layer of marking is needed
orthologs_in_box = [ide[3:] for ide in self.pathway.orthologs[i].name.split()] # 'ko:K16157 ko:K16158 ko:K16159' -> ['K16157', 'K16158', 'K16159']
for ortholog in orthologs_in_box:
if ortholog not in self.ko_boxes.keys():
Expand All @@ -95,15 +95,16 @@ def set_pathway(self, data, pathway_ID, ko_column, ec_column):
ko.append(self.pathway.orthologs[i].graphics[0].name.rstrip(".")) # 'K16157...' -> 'K16157'

# Set text in boxes to EC numbers
data = data[data[ec_column].notnull()][[ko_column, ec_column]]
ko_to_ec = {data.iloc[i][ko_column]:data.iloc[i][ec_column]
for i in range(len(data))} # {'K16157':'ec:1.14.13.25'}
for ortholog_rec in self.pathway.orthologs:
ko = ortholog_rec.graphics[0].name.strip(".")
if ko in ko_to_ec.keys():
ortholog_rec.graphics[0].name = ko_to_ec[ko]
ecs = list()
kos = ortholog_rec.name.split()
for ko in kos:
lines = kegg_link("enzyme", ko).read().split('\n')
ecs += [line.split('\t')[1] for line in lines if len(line) > 0]
if len(ecs) > 0:
ortholog_rec.graphics[0].name = max(set(ecs), key = ecs.count).upper()
else:
ortholog_rec.graphics[0].name = ko
ortholog_rec.graphics[0].name = kos[0][3:]

############################################################################
#### Graphical Manipulation ####
Expand Down
2 changes: 1 addition & 1 deletion meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set name = "keggcharter" %}
{% set version = "0.1.0" %}
{% set version = "0.1.1" %}
{% set sha256 = "905268158c74058228faca2b34d44eae8f84b23bfa5dee49285635cf59684d7f" %}

package:
Expand Down

0 comments on commit 0eb18a5

Please sign in to comment.