Skip to content

Commit 1d263fe

Browse files
committed
showing signs of life
1 parent 10a3c4a commit 1d263fe

7 files changed

Lines changed: 42 additions & 21 deletions

File tree

neat/cli/commands/read_simulator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import argparse
6+
from pathlib import Path
67

78
from ...read_simulator import read_simulator_runner
89
from .base import BaseCommand

neat/read_simulator/parallel_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def main(options: Options) -> None:
8787
if options.produce_vcf:
8888
vcf = current_output_dir / options.vcf.name
8989

90-
current_options = Options(reference, current_output_dir, fq1, fq2, vcf, bam, options)
90+
current_options = options.copy_with_changes(reference, current_output_dir, fq1, fq2, vcf, bam)
9191
output_opts.append(current_options)
9292

9393
pool = Pool()

neat/read_simulator/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def read_simulator_runner(config: str, output_dir: str, file_prefix: str):
5353
# Read options file
5454
options = Options.from_cli(
5555
output_dir,
56-
file_prefix,
56+
str(file_prefix),
5757
config,
5858

5959
)

neat/read_simulator/single_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def read_simulator_single(options: Options):
128128

129129
local_bam_pickle_file = None
130130
if options.produce_bam:
131-
local_bam_pickle_file = options.temp_dir_path / f'{options.output.stem}_tmp_{contig}_{threadidx}.p.gz'
131+
local_bam_pickle_file = options.temp_dir_path / f'{options.output_dir}/{options.output_prefix}_tmp_{contig}_{threadidx}.p.gz'
132132

133133
if threadidx == 1:
134134
# init_progress_info()

neat/read_simulator/utils/options.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
trigger quick-run mode, setting most of the parameters to defaults.
1515
"""
1616
import os
17+
from copy import deepcopy
1718
from typing import Any
1819

1920
import numpy as np
@@ -50,7 +51,7 @@ class representing the options
5051

5152
def __init__(self,
5253
reference: Path | None = None,
53-
output_dir: Path | None = Path(os.getcwd()),
54+
output_dir: Path | None = Path.cwd(),
5455
fq1: Path | None = None,
5556
fq2: Path | None = None,
5657
vcf: Path | None = None,
@@ -139,7 +140,7 @@ def __init__(self,
139140
super().__init__(**kwargs)
140141
self.reference: Path = reference
141142
self.output_dir: Path = output_dir
142-
self.output = self.output_dir / output_prefix
143+
self.output_prefix: str = output_prefix
143144
self.overwrite_output = overwrite_output
144145
self.rng_seed = rng_seed
145146
self.read_len: int = read_len
@@ -206,9 +207,6 @@ def from_cli(output_dir: Path,
206207
should be the highest acceptable value (inclusive).
207208
(type, default, criteria1 (low/'exists'), criteria2 (high/None)
208209
"""
209-
# TODO maybe redo as a dataclass?
210-
output = output_dir / output_prefix
211-
212210
# These are for checking
213211
defs = {
214212
'reference': (Path, None, 'exists', None),
@@ -331,6 +329,29 @@ def read_yaml(self, config_yaml: Path, args: dict):
331329
value = Path(value)
332330
args[key] = value
333331

332+
def copy_with_changes(self,
333+
reference: Path | None = None,
334+
current_output_dir: Path | None = None,
335+
fq1: Path | None = None,
336+
fq2: Path | None = None,
337+
vcf: Path | None = None,
338+
bam: Path | None = None,
339+
):
340+
return_options = deepcopy(self)
341+
if reference is not None:
342+
return_options.reference = reference
343+
if current_output_dir is not None:
344+
return_options.current_output_dir = current_output_dir
345+
if fq1 is not None:
346+
return_options.fq1 = fq1
347+
if fq2 is not None:
348+
return_options.fq2 = fq2
349+
if vcf is not None:
350+
return_options.vcf = vcf
351+
if bam is not None:
352+
return_options.bam = bam
353+
return return_options
354+
334355
def set_random_seed(self) -> Generator:
335356
"""
336357
Sets up random number generator, which will be used for the run.
@@ -376,26 +397,26 @@ def log_configuration(self):
376397
files_to_produce = f'Producing the following files:\n'
377398
if self.produce_fastq:
378399
if self.paired_ended:
379-
fq1 = f'{str(self.output)}_r1.fastq.gz'
380-
fq2 = f'{str(self.output)}_r2.fastq.gz'
400+
fq1 = f'{str(self.output_dir)}/{self.output_prefix}_r1.fastq.gz'
401+
fq2 = f'{str(self.output_dir)}/{self.output_prefix}_r2.fastq.gz'
381402
validate_output_path(fq1, True, self.overwrite_output)
382403
validate_output_path(fq2, True, self.overwrite_output)
383404
files_to_produce += f'\t- {fq1}\n'
384405
files_to_produce += f'\t- {fq2}\n'
385406
self.fq1 = Path(fq1)
386407
self.fq2 = Path(fq2)
387408
else:
388-
fq1 = f'{str(self.output)}.fastq.gz'
409+
fq1 = f'{str(self.output_dir)}/{self.output_prefix}.fastq.gz'
389410
validate_output_path(fq1, True, self.overwrite_output)
390411
files_to_produce += f'\t- {fq1}\n'
391412
self.fq1 = Path(fq1)
392413
if self.produce_bam:
393-
bam = f'{self.output}_golden.bam'
414+
bam = f'{str(self.output_dir)}/{self.output_prefix}_golden.bam'
394415
validate_output_path(bam, True, self.overwrite_output)
395416
files_to_produce += f'\t- {bam}\n'
396417
self.bam = Path(bam)
397418
if self.produce_vcf:
398-
vcf = f'{self.output}_golden.vcf.gz'
419+
vcf = f'{str(self.output_dir)}/{self.output_prefix}_golden.vcf.gz'
399420
validate_output_path(vcf, True, self.overwrite_output)
400421
files_to_produce += f'\t- {vcf}\n'
401422
self.vcf = Path(vcf)
@@ -420,8 +441,7 @@ def log_configuration(self):
420441
if splits_dir.is_dir():
421442
_LOG.info(f'Reusing existing splits {splits_dir}.')
422443
else:
423-
_LOG.error(f'Reused splits set to True, but splits dir not found: {splits_dir}.')
424-
sys.exit(1)
444+
_LOG.warning(f'Reused splits set to True, but splits dir not found: {splits_dir}. Creating new splits')
425445

426446
validate_output_path(splits_dir, False)
427447
self.splits_dir = splits_dir

neat/read_simulator/utils/output_file_writer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ def __init__(self,
9696
# Set up filenames based on booleans
9797
files_to_write = []
9898
if self.paired and self.write_fastq:
99-
self.fastq1_fn = options.output.parent / f'{options.output.stem}_r1.fastq.gz'
100-
self.fastq2_fn = options.output.parent / f'{options.output.stem}_r2.fastq.gz'
99+
self.fastq1_fn = options.fq1
100+
self.fastq2_fn = options.fq2
101101
self.fastq_fns = [self.fastq1_fn, self.fastq2_fn]
102102
files_to_write.extend(self.fastq_fns)
103103
elif self.write_fastq:
104-
self.fastq1_fn = options.output.parent / f'{options.output.stem}.fastq.gz'
104+
self.fastq1_fn = options.fq1
105105
self.fastq2_fn = self.temporary_dir / "dummy.fastq.gz"
106106
self.fastq_fns = [self.fastq1_fn, self.fastq2_fn]
107107
files_to_write.extend(self.fastq_fns)
108108
if self.write_bam:
109-
self.bam_fn = options.output.parent / f'{options.output.stem}_golden.bam'
109+
self.bam_fn = options.bam
110110
self.bam_keys = list(bam_header)
111111
files_to_write.append(self.bam_fn)
112112
if self.write_vcf:
113-
self.vcf_fn = options.output.parent / f'{options.output.stem}_golden.vcf.gz'
113+
self.vcf_fn = options.vcf
114114
files_to_write.append(self.vcf_fn)
115115

116116
self.files_to_write = files_to_write

neat/read_simulator/utils/stitch_outputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
_LOG = logging.getLogger(__name__)
2222

23-
def concat(files_to_join: List[(Path,)], dest: Path) -> None:
23+
def concat(files_to_join: List[Path], dest: Path) -> None:
2424
if not files_to_join:
2525
# Nothing to do, and no error to throw
2626
return

0 commit comments

Comments
 (0)