Skip to content

Commit

Permalink
Downloading maps can now fail
Browse files Browse the repository at this point in the history
-Error is catched by exception
Reformulated meta.yaml to keep things out of /bin
Added openpyxl to read EXCELs
  • Loading branch information
iquasere committed Jul 29, 2020
1 parent 6ddd5a1 commit 419070e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
2 changes: 1 addition & 1 deletion install.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

conda install -y -c conda-forge matplotlib progressbar
conda install -y -c anaconda pandas biopython reportlab # reportlab for Bio.Graphics (Biopython)
conda install -y -c anaconda pandas biopython reportlab openpyxl # reportlab for Bio.Graphics (Biopython)
65 changes: 35 additions & 30 deletions kegg_charter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import argparse, pandas as pd, numpy as np, os, pathlib, PIL, re, sys, subprocess
import matplotlib.pyplot as plt

__version__ = "0.0.3"
__version__ = "0.0.4"

class KEGGCharter:

Expand All @@ -34,9 +34,9 @@ def get_arguments(self):
parser.add_argument("-mtc", "--metatranscriptomic-columns", type = str,
help = "Names of columns with metatranscriptomics quantification")
parser.add_argument("-tc", "--taxa-column", type = str, default = 'Taxonomic lineage(GENUS)',
help = "Column with the taxa designations to represent with KEGGChart")
help = "Column with the taxa designations to represent with KEGGChart") # TODO - test this argument without UniProt shenanigans
parser.add_argument("-tls", "--taxa-list", type = str,
help = "List of taxa to represent in genomic potential charts (comma separated)")
help = "List of taxa to represent in genomic potential charts (comma separated)") # TODO - must be tested
parser.add_argument("-not", "--number-of-taxa", type = str,
help = "Number of taxa to represent in genomic potential charts (comma separated)",
default = '10')
Expand Down Expand Up @@ -459,9 +459,6 @@ def main(self):
self.timed_message('Creating KEGG Pathway representations for {} metabolic pathways.'.format(
str(len(metabolic_maps))))

not_loaded = list(); differential_no_kos = list()
i = 1

# Set colours for taxa if MG data is present
if hasattr(args, 'metagenomic_columns'):
args.metagenomic_columns = args.metagenomic_columns.split(',')
Expand All @@ -478,36 +475,44 @@ def main(self):
if hasattr(args, 'metatranscriptomic_columns'):
args.metatranscriptomic_columns = args.metatranscriptomic_columns.split(',')

i = 1
failed_maps = list(); differential_no_kos = list()

# For each metabolic map, will chart genomic potential and differential expression if MG and MT data are available, respectively
for metabolic_map in metabolic_maps:
kegg_pathway_map = KEGGPathwayMap(data, metabolic_map) # if getting 404 here, is likely because map doesn't exist # TODO - put something here to inform users to report that problem
print('[{}/{}] Creating representation for pathway: {}'.format(
str(i), str(len(metabolic_maps)),
kegg_pathway_map.pathway.title))
if args.metagenomic_columns:
kegg_pathway_map = KEGGPathwayMap(data, metabolic_map)
if args.uniprot_taxonomic_columns:
args.taxa_column = 'Taxonomic lineage ({})'.format(args.taxonomic_level.upper())
self.genomic_potential_taxa(kegg_pathway_map, data,
args.metagenomic_columns, dic_colors,
taxa_column = args.taxa_column,
output_basename = args.output + '/potential') # TODO - log should be True, fix the other TODO
if args.metatranscriptomic_columns:
kegg_pathway_map = KEGGPathwayMap(data, metabolic_map)
saul_good = self.differential_expression_sample(kegg_pathway_map, data,
args.metatranscriptomic_columns,
output_basename = args.output + '/differential',
log = False)
if saul_good == 1:
differential_no_kos.append(metabolic_map)
plt.close()
try:
kegg_pathway_map = KEGGPathwayMap(data, metabolic_map) # if getting 404 here, is likely because map doesn't exist # TODO - put something here to inform users to report that problem
print('[{}/{}] Creating representation for pathway [{}]: {}'.format(
str(i), str(len(metabolic_maps)), metabolic_map,
kegg_pathway_map.pathway.title))
if args.metagenomic_columns:
kegg_pathway_map = KEGGPathwayMap(data, metabolic_map)
if args.uniprot_taxonomic_columns:
args.taxa_column = 'Taxonomic lineage ({})'.format(args.taxonomic_level.upper())
self.genomic_potential_taxa(kegg_pathway_map, data,
args.metagenomic_columns, dic_colors,
taxa_column = args.taxa_column,
output_basename = args.output + '/potential') # TODO - log should be True, fix the other TODO
if args.metatranscriptomic_columns:
kegg_pathway_map = KEGGPathwayMap(data, metabolic_map)
saul_good = self.differential_expression_sample(kegg_pathway_map, data,
args.metatranscriptomic_columns,
output_basename = args.output + '/differential',
log = False)
if saul_good == 1:
differential_no_kos.append(metabolic_map)
plt.close()
except:
print('[{}/{}] Representation of pathway [{}] has failed!'.format(
str(i), str(len(metabolic_maps)), metabolic_map))
failed_maps.append(metabolic_map)
i += 1

not_loaded_filename = args.output + '/not_loaded.txt'
failed_maps_filename = args.output + '/failed_maps.txt'
no_kos_filename = args.output + '/no_kos.txt'
print('{} maps could not be loaded. You can see which ones at {}'.format(
len(not_loaded), not_loaded_filename))
open(not_loaded_filename, 'w').write('\n'.join(not_loaded))
len(failed_maps), failed_maps_filename))
open(failed_maps_filename, 'w').write('\n'.join(failed_maps))
print('{} maps had no KOs attributed to them. You can see which ones at {}'.format(
len(differential_no_kos), no_kos_filename))
open(no_kos_filename, 'w').write('\n'.join(differential_no_kos))
Expand Down
12 changes: 9 additions & 3 deletions meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set name = "keggcharter" %}
{% set version = "0.0.3" %}
{% set sha256 = "c824ad580a422a55073d569e1567a255472b90ea428af7cf990022522a5587e9" %}
{% set version = "0.0.4" %}
{% set sha256 = "3031f4aed298df068aa6fd3d9f70b10b4b6974eb6221abb3e4fcccec74488f98" %}

package:
name: {{ name|lower }}
Expand All @@ -13,7 +13,13 @@ source:
build:
noarch: generic
number: 0
script: "mkdir -p $PREFIX/bin && cp *.py KEGGCharter_prokaryotic_maps.txt $PREFIX/bin"
script: |
dir="${PREFIX}/share/KEGGCharter"
mkdir -p "${dir}"
cp *.py KEGGCharter_prokaryotic_maps.txt "${dir}/"
mkdir -p "${PREFIX}/bin"
chmod +x "${dir}/kegg_charter.py"
ln -s "${dir}/kegg_charter.py" "${PREFIX}/bin/"
requirements:
run:
Expand Down

0 comments on commit 419070e

Please sign in to comment.