Commit 0e62d05e authored by AITE Meziane's avatar AITE Meziane

Merge branch 'python3' into 'master'

Convert to Python3

See merge request !1
parents 59058645 d480fd48
This diff is collapsed.
---
title: padmet-utils - Documentation
author: Meziane AITE
date: 2017-06-19
version: 2.5
date: 2018-07-12
version: 3.0.1
---
################################################################################
##Descirption
The main concept underlying padmet-utils is to provide solutions that ensure the consistency, the internal standardization and the reconciliation of the information used within any workflow that combines several tools involving metabolic networks reconstruction or analysis. The PADMet package is at the core of the AuReMe workflow, dedicated to the primary reconstruction of genome-scale metabolic networks from raw data. It allows the study of organisms for which few experimental data are available. Its main feature is to undergo the reconstruction of the metabolic network by combining several
heterogeneous knowledge and data sources, including the information reported by several scaffold metabolic networks for cousin species.
## Description
The main concept underlying padmet-utils is to provide solutions that ensure the consistency, the internal standardization and the reconciliation of the information used within any workflow that combines several tools involving metabolic networks reconstruction or analysis. The PADMet package is at the core of the AuReMe workflow, dedicated to the primary reconstruction of genome-scale metabolic networks from raw data. It allows the study of organisms for which few experimental data are available. Its main feature is to undergo the reconstruction of the metabolic network by combining several heterogeneous knowledge and data sources, including the information reported by several scaffold metabolic networks for cousin species.
## Installation
From git repository:
cd ~/programs
git clone https://gitlab.inria.fr/maite/padmet-utils.git
## Architecture
......@@ -32,7 +33,7 @@ From git repository:
│ ├── extract_rxn_with_gene_assoc.py
│ ├── gbk_to_faa.py
│ ├── gene_to_targets.py
│ ├── gramma-boolean-rapsody.py
│ ├── grammar-boolean-rapsody.py
│ ├── padmet_to_askomic.py
│ ├── padmet_to_asp.py
│ ├── padmet_to_sbml.py
......@@ -82,9 +83,10 @@ From git repository:
##Documentation
## Documentation
.aureme.add_seeds_reactions.py
Description:
For a given set of compounds representing the growth medium (or seeds). Create 2 reactions
for each compounds to maintain consistency of the network for flux analysis.
......@@ -111,6 +113,7 @@ From git repository:
-v print info
.aureme.compounds_to_sbml.py
Convert a list of compounds to an sbml file. Often in sbml, the compartment of the
compounds is concatenate to the id. If wanted, possible to add a compart each compounds with compart_name
If verbose, will also check if each compound is in a padmetRef and or a padmetSpec
......@@ -131,6 +134,7 @@ From git repository:
-v print info and check if ids in padmetRef and or padmet
.aureme.enhanced_meneco_output.py
Description:
The standard output of meneco return ids of reactions corresponding to the solution for gapfilling.
The ids are those from the sbml and so they are encoded.
......@@ -153,6 +157,7 @@ From git repository:
--output=FILE pathname to tsv file containing more informations about the reactions.
.aureme.extract_deadends.py
Description:
extract first solution of dead_ends on output of clingo deadend_encoding.lp
......@@ -165,6 +170,7 @@ From git repository:
--output=FILE file with deadends id.
.aureme.extract_rxn_with_gene_assoc.py
Description:
From a given sbml file, create a sbml with only the reactions associated to a gene.
Need for a reaction, in section 'note', 'GENE_ASSOCIATION': ....
......@@ -179,6 +185,7 @@ From git repository:
-v print info
.aureme.fba_test.py
Description:
Run flux balance analyse with cobra package. If the flux is >0. Run also FVA
and return result in standard output
......@@ -191,6 +198,7 @@ From git repository:
--sbml=FILE pathname to the sbml file to test for fba and fva.
.aureme.gbk_to_faa.py
Description:
convert GBK to FAA with Bio package
......@@ -205,6 +213,7 @@ From git repository:
-v print info
.aureme.gene_to_targets.py
Description:
From a list of genes, recovere from the linked reactions the list of products.
R1 is linked to G1, R1 produces M1 and M2. output: M1,M2. Takes into account reversibility
......@@ -219,7 +228,22 @@ From git repository:
--output=FILE pathname to the output file containing all tagerts which can by produced by all reactions associated to the given genes
-v print info
.aureme.grammar-boolean-rapsody.py
Description:
Produce list of elements from a pattern.
usage:
grammar-boolean-rapsody.py STRING
positional arguments:
input_string The pattern to parse, must be a string like 'a&(b|c)&(d|e)'.
optional arguments:
-h, --help show this help message and exit
.aureme.manual_curation.py
Description:
This script allows to combine reaction_creator.py and update_padmetSpec.py.
This script was created specially for AuReMe and the default metabolic network
......@@ -241,6 +265,7 @@ From git repository:
-v print info
.aureme.pre_pantograph.py
Description:
Before running pantograph it is necessary to check if the metabolic network
and the proteom of the model organism use the same ids for genes (or at least more than a given cutoff).
......@@ -268,6 +293,7 @@ From git repository:
-v print info
.aureme.reactions_to_sbml.py
Description:
Convert a list of reactions to SBML file.
......@@ -282,6 +308,7 @@ From git repository:
-v print info
.misc.bigg_to_padmet.py
Description:
Create a padmet file from 2 tsv files (reactions.tsv and metabolites.tsv)
metabolites.tsv: col1 = metabolite ID, col2 = metabolite Name
......@@ -318,6 +345,7 @@ From git repository:
-v print info
.misc.change_compart.py
Description:
Two disctinct usages:
change_compart.py --padmetSpec=FILE --compart=STR --output=FILE [-v]
......@@ -344,6 +372,7 @@ From git repository:
-v print info
.misc.compare_sbml_padmet.py
Description:
compare reactions in sbml and padmet files
......@@ -356,6 +385,7 @@ From git repository:
--sbml=FILE pathanme of the sbml file
.misc.padmetSpec_to_ASP_for_deadends.py
Description:
use the script padmetSpec_to_asp_for_deadend to convert a padmet file to .lp for
asp. the output is then used with clingo and deadend_encoding.lp to find deadends
......@@ -371,6 +401,7 @@ From git repository:
-v print info.
.misc.padmet_to_asp.py
Description:
Convert PADMet to ASP following this predicats:
direction(reaction_id, reaction_direction). #LEFT-TO-RIGHT or REVERSIBLE
......@@ -389,6 +420,7 @@ From git repository:
-v print info
.misc.padmet_to_sbml.py
Description:
Use the script padmet_to_sbml to convert padmet to a sbml file
give only the id of the reaction to test (obj_coef)
......@@ -406,6 +438,7 @@ From git repository:
-v print info.
.misc.pgdb_to_padmet.py
Description:
classes.dat:
......@@ -502,6 +535,7 @@ From git repository:
-v print info
.misc.reaction_creator.py
Description:
Allows to create news reactions that are not in the database of reference and add
them in a padmet file. First, fill the template (to get the template use the 2nd usage).
......@@ -523,6 +557,7 @@ From git repository:
-v print info
.misc.report_network.py
Description:
Create reports of a padmet file.
all_pathways.tsv: header = ["dbRef_id", "Common name", "Number of reaction found",
......@@ -542,6 +577,7 @@ From git repository:
-v print info.
.misc.sbml_to_padmet.py
Description:
To convert a sbml to padmet without a padmet of database reference use the 2nd usage.
It is possible to define a specific policy and info for the padmet. To learn more about
......@@ -571,6 +607,7 @@ From git repository:
-v print info
.misc.update_padmetSpec.py
Description:
Allows to add or delete reactions/metabolites/pathways based on the given id.
From the updateFile (obtained with 2nd usage) the script extract the id (col1),
......@@ -595,6 +632,7 @@ From git repository:
-v print info
.misc.visu_path.py
Description:
Allows to visualize a pathway in padmet network.
Color code:
......@@ -612,6 +650,7 @@ From git repository:
--pathway=ID pathway id to visualize.
.misc.wikipage_creation.py
Description:
Create the files containing the wikicode for each page of the wiki relative to a
padmetSpec based on a database padmetRef. All the pages are stored in the folder
......
......@@ -77,7 +77,7 @@ def padmet_to_asp(padmet_file, output, verbose = False):
with open(output, 'w') as f:
#recover all reactions's data
reactions = [node for node in padmet.dicOfNode.itervalues()
reactions = [node for node in padmet.dicOfNode.values()
if node.type == "reaction"]
nb_reactions = len(reactions)
......@@ -214,7 +214,7 @@ def padmet_to_asp(padmet_file, output, verbose = False):
except KeyError:
pass
#recover all pathway's data
pathways = [node for node in padmet.dicOfNode.itervalues()
pathways = [node for node in padmet.dicOfNode.values()
if node.type == "pathway"]
nb_pathways = len(pathways)
count = 0
......
......@@ -56,7 +56,7 @@ def raw_data():
url_bigg = 'http://bigg.ucsd.edu/api/v2/'
raw_data = requests.get(url_bigg + "universal/reactions").json()['results']
all_reactions_ids = [rxn_dict['bigg_id'] for rxn_dict in raw_data if not rxn_dict['bigg_id'].startswith("BIOMASS")]
print("%s reactions to extract" %(len(all_reactions_ids)))
print(("%s reactions to extract" %(len(all_reactions_ids))))
with open("/home/maite/Documents/data/bigg/bigg_raw.txt", 'w') as f:
count = 0
......@@ -129,7 +129,7 @@ def raw_to_padmet():
count += 1
print("%s/%s" %(count, len(raw_data)))
rxn_id = rxn_dict["bigg_id"]
if rxn_id not in padmet.dicOfNode.keys():
if rxn_id not in list(padmet.dicOfNode.keys()):
rxn_metabolites = rxn_dict["metabolites"]
rxn_name = rxn_dict["name"]
rxn_direction = rxn_dict["direction"]
......@@ -141,9 +141,9 @@ def raw_to_padmet():
has_xref_rlt = Relation(rxn_id, "has_xref", xref_id)
list_of_relation.append(has_xref_rlt)
for db, k in rxn_xrefs.items():
for db, k in list(rxn_xrefs.items()):
_id = k[0]["id"]
if db in xref_node.misc.keys() and _id not in xref_node.misc[db]:
if db in list(xref_node.misc.keys()) and _id not in xref_node.misc[db]:
xref_node.misc[db].append(_id)
else:
xref_node.misc[db] = [_id]
......@@ -199,7 +199,7 @@ def add_kegg_pwy(pwy_file, padmetRef, verbose = False):
except KeyError:
pwy_node.misc["COMMON_NAME"] = [name]
if rxn_id:
if rxn_id in padmetRef.dicOfNode.keys():
if rxn_id in list(padmetRef.dicOfNode.keys()):
pwy_rlt = Relation(rxn_id,"is_in_pathway",pwy_id)
padmetRef._addRelation(pwy_rlt)
else:
......
......@@ -115,7 +115,7 @@ def main():
for rxn_id in [i for i in all_reactions_ids if not i.startswith("BIOMASS")]:
count += 1
if verbose: print("reaction: %s, %s/%s" %(rxn_id, count, len(all_reactions_ids)))
if rxn_id not in padmetRef.dicOfNode.keys():
if rxn_id not in list(padmetRef.dicOfNode.keys()):
rxn_response = requests.get(url_bigg + "universal/reactions/" +rxn_id)
rxn_dict = rxn_response.json()
......@@ -149,9 +149,9 @@ def main():
has_xref_rlt = Relation(rxn_id, "has_xref", xref_id)
list_of_relation.append(has_xref_rlt)
for db, k in rxn_xrefs.items():
for db, k in list(rxn_xrefs.items()):
_id = k[0]["id"]
if db in xref_node.misc.keys() and _id not in xref_node.misc[db]:
if db in list(xref_node.misc.keys()) and _id not in xref_node.misc[db]:
xref_node.misc[db].append(_id)
else:
xref_node.misc[db] = [_id]
......@@ -195,7 +195,7 @@ def main():
chrono = (time() - chronoDepart)
partie_entiere, partie_decimale = str(chrono).split('.')
chrono = ".".join([partie_entiere, partie_decimale[:3]])
if verbose: print "done in: ", chrono, "s !"
if verbose: print("done in: ", chrono, "s !")
def add_kegg_pwy(pwy_file, padmetRef, verbose = False):
global list_of_relation
......@@ -212,7 +212,7 @@ def add_kegg_pwy(pwy_file, padmetRef, verbose = False):
except KeyError:
pwy_node.misc["COMMON_NAME"] = [name]
if rxn_id:
if rxn_id in padmetRef.dicOfNode.keys():
if rxn_id in list(padmetRef.dicOfNode.keys()):
pwy_rlt = Relation(rxn_id,"is_in_pathway",pwy_id)
padmetRef._addRelation(pwy_rlt)
else:
......
......@@ -65,7 +65,7 @@ def main():
for line in file_in_array[start_index:]]
reactions_ids = [convert_from_coded_id(r)[0] for r in encoded_reactions]
nb_reactions = str(len(reactions_ids))
if verbose: print(nb_reactions+" reactions to check")
if verbose: print(nb_reactions+" reactions to check")
with open(output,'w') as f:
header = ["idRef","Common name","EC-number","Formula (with id)","Formula (with cname)","Action","Comment", "Genes"]
header = "\t".join(header)+"\n"
......
......@@ -74,7 +74,7 @@ def main():
#2: extract all pathways from database Ref
if verbose: print("extract all pathways from database Ref")
all_pathways_id = (node.id for node in padmetRef.dicOfNode.values() if node.type == "pathway")
all_pathways_id = (node.id for node in list(padmetRef.dicOfNode.values()) if node.type == "pathway")
for pwy_id in all_pathways_id:
rxns_assoc = [rlt.id_in for rlt in padmetRef.dicOfRelationOut[pwy_id]
if rlt.type == "is_in_pathway" and padmetRef.dicOfNode[rlt.id_in].type == "reaction"]
......@@ -95,15 +95,15 @@ def main():
dict_mnxref[mnx][db].add(_id)
except KeyError:
dict_mnxref[mnx].update({db: set([_id])})
for k,v in dict_mnxref.items():
if len(v.keys()) < 2:
for k,v in list(dict_mnxref.items()):
if len(list(v.keys())) < 2:
dict_mnxref.pop(k)
#map reactions id
assoc_sgs_id_reactions_mapped = {}
for sgs_id, set_rxn in assoc_sgs_id_reactions.iteritems():
for assoc_dict in dict_mnxref.values():
for sgs_id, set_rxn in assoc_sgs_id_reactions.items():
for assoc_dict in list(dict_mnxref.values()):
for _id in assoc_dict[db_origin]:
if _id in set_rxn:
try:
......@@ -116,8 +116,8 @@ def main():
if an intersection length is > 0 ==> the sgs covere a part of this pwy.
Extract which reactions and the ratio on all the reactions in the pathways.
"""
for sgs_id, rxns_in_sgs in assoc_sgs_id_reactions_mapped.iteritems():
for pwy_id, rxns_in_pwy in assoc_pathways_reactions.iteritems():
for sgs_id, rxns_in_sgs in assoc_sgs_id_reactions_mapped.items():
for pwy_id, rxns_in_pwy in assoc_pathways_reactions.items():
rxns_inter = rxns_in_sgs.intersection(rxns_in_pwy)
len_rxns_inter = len(rxns_inter)
if len_rxns_inter > 0 and float(len_rxns_inter)/float(len(rxns_in_pwy)) > float(1)/float(3):
......@@ -153,13 +153,13 @@ def main():
header = ["PATHWAYS ID\SGS ID"]+all_sgs
f.write("\t".join(header)+"\n")
for pwy_id,sgs_dict in assoc_pathways_sgs.iteritems():
for pwy_id,sgs_dict in assoc_pathways_sgs.items():
line = [""]*len(header)
try:
line[0] = pwy_id+"/"+padmetRef.dicOfNode[pwy_id].misc["COMMON_NAME"][0]
except KeyError:
line[0] = pwy_id
for sgs_id, data in sgs_dict.iteritems():
for sgs_id, data in sgs_dict.items():
sgs_index = header.index(sgs_id)
line[sgs_index] = data
line = "\t".join(line)+"\n"
......
......@@ -44,7 +44,7 @@ def main():
if not args["--rxn_id"]:
try:
rxn = (rxn for rxn in model.reactions if rxn.objective_coefficient == 1.0).next()
rxn = next(rxn for rxn in model.reactions if rxn.objective_coefficient == 1.0)
except StopIteration:
print("No reaction id given and no reaction with obj coefficient to 1.0, enable to get the reaction")
exit()
......@@ -80,7 +80,7 @@ def main():
f.write(line)
#check if have gene assoc
try:
k = [i for i in rxn.notes.keys() if i.lower().startswith("gene")][0]
k = [i for i in list(rxn.notes.keys()) if i.lower().startswith("gene")][0]
gene_assoc = rxn.notes[k][0]
line = ["linked_gene", gene_assoc]
except IndexError:
......
......@@ -45,7 +45,7 @@ def main():
reactions_to_remove = []
for reaction in listOfReactions:
if "GENE_ASSOCIATION" not in parseNotes(reaction).keys():
if "GENE_ASSOCIATION" not in list(parseNotes(reaction).keys()):
reactions_to_remove.append(reaction.getId())
for rId in reactions_to_remove:
listOfReactions.remove(rId)
......
# -*- coding: utf-8 -*-
"""
This file is part of padmet-utils.
padmet-utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
padmet-utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with padmet-utils. If not, see <http://www.gnu.org/licenses/>.
@author: Meziane AITE, meziane.aite@inria.fr
Description:
convert GBK to FAA with Bio package
usage:
gbk_to_faa.py --gbk=FILE --output=FILE [--qualifier=STR] [-v]
option:
-h --help Show help.
--gbk=FILE pathname to the gbk file.
--output=FILE pathename to the output, a FAA file.
--qualifier=STR the qualifier of the gene id [default: locus_tag].
-v print info
"""
from Bio import SeqIO
import docopt
def main():
args = docopt.docopt(__doc__)
gbk_file = args["--gbk"]
faa_file = args["--output"]
qualifier = args["--qualifier"]
verbose = args["-v"]
dict_faa = {}
with open(gbk_file, "rU") as gbk:
for seq_record in SeqIO.parse(gbk, "genbank"):
seq_feature_cds = (seq_feature for seq_feature in seq_record.features if seq_feature.type == "CDS")
for seq_feature in seq_feature_cds:
try:
dict_faa[seq_feature.qualifiers[qualifier][0]] = seq_feature.qualifiers['translation'][0]
except KeyError:
if verbose:
try:
print ("locus without Translation: "+seq_feature.qualifiers['locus_tag'][0])
except KeyError:
print ("locus without Translation: "+seq_feature.qualifiers.get('gene',["Unknown"])[0])
with open(faa_file,'w') as f:
for locus_tag, seq in dict_faa.iteritems():
f.write(">%s\n%s\n" % (locus_tag,seq))
if __name__ == "__main__":
# -*- coding: utf-8 -*-
"""
This file is part of padmet-utils.
padmet-utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
padmet-utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with padmet-utils. If not, see <http://www.gnu.org/licenses/>.
@author: Meziane AITE, meziane.aite@inria.fr
Description:
convert GBK to FAA with Bio package
usage:
gbk_to_faa.py --gbk=FILE --output=FILE [--qualifier=STR] [-v]
option:
-h --help Show help.
--gbk=FILE pathname to the gbk file.
--output=FILE pathename to the output, a FAA file.
--qualifier=STR the qualifier of the gene id [default: locus_tag].
-v print info
"""
from Bio import SeqIO
import docopt
def main():
args = docopt.docopt(__doc__)
gbk_file = args["--gbk"]
faa_file = args["--output"]
qualifier = args["--qualifier"]
verbose = args["-v"]
dict_faa = {}
with open(gbk_file, "rU") as gbk:
for seq_record in SeqIO.parse(gbk, "genbank"):
seq_feature_cds = (seq_feature for seq_feature in seq_record.features if seq_feature.type == "CDS")
for seq_feature in seq_feature_cds:
try:
dict_faa[seq_feature.qualifiers[qualifier][0]] = seq_feature.qualifiers['translation'][0]
except KeyError:
if verbose:
try:
print("locus without Translation: "+seq_feature.qualifiers['locus_tag'][0])
except KeyError:
print("locus without Translation: "+seq_feature.qualifiers.get('gene',["Unknown"])[0])
with open(faa_file,'w') as f:
for locus_tag, seq in dict_faa.items():
f.write(">%s\n%s\n" % (locus_tag,seq))
if __name__ == "__main__":
main()
\ No newline at end of file
......@@ -42,11 +42,13 @@ Idea is, mainly, that a syntree is simple to store (dict {node:successors}),
Note that there is no real error handling for parenthesis.
"""
import argparse
import re
from enum import Enum
from collections import ChainMap, defaultdict
import sys
from collections import ChainMap, defaultdict
from enum import Enum
# Constants
ERROR_LIMIT = 10 # at most 10 errors before compilation abortion
SILENT_SYNTACTIC_ANALYSIS = True # continue compilation even if syntactic error
......@@ -333,7 +335,11 @@ def compile_input(string, combine_or:bool=False):
yield from eval_tree(syntree, combine_or=bool(combine_or))
if __name__ == '__main__':
string = sys.argv[1]
parser = argparse.ArgumentParser(usage="python grammar-boolean-rapsody.py STRING", description="Produce list of elements from a pattern.")
parser.add_argument("input_string", metavar = "input_string", help = "The pattern to parse, must be a string like 'a&(b|c)&(d|e)'.")
parser_args = parser.parse_args()
string = parser_args.input_string
#print(string)
#print(sys.argv)
#string = "(b3670|b3671)&(b0077|b0078)"
......
......@@ -73,7 +73,7 @@ def main():
rxn_data.pop("rxn12985")
if verbose: print("updating padmet")
count = 0
for rxn_id, rxn_dict in rxn_data.items():
for rxn_id, rxn_dict in list(rxn_data.items()):
count += 1
if verbose: print("reaction: %s, %s/%s" %(rxn_id, count, len(rxn_data)))
try:
......@@ -82,7 +82,7 @@ def main():
except KeyError:
print(rxn_id)
continue
if rxn_id not in padmetRef.dicOfNode.keys():
if rxn_id not in list(padmetRef.dicOfNode.keys()):
if rxn_dict["reversibility"] == ">":
rxn_direction = "LEFT-TO-RIGHT"
else:
......@@ -160,7 +160,7 @@ def main():
chrono = (time() - chronoDepart)
partie_entiere, partie_decimale = str(chrono).split('.')
chrono = ".".join([partie_entiere, partie_decimale[:3]])
if verbose: print "done in: ", chrono, "s !"
if verbose: print("done in: ", chrono, "s !")
def add_kegg_pwy(pwy_file, padmetRef, verbose = False):
global list_of_relation
......@@ -177,7 +177,7 @@ def add_kegg_pwy(pwy_file, padmetRef, verbose = False):
except KeyError:
pwy_node.misc["COMMON_NAME"] = [name]
if rxn_id:
if rxn_id in padmetRef.dicOfNode.keys():
if rxn_id in list(padmetRef.dicOfNode.keys()):
pwy_rlt = Relation(rxn_id,"is_in_pathway",pwy_id)
padmetRef._addRelation(pwy_rlt)
else:
......
......@@ -40,7 +40,7 @@ def main():
padmet = PadmetSpec(padmet_file)
all_metabolites = sorted(set([rlt.id_out for rlt in padmet.getAllRelation() if rlt.type in ["consumes","produces"]]))
all_reactions = sorted([node.id for node in padmet.dicOfNode.values() if node.type == "reaction"])
all_reactions = sorted([node.id for node in list(padmet.dicOfNode.values()) if node.type == "reaction"])
#col = reactions, row = metabolites
matrix_dict = {}
for met in all_metabolites:
......
......@@ -86,7 +86,7 @@ def main():
path = args["--to_add"]
if not path.endswith("/"):
path += "/"
all_files = [i for i in os.walk(path).next()[2] if not i.startswith(".~lock")]
all_files = [i for i in next(os.walk(path))[2] if not i.startswith(".~lock")]
padmetFiles = [path+i for i in all_files if i.endswith(".padmet")]
else:
padmetFiles = [args["--to_add"]]
......@@ -110,7 +110,7 @@ def main():
chrono = (time() - chronoDepart)
partie_entiere, partie_decimale = str(chrono).split('.')
chrono = ".".join([partie_entiere, partie_decimale[:3]])
if verbose: print "done in: ", chrono, "s !"
if verbose: print("done in: ", chrono, "s !")
if __name__ == "__main__":
......
......@@ -54,7 +54,7 @@ options:
-v
"""
from padmet.classes import PadmetSpec, PadmetRef
from itertools import izip_longest
from itertools import zip_longest
import os
import csv
import docopt
......@@ -80,7 +80,7 @@ def main():
padmetSpec_name = os.path.splitext(os.path.basename(padmetSpec_file))[0]
padmetSpec_folder = output_dir+padmetSpec_name+"/"
if not os.path.isdir(padmetSpec_folder):
if verbose: print("Creating folder %s" %padmetSpec_folder)
if verbose: print(("Creating folder %s" %padmetSpec_folder))
os.makedirs(padmetSpec_folder)
#if padmetRef given, create folder for padmetRef
......@@ -105,7 +105,7 @@ def main():
writer.writerow([padmetRef_name, padmetRef_name])
if verbose: print("\tExtracting reactions")
all_rxn_nodes = [node for node in padmetRef.dicOfNode.values() if node.type == "reaction"]
all_rxn_nodes = [node for node in list(padmetRef.dicOfNode.values()) if node.type == "reaction"]
if all_rxn_nodes: extract_nodes(padmetRef, all_rxn_nodes, "reaction", padmetRef_folder+"rxn.tsv", {"in@metabolic_network":[padmetRef_name]})
if verbose: print("\t%s reactions" %len(all_rxn_nodes))
......@@ -115,12 +115,12 @@ def main():
if verbose: print("\t%s compounds" %len(all_cpd_nodes))
if verbose: print("\tExtracting pathways")
all_pwy_nodes = [node for node in padmetRef.dicOfNode.values() if node.type == "pathway"]
all_pwy_nodes = [node for node in list(padmetRef.dicOfNode.values()) if node.type == "pathway"]
if all_pwy_nodes: extract_nodes(padmetRef, all_pwy_nodes, "pathway", padmetRef_folder+"pwy.tsv")
if verbose: print("\t%s pathways" %len(all_pwy_nodes))
if verbose: print("\tExtracting xrefs")
all_xrefs_nodes = [node for node in padmetRef.dicOfNode.values() if node.type == "xref"]
all_xrefs_nodes = [node for node in list(padmetRef.dicOfNode.values()) if node.type == "xref"]
if all_xrefs_nodes: extract_nodes(padmetRef, all_xrefs_nodes, "xref", padmetRef_folder+"xref.tsv")
if verbose: print("\t%s xrefs" %len(all_xrefs_nodes))
......@@ -189,7 +189,7 @@ def main():
writer.writerow([padmetSpec_name,padmetSpec_name])
if verbose: print("\tExtracting reactions")
spec_rxn_nodes = [node for node in padmetSpec.dicOfNode.values() if node.type == "reaction"]
spec_rxn_nodes = [node for node in list(padmetSpec.dicOfNode.values()) if node.type == "reaction"]
if all_rxn_nodes: extract_nodes(padmetSpec, spec_rxn_nodes, "reaction", padmetSpec_folder+"rxn.tsv", {"in@metabolic_network":[padmetSpec_name]})
if verbose: print("\t%s reactions" %len(all_rxn_nodes))
......@@ -199,22 +199,22 @@ def main():
if verbose: print("\t%s compounds" %len(all_cpd_nodes))
if verbose: print("\tExtracting pathways")
spec_pwy_nodes = [node for node in padmetSpec.dicOfNode.values() if node.type == "pathway"]
spec_pwy_nodes = [node for node in list(padmetSpec.dicOfNode.values()) if node.type == "pathway"]
if all_pwy_nodes: extract_nodes(padmetSpec, spec_pwy_nodes, "pathway", padmetSpec_folder+"pwy.tsv")
if verbose: print("\t%s pathways" %len(all_pwy_nodes))
if verbose: print("\tExtracting xrefs")
spec_xrefs_nodes = [node for node in padmetSpec.dicOfNode.values() if node.type == "xref"]
spec_xrefs_nodes = [node for node in list(padmetSpec.dicOfNode.values()) if node.type == "xref"]
if spec_xrefs_nodes: extract_nodes(padmetSpec, spec_xrefs_nodes, "xref", padmetSpec_folder+"xref.tsv")
if verbose: print("\t%s xrefs" %len(spec_xrefs_nodes))
if verbose: print("\tExtracting all genes")
spec_genes_nodes = [node for node in padmetSpec.dicOfNode.values() if node.type == "gene"]
spec_genes_nodes = [node for node in list(padmetSpec.dicOfNode.values()) if node.type == "gene"]
if spec_genes_nodes: extract_nodes(padmetSpec, spec_genes_nodes, "gene", padmetSpec_folder+"gene.tsv", opt_col = {"in@metabolic_network":[padmetSpec_name]})
if verbose: print("\t%s genes" %len(spec_genes_nodes))
if verbose: print("\tExtracting all reconstructionData")
spec_recData_nodes = [node for node in padmetSpec.dicOfNode.values() if node.type == "reconstructionData"]
spec_recData_nodes = [node for node in list(padmetSpec.dicOfNode.values()) if node.type == "reconstructionData"]
if spec_genes_nodes: extract_nodes(padmetSpec, spec_recData_nodes, "reconstructionData", padmetSpec_folder+"reconstructionData.tsv")