Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relative path issue with paths in config #420

Open
wants to merge 2 commits into
base: v1.12rc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def resolve_config(config, workdir=None):
if isinstance(config, str):
config = yaml.load(open(config), Loader=yaml.FullLoader)

def rel(pth):
if workdir is None or os.path.isabs(pth):
def abs_path(pth):
if os.path.isabs(pth):
return pth
return os.path.join(workdir, pth)
for key in PATH_KEYS:
if key in config:
config[key] = rel(config[key])
if key in config and workdir:
config[key] = abs_path(config[key])
return config


Expand Down
6 changes: 3 additions & 3 deletions lib/patterns_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ def __init__(self, config, patterns, workdir=None):
as relative to `workdir`
"""
self.path = None
self.workdir = '.'
self.workdir = None
if workdir is not None:
config = os.path.join(workdir, config)
patterns = os.path.join(workdir, patterns)
self.workdir = workdir

if isinstance(config, str):
self.path = config
config = os.path.join(workdir, config)

self.config = common.load_config(
common.resolve_config(config, workdir))
common.resolve_config(config, self.workdir))

stranded = self.config.get('stranded', None)
self.stranded = None
Expand Down
4 changes: 3 additions & 1 deletion workflows/chipseq/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import pybedtools
from lib import common, utils, helpers, aligners, chipseq
from lib.patterns_targets import ChIPSeqConfig
from lib.utils import autobump, gb, hours
from pathlib import Path

# ----------------------------------------------------------------------------
#
Expand All @@ -30,7 +31,8 @@ helpers.preflight(config)

c = ChIPSeqConfig(
config,
config.get('patterns', 'config/chipseq_patterns.yaml')
config.get('patterns', 'config/chipseq_patterns.yaml'),
Path('.').resolve()
)

SAMPLES = c.sampletable.iloc[:, 0].values
Expand Down
3 changes: 2 additions & 1 deletion workflows/rnaseq/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import pandas as pd
from lib import common, utils, helpers, aligners
from lib.utils import autobump, gb, hours
from lib.patterns_targets import RNASeqConfig
from pathlib import Path

# ----------------------------------------------------------------------------
#
Expand All @@ -27,7 +28,7 @@ include: '../references/Snakefile'
# Verify configuration of config and sampletable files
helpers.preflight(config)

c = RNASeqConfig(config, config.get('patterns', 'config/rnaseq_patterns.yaml'))
c = RNASeqConfig(config, config.get('patterns', 'config/rnaseq_patterns.yaml'), Path('.').resolve())

SAMPLES = c.sampletable.iloc[:, 0].values
wildcard_constraints:
Expand Down