Skip to content

Commit

Permalink
allow relative paths in yaml config
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewprzh committed Nov 6, 2023
1 parent 05af068 commit e915594
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ def merge_files(file_names, merged_file_name, stats_file_names=None, ignore_read
outf.write("__no_feature\t%d\n" % not_assigned_reads)
outf.write("__not_aligned\t%d\n" % not_aligned_reads)


def normalize_path(config_path, file_path):
if os.path.isabs(file_path):
return os.path.normpath(file_path)
else:
return os.path.normpath(os.path.join(os.path.dirname(config_path), file_path))

12 changes: 6 additions & 6 deletions src/input_data_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import yaml
from collections import defaultdict

from .file_utils import normalize_path


logger = logging.getLogger('IsoQuant')

Expand Down Expand Up @@ -191,16 +193,14 @@ def get_samples_from_file(self, file_name):
def has_replicas(self):
return any(len(sample.file_list) > 1 for sample in self.samples)

def get_samples_from_yaml(self, file_name):
def get_samples_from_yaml(self, yaml_file_path):
# TODO: allow relative paths, i.e. introduce "path fixer" for non-abosulte paths (relative to YAML file)
sample_files = []
experiment_names = []
illumina_bam = []
readable_names_dict = defaultdict(lambda: defaultdict(str))
yaml_file = open(file_name, 'r')
yaml_file = open(yaml_file_path, 'r')
con = yaml.safe_load(yaml_file)
current_sample = []
current_sample_name = self.experiment_prefix
current_index = 0
t = con[0]
if not 'data format' in t.keys():
Expand Down Expand Up @@ -235,7 +235,7 @@ def get_samples_from_yaml(self, file_name):
logger.critical("Experiment %s does not contain any files" %current_sample_name)
exit(-2)
else:
current_sample = sample['long read files']
current_sample = [normalize_path(yaml_file_path, b) for b in sample['long read files']]
names = 'labels' in sample.keys()
if names and not len(sample['labels']) == len(current_sample):
logger.critical("The number of file aliases differs from the number of files")
Expand All @@ -254,7 +254,7 @@ def get_samples_from_yaml(self, file_name):
sample_files.append([current_sample])
experiment_names.append(current_sample_name)
if 'illumina bam' in sample.keys():
illumina_bam.append(sample['illumina bam'])
illumina_bam.append([normalize_path(yaml_file_path, ib) for ib in sample['illumina bam']])
else:
illumina_bam.append(None)

Expand Down
2 changes: 1 addition & 1 deletion tests/console_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_with_illumina():
"-o", out_dir,
"--data_type", "nanopore",
"--bam", os.path.join(data_dir, "chr9.4M.ont.sim.polya.bam"),
"--illumina_bam", os.path.join(data_dir, "chr9.4M.Illumina.bam")
"--illumina_bam", os.path.join(data_dir, "chr9.4M.Illumina.bam"),
"--genedb", os.path.join(data_dir, "chr9.4M.gtf.gz"), "--complete_genedb",
"-r", os.path.join(data_dir, "chr9.4M.fa.gz"),
"-t", "2",
Expand Down

0 comments on commit e915594

Please sign in to comment.