Skip to content

Commit

Permalink
Merge pull request #40 from CASCI-lab/style-and-formatting-patch1
Browse files Browse the repository at this point in the history
format, style, and fixed some unused args
  • Loading branch information
jcrozum committed Jan 5, 2024
2 parents cb7aa4d + f7f0b49 commit e2ef03f
Show file tree
Hide file tree
Showing 16 changed files with 1,681 additions and 1,027 deletions.
32 changes: 17 additions & 15 deletions cana/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
__package__ = 'cana'
__title__ = u'CANAlization: Control & Redundancy in Boolean Networks'
__description__ = u'This package implements a series of methods used to study control, canalization and redundancy in Boolean networks.'
__package__ = "cana"
__title__ = "CANAlization: Control & Redundancy in Boolean Networks"
__description__ = "This package implements a series of methods used to study control, canalization and redundancy in Boolean networks."

__author__ = """\n""".join([
'Rion Brattig Correia <rionbr@gmail.com>',
'Alex Gates <ajgates42@gmail.com>',
'Xuan Wang <xw47@indiana.edu>',
'Thomas Parmer <tjparmer@indiana.edu>',
'Etienne Nzabarushimana <enzabaru@indiana.edu>',
'Luis M. Rocha <rocha@indiana.edu>'
])
__author__ = """\n""".join(
[
"Rion Brattig Correia <rionbr@gmail.com>",
"Alex Gates <ajgates42@gmail.com>",
"Xuan Wang <xw47@indiana.edu>",
"Thomas Parmer <tjparmer@indiana.edu>",
"Etienne Nzabarushimana <enzabaru@indiana.edu>",
"Luis M. Rocha <rocha@indiana.edu>",
]
)

__copyright__ = u'2021, Correia, R. B., Gates, A., Rocha, L. M.'
__copyright__ = "2021, Correia, R. B., Gates, A., Rocha, L. M."

__version__ = '0.2.0'
__release__ = '0.2.0'
__version__ = "0.2.0"
__release__ = "0.2.0"
#
__all__ = ['boolean_network', 'boolean_node']
__all__ = ["boolean_network", "boolean_node"]
10 changes: 7 additions & 3 deletions cana/base.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import warnings
import functools
import warnings


def deprecated(func):
"""This is a decorator which can be used to mark functions as deprecated.
It will result in a warning being emitted when the function is used.
"""

@functools.wraps(func)
def new_func(*args, **kwargs):
warnings.warn_explicit(
"You've called a deprecated function. Maybe this function needs updating to the new package. {}".format(func.__name__),
"You've called a deprecated function. Maybe this function needs updating to the new package. {}".format(
func.__name__
),
category=DeprecationWarning,
filename=func.func_code.co_filename,
lineno=func.func_code.co_firstlineno + 1
lineno=func.func_code.co_firstlineno + 1,
)
return func(*args, **kwargs)

return new_func
29 changes: 17 additions & 12 deletions cana/bns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import os
import subprocess
import tempfile

from cana.utils import binstate_to_statenum

_path = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -53,41 +54,45 @@ def attractors(cnet, bnspath=_path, cleanup=True):
# If string, Creates a Temporary File to be supplied to BNS
elif isinstance(cnet, str):
tmp = tempfile.NamedTemporaryFile(delete=cleanup)
with open(tmp.name, 'w') as openfile:
with open(tmp.name, "w") as openfile:
openfile.write(cnet)
tmp.file.close()
file = tmp.name
else:
raise TypeError('The cnet input should be either a file to a .cnet file or a string containing the .cnet content')
raise TypeError(
"The cnet input should be either a file to a .cnet file or a string containing the .cnet content"
)

cmd = [os.path.join(_path, 'bns'), file]
cmd = [os.path.join(bnspath, "bns"), file]
attractors = list()

try:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

current_attractor = []
for i, line in enumerate(p.stdout):
for _, line in enumerate(p.stdout):
# Strip line
cleanline = line.decode('ascii').strip().replace('\n', '')
cleanline = line.decode("ascii").strip().replace("\n", "")

if 'Attractor' in cleanline:
if "Attractor" in cleanline:
attractors.append(current_attractor)
current_attractor = []
elif 'Node' in cleanline and 'assumed to be constant' in cleanline:
elif "Node" in cleanline and "assumed to be constant" in cleanline:
pass
elif 'Total' in cleanline:
elif "Total" in cleanline:
pass
elif 'Start searching for all atractors.' in cleanline:
elif "Start searching for all atractors." in cleanline:
pass
elif 'Depth' in cleanline:
elif "Depth" in cleanline:
pass
elif 'average' in cleanline:
elif "average" in cleanline:
pass
elif len(cleanline) > 0:
current_attractor.append(binstate_to_statenum(cleanline))

except OSError:
print("'BNS' could not be found! You must have it compiled or download the binary for your system from the 'bns' website (https://people.kth.se/~dubrova/bns.html).")
print(
"'BNS' could not be found! You must have it compiled or download the binary for your system from the 'bns' website (https://people.kth.se/~dubrova/bns.html)."
)

return attractors
Loading

0 comments on commit e2ef03f

Please sign in to comment.