Skip to content

Commit

Permalink
refactor code, verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
grexor committed Dec 19, 2024
1 parent d398ed4 commit 9be9997
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
58 changes: 29 additions & 29 deletions splicekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,50 @@
print("splicekit | please run splicekit in a folder with splicekit.config present")
sys.exit(0)

print("splicekit | loading splicekit.config")
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, add_help=False)
parser.add_argument('command', help="command(s) to run", nargs='*')
parser.add_argument("-help", "-h", "--help", action="store_true")
parser.add_argument("-version", "--version", help="Print version", action="store_true")
parser.add_argument("-force", "--force", help="Force recreation / overwrite of results", action="store_true", default=False)
parser.add_argument("-hostname", "--hostname", help="If you are submitting 'splicekit process' to the cluster, you can provide a custom hostname. This will be used to create JBrowse2 URLs.", default=None)
parser.add_argument("-verbose", "--verbose", help="Verbose mode", action="store_true", default=False)
args, unknown_args = parser.parse_known_args()

verbose = args.verbose

import splicekit.config as config
print("splicekit | ", config.platform, " detected")
print("splicekit | loading splicekit.core")
import splicekit.core as core
print("splicekit | loading splicekit.core.annotation")
verbose and print("splicekit | loading splicekit.core.annotation")
import splicekit.core.annotation
print("splicekit | loading splicekit.core.features")
verbose and print("splicekit | loading splicekit.core.features")
import splicekit.core.features
print("splicekit | loading splicekit.core.exons")
verbose and print("splicekit | loading splicekit.core.exons")
import splicekit.core.exons
print("splicekit | loading splicekit.core.genes")
verbose and print("splicekit | loading splicekit.core.genes")
import splicekit.core.genes
print("splicekit | loading splicekit.core.report")
verbose and print("splicekit | loading splicekit.core.report")
import splicekit.core.report
print("splicekit | loading splicekit.core.patterns")
verbose and print("splicekit | loading splicekit.core.patterns")
import splicekit.core.patterns
print("splicekit | loading splicekit.core.promisc")
verbose and print("splicekit | loading splicekit.core.promisc")
import splicekit.core.promisc
print("splicekit | loading splicekit.core.anchors ")
verbose and print("splicekit | loading splicekit.core.anchors ")
import splicekit.core.anchors
print("splicekit | loading splicekit.core.junctions")
verbose and print("splicekit | loading splicekit.core.junctions")
import splicekit.core.junctions
print("splicekit | loading splicekit.core.jbrowse2")
verbose and print("splicekit | loading splicekit.core.jbrowse2")
import splicekit.core.jbrowse2
print("splicekit | loading splicekit.core.juan")
verbose and print("splicekit | loading splicekit.core.juan")
import splicekit.core.juan
print("splicekit | loading splicekit.judge")
verbose and print("splicekit | loading splicekit.judge")
import splicekit.judge
print("splicekit | loading splicekit.core.delta_dar")
verbose and print("splicekit | loading splicekit.core.delta_dar")
import splicekit.core.delta_dar
print("splicekit | loading splicekit.clusterlogfc")
verbose and print("splicekit | loading splicekit.clusterlogfc")
import splicekit.clusterlogfc
print("splicekit | loading splicekit.june")
verbose and print("splicekit | loading splicekit.june")
import splicekit.june
print("splicekit | loading splicekit.report")
verbose and print("splicekit | loading splicekit.report")
import splicekit.report

# initialization (triggered once on "import splicekit")
Expand Down Expand Up @@ -405,23 +413,15 @@ def main():
If no sub-command is given, all analyses will be run (DREME, scanRBP).
"""

parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, add_help=False)
parser.add_argument('command', help="command(s) to run", nargs='*')
parser.add_argument("-help", "-h", "--help", action="store_true")
parser.add_argument("-version", "--version", help="Print version", action="store_true")
parser.add_argument("-force", "--force", help="Force recreation / overwrite of results", action="store_true", default=False)
parser.add_argument("-hostname", "--hostname", help="If you are submitting 'splicekit process' to the cluster, you can provide a custom hostname. This will be used to create JBrowse2 URLs.", default=None)
args = parser.parse_args()

# lookup version without loading splicekit
import importlib.util
splicekit_init = importlib.util.find_spec("splicekit")
splicekit_path = splicekit_init.origin
splicekit_folder = os.path.dirname(splicekit_path)
version = open(os.path.join(splicekit_folder, "version"), "rt").readlines()[0].replace("\n", "").replace("\r", "")
verbose = args.verbose

print(f"splicekit | v{version}, https://github.com/bedapub/splicekit")
print()
print(f"splicekit | v{version} | https://github.com/bedapub/splicekit")

if args.version:
sys.exit(0)
Expand Down
6 changes: 5 additions & 1 deletion splicekit/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import os
import sys
import splicekit
import splicekit.core as core
import socket

module_desc = "splicekit | config |"
splicekit.verbose and print(f"{module_desc} loading")

if os.path.exists("splicekit.config"):
config_lines = open("splicekit.config").readlines()
Expand All @@ -18,6 +20,8 @@
except:
jbrowse2_url = None

splicekit.verbose and print(f"{module_desc} {platform} detected")

def jbrowse2_config(hostname):
global jbrowse2_url
if jbrowse2_url not in [None, ""]: # user defined JBrowse2 url? -> do not change it
Expand All @@ -28,7 +32,7 @@ def jbrowse2_config(hostname):
hostname=socket.gethostname()
ip_addr=socket.gethostbyname(hostname)
jbrowse2_url = f"http://{ip_addr}:{port}/jbrowse2/?config=splicekit_data/config.json"
print(f"{module_desc} setting JBrowse2 URL to {jbrowse2_url}")
splicekit.verbose and print(f"{module_desc} JBrowse2 URL = {jbrowse2_url}")

# read in location of gtf and fasta files
if genome_version!=None:
Expand Down

0 comments on commit 9be9997

Please sign in to comment.