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

KeyError while preparing assembly SampleSheet #11

Open
dfornika opened this issue Sep 2, 2023 · 0 comments
Open

KeyError while preparing assembly SampleSheet #11

dfornika opened this issue Sep 2, 2023 · 0 comments

Comments

@dfornika
Copy link
Member

dfornika commented Sep 2, 2023

We've run into an error:

Traceback (most recent call last):
  File "auto-cpo/bin/auto-cpo", line 33, in <module>
    sys.exit(load_entry_point('auto-cpo', 'console_scripts', 'auto-cpo')())
  File "auto-cpo/auto_cpo/__main__.py", line 62, in main
    core.analyze_run(config, run, "short")
  File "auto-cpo/auto_cpo/core.py", line 327, in analyze_run
    writer.writerow(library_fastq_paths[library_id])
KeyError: '<SAMPLE_ID>'

The context is:

auto-cpo/auto_cpo/core.py

Lines 318 to 327 in ee7ba4e

library_fastq_paths = get_library_fastq_paths(run['analysis_parameters']['fastq_input'])
assembly_samplesheet_path = os.path.join(samplesheets_dir, analysis_run_id + '_routine-assembly_samplesheet.csv')
with open(assembly_samplesheet_path, 'w') as f:
output_fieldnames = ['ID', 'R1', 'R2']
writer = csv.DictWriter(f, fieldnames=output_fieldnames, dialect='unix', quoting=csv.QUOTE_MINIMAL)
writer.writeheader()
for library_id, library_qc in total_bases_by_library.items():
pass_fail = library_qc['total_bases_input_pass_fail']
if pass_fail == "PASS" or pass_fail == "WARN":
writer.writerow(library_fastq_paths[library_id])

This function also relevant:

auto-cpo/auto_cpo/core.py

Lines 118 to 143 in ee7ba4e

def get_library_fastq_paths(fastq_input_dir: str):
"""
Get the paths to all of the fastq files in a directory.
param: fastq_input_dir: Path to a directory containing fastq files.
type: fastq_input_dir: str
return: Paths to R1 and R2 fastq files, indexed by library ID. Keys of the dict are library IDs, values are dicts with keys: ['ID', 'R1', 'R2'].
rtype: dict[str, dict[str, str]]
"""
fastq_paths_by_library_id = {}
for fastq_file in glob.glob(os.path.join(fastq_input_dir, '*.f*q.gz')):
fastq_file_basename = os.path.basename(fastq_file)
fastq_file_abspath = os.path.abspath(fastq_file)
fastq_file_basename_parts = fastq_file_basename.split('_')
library_id = fastq_file_basename_parts[0]
if library_id not in fastq_paths_by_library_id:
fastq_paths_by_library_id[library_id] = {
'ID': library_id,
'R1': None,
'R2': None,
}
if '_R1' in fastq_file_basename:
fastq_paths_by_library_id[library_id]['R1'] = fastq_file_abspath
elif '_R2' in fastq_file_basename:
fastq_paths_by_library_id[library_id]['R2'] = fastq_file_abspath
return fastq_paths_by_library_id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant