Skip to content

Commit

Permalink
Merge pull request #54 from mazzalab/issues42-48
Browse files Browse the repository at this point in the history
Issues42 48
  • Loading branch information
mazzalab authored Nov 26, 2020
2 parents 36800f5 + cc96f76 commit 40762c8
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 142 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ also install the CUDA toolkit by downloading and installing the Toolkit from the
Changelog for current and past releases:


### 1.3.1:
Bug fixes:
- \#47 -nprocs removed in keyplayer kp-info command line
- \#48 empty result with kp-finder
- \#49 -seed argument removed in pyntacle generator
- \#50 --plot-format option removed from 1.2 onward
- \#51 seed argument removed in group degree API
- \#52 bad handling of missing output file names
- \#53 bad handling of empty set due to graph intersection

### 1.3:
Major updates:
- [algorithms] Implementation of the new Stochastic Gradient Descent (SGD) search algorithm
Expand Down
89 changes: 41 additions & 48 deletions cmds/convert.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
__author__ = u"Mauro Truglio, Tommaso Mazza"
__copyright__ = u"Copyright 2018, The Pyntacle Project"
__author__ = u"Tommaso Mazza"
__copyright__ = u"Copyright 2018-2020, The Pyntacle Project"
__credits__ = [u"Ferenc Jordan"]
__version__ = u"1.1"
__version__ = u"1.3.1"
__maintainer__ = u"Tommaso Mazza"
__email__ = "bioinformatics@css-mendel.it"
__status__ = u"Development"
__date__ = u"26/11/2018"
__date__ = u"26/11/2020"
__license__ = u"""
Copyright (C) 2016-2020 Tommaso Mazza <t.mazza@css-mendel.it>
Viale Regina Margherita 261, 00198 Rome, Italy
Expand Down Expand Up @@ -55,7 +55,7 @@ def run(self):

if self.args.input_file is None:
sys.stderr.write(
u"Please specify an input file using the `-i/--input-file` option. Quitting\n")
u"Please specify an input file using the `-i/--input-file` option. Quit\n")
sys.exit(1)

if not os.path.exists(self.args.input_file):
Expand All @@ -67,89 +67,82 @@ def run(self):

else:
separator = self.args.input_separator

sys.stdout.write(run_start)
sys.stdout.write(u"Converting input file {0} to requested output file: {1}\n".format(os.path.basename(self.args.input_file), os.path.basename(self.args.output_file)))

out_form = format_dictionary.get(self.args.output_format, "NA")


if self.args.output_file is None:
self.args.output_file = os.path.splitext(os.path.basename(self.args.input_file))[0]
sys.stdout.write(
u"Output file name will be the basename of the input file ({})\n".format(self.args.output_file))
# print(self.args.output_file)

sys.stdout.write(run_start)
sys.stdout.write(u"Converting input file {0} to requested output file: {1}\n".format(
os.path.basename(self.args.input_file),
os.path.basename(self.args.output_file)))

out_format = format_dictionary.get(self.args.output_format, "NA")
if out_format == "NA":
sys.stderr.write(
u"The specified extension for the output file is not supported, see '--help' for more info. Quit\n")
sys.exit(1)

if self.args.output_separator is None:
sys.stdout.write(
u"Using the field separator used in the input network file in the converted output file, if the desired output format requires field separator\n")
sys.stdout.write(u"Using the field separator of the input file in the converted output file\n")
self.args.output_separator = separator

if not os.path.isdir(self.args.directory):
sys.stdout.write(u"WARNING: output directory does not exist, will create one at {}\n".format(
sys.stdout.write(u"WARNING: the output directory does not exist. It will be created at {}\n".format(
os.path.abspath(self.args.directory)))
os.makedirs(os.path.abspath(self.args.directory), exist_ok=True)

if out_form == "NA":
sys.stderr.write(u"Output extension specified is not supported, see '--help' for more info. Quitting\n")
sys.exit(1)

output_path = os.path.join(self.args.directory, ".".join([self.args.output_file, out_form]))
init_graph = GraphLoad(input_file=self.args.input_file, file_format=format_dictionary.get(self.args.format, "NA"), header=header, separator=self.args.input_separator)
output_path = os.path.join(self.args.directory, ".".join([self.args.output_file, out_format]))
init_graph = GraphLoad(input_file=self.args.input_file, file_format=format_dictionary.get(
self.args.format, "NA"), header=header, separator=self.args.input_separator)
input_basename = os.path.basename(self.args.input_file)
# special cases:
#1: convert an edgelist to a sif file
if format_dictionary.get(self.args.format, "NA") == "egl" and out_form == "sif":

sys.stdout.write(u"Converting edge list to Simple Interaction Format (SIF)\nFull path to the output file:\n{}\n".format(output_path))
# special cases:
# 1: convert an edgelist to a sif file
if format_dictionary.get(self.args.format, "NA") == "egl" and out_format == "sif":
sys.stdout.write(u"Converting edge-list to SIF\nFull path to the output file:\n{}\n".format(output_path))
PyntacleConverter.edgelistToSif(file=self.args.input_file, sep=separator, output_sep=self.args.output_separator, header=output_header, output_file=output_path)

#2: convert a sif to an edgelist file
elif format_dictionary.get(self.args.format, "NA") == "sif" and out_form == "egl":
sys.stdout.write(u"Converting Simple Interaction Format (SIF) to edge list\nFull path to the output file:\n{}\n".format(output_path))
# 2: convert a sif to an edgelist file
elif format_dictionary.get(self.args.format, "NA") == "sif" and out_format == "egl":
sys.stdout.write(u"Converting SIF to edge-list\nFull path to the output file:\n{}\n".format(output_path))
PyntacleConverter.sifToEdgelist(file=self.args.input_file, sep=separator, output_sep=self.args.output_separator,
header=output_header, output_file=output_path)

else:

graph = init_graph.graph_load()
in_form = init_graph.get_format()

if in_form == out_form:
sys.stderr.write(u"The output format specified is the same as the input format. Quitting\n")
if in_form == out_format:
sys.stderr.write(u"The specified format of the output file is the same as the input file. Quit\n")
sys.exit(1)

if out_form == "adjm":
sys.stdout.write(u"Converting input graph file {0} to adjacency matrix at full path:\n{1}\n".format(
if out_format == "adjm":
sys.stdout.write(u"Converting the input file {0} to adjacency matrix. Path:\n{1}\n".format(
input_basename, output_path))
PyntacleExporter.AdjacencyMatrix(graph, output_path, sep=self.args.output_separator,
header=output_header)

elif out_form == "egl":
elif out_format == "egl":
sys.stdout.write(
u"Converting input graph file {0} to edge list at full path:\n{1}\n".format(
u"Converting the input file {0} to edge-list. Path:\n{1}\n".format(
input_basename,
output_path))
PyntacleExporter.EdgeList(graph, output_path, sep=self.args.output_separator, header=output_header)

elif out_form == "sif":
elif out_format == "sif":
sys.stdout.write(
u"Converting input graph file {0} to Simple Interaction Format (SIF) file at full path:\n{1}\n".format(
u"Converting the input file {0} to SIF. Path:\n{1}\n".format(
input_basename, output_path))
PyntacleExporter.Sif(graph, output_path, sep=self.args.output_separator, header=output_header)

elif out_form == "dot":
elif out_format == "dot":
# Ignore ugly RuntimeWarnings while converting to dot
simplefilter("ignore", RuntimeWarning)

sys.stdout.write(
u"Converting input graph file {0} to DOT file using igraph utilities at full path:\n{1}\n(output separator will be ignored)\n".format(
u"Converting the input file {0} to DOT. Path:\n{1}\n(output separator will be ignored)\n".format(
input_basename, output_path))
PyntacleExporter.Dot(graph, output_path)


elif out_form == "graph":
elif out_format == "graph":
sys.stdout.write(
u"Converting input graph file {0} to a binary file (ending in .graph) at full path:\n{1}\n(output separator will be ignored)\n".format(
u"Converting the input file {0} to a binary file (with .graph extension). Path:\n{1}\n(output separator will be ignored)\n".format(
input_basename, output_path))
PyntacleExporter.Binary(graph, output_path)

Expand Down
8 changes: 4 additions & 4 deletions cmds/keyplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def run(self):
kp_runner.run_reachability(self.args.k_size, KpposEnum.dR, cmode=implementation)
sys.stdout.write("\n")

if self.args.type in (['m-reach', 'pos', 'all']):
if self.args.type in (['mreach', 'pos', 'all']):
sys.stdout.write(
u"KP-Pos: Finding optimal set of nodes of size {0} that maximizes the m-reach at distance {1}\n".format(
self.args.k_size, self.args.m_reach))
Expand Down Expand Up @@ -218,7 +218,7 @@ def run(self):

sys.stdout.write(sep_line)

if self.args.type in (['m-reach', 'pos', 'all']):
if self.args.type in (['mreach', 'pos', 'all']):
sys.stdout.write(
u"KP-Pos: Finding the best set(s) of nodes of size {0} that maximizes the m-reach at distance {1}\n".format(
self.args.k_size, self.args.m_reach))
Expand Down Expand Up @@ -284,7 +284,7 @@ def run(self):
**{k: v for k, v in optional_args.items() if v is not None})
sys.stdout.write("\n")

if self.args.type in (['m-reach', 'pos', 'all']):
if self.args.type in (['mreach', 'pos', 'all']):
sys.stdout.write(
u"KP-Pos: Finding optimal set of nodes of size {0} that maximizes the m-reach at distance {1}\n".format(
self.args.k_size, self.args.m_reach))
Expand Down Expand Up @@ -368,7 +368,7 @@ def run(self):
kp_runner.run_reachability(KpposEnum.dR, cmode=implementation)
sys.stdout.write("\n")

if self.args.type in (['m-reach', 'pos', 'all']):
if self.args.type in (['mreach', 'pos', 'all']):
kp_runner.run_reachability(KpposEnum.mreach, m=self.args.m_reach, cmode=implementation)
sys.stdout.write("\n")

Expand Down
Loading

0 comments on commit 40762c8

Please sign in to comment.