Skip to content

Commit f49a23e

Browse files
authored
Fetch read length info for run instead of just lane 1 (#66)
* Fetch read length info for run instead of just lane 1 * updated actions/cache: v2 --> v.4.2.2 * reformatted with black * add unit test for read_run_info() * sort reads list by @Number * removed printVersion function * removed version information from manifest * updated ubuntu version for running tests * changed ubuntu to 22.04 instead
1 parent a981694 commit f49a23e

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

.github/workflows/run_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Run tests
22
on: [push, pull_request]
33
jobs:
44
run-tests:
5-
runs-on: ubuntu-20.04
5+
runs-on: ubuntu-22.04
66
env:
77
NXF_VER: 21.04.1
88
NXF_ANSI_LOG: false
@@ -11,7 +11,7 @@ jobs:
1111
uses: actions/checkout@v2
1212

1313
- name: Cache singularity images
14-
uses: actions/cache@v2
14+
uses: actions/cache@v4.2.2
1515
with:
1616
path: work/singularity
1717
key: singularity-${{ hashFiles('config/nextflow_config/singularity.config') }}

bin/get_metadata.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
import argparse
77
import os
88
import json
9+
from operator import itemgetter
910
from pathlib import Path
1011
import yaml
1112

1213

1314
class RunfolderInfo:
1415
def __init__(self, runfolder, bcl2fastq_outdir):
1516
self.runfolder = runfolder
17+
self.run_info = self.read_run_info()
1618
self.run_parameters = self.read_run_parameters()
1719
self.stats_json = self.read_stats_json(bcl2fastq_outdir)
1820
self.description_and_identifier = OrderedDict()
@@ -42,6 +44,14 @@ def find(self, d, tag):
4244
for i in v:
4345
yield from self.find(i, tag)
4446

47+
def read_run_info(self):
48+
run_info = os.path.join(self.runfolder, "RunInfo.xml")
49+
if os.path.exists(run_info):
50+
with open(run_info) as f:
51+
return xmltodict.parse(f.read())
52+
else:
53+
return None
54+
4555
def read_run_parameters(self):
4656
alt_1 = os.path.join(self.runfolder, "runParameters.xml")
4757
alt_2 = os.path.join(self.runfolder, "RunParameters.xml")
@@ -109,18 +119,25 @@ def get_read_cycles(self):
109119
read_counter = 1
110120
index_counter = 1
111121
try:
112-
for read_info in self.stats_json["ReadInfosForLanes"][0]["ReadInfos"]:
113-
if read_info["IsIndexedRead"]:
122+
reads = self.run_info["RunInfo"]["Run"]["Reads"]["Read"]
123+
124+
# Handle potential cases with only one Read element
125+
if isinstance(reads, dict):
126+
reads = [reads] # Wrap it in a list to make it iterable
127+
128+
for read_info in sorted(reads, key=itemgetter("@Number")):
129+
if read_info["@IsIndexedRead"] == "Y":
114130
read_and_cycles[f"Index {index_counter} (bp)"] = read_info[
115-
"NumCycles"
131+
"@NumCycles"
116132
]
117133
index_counter += 1
118134
else:
119135
read_and_cycles[f"Read {read_counter} (bp)"] = read_info[
120-
"NumCycles"
136+
"@NumCycles"
121137
]
122138
read_counter += 1
123139
return read_and_cycles
140+
124141
except TypeError:
125142
return read_and_cycles
126143

main.nf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ def helpMessage() {
6161
"""
6262
}
6363

64-
def printVersion() {
65-
66-
log.info "seqreports v${workflow.manifest.version}"
67-
68-
}
69-
70-
printVersion()
71-
7264
if (params.help || !params.run_folder){
7365
helpMessage()
7466
exit 0

nextflow.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ manifest {
55
description = 'A Nextflow run folder QC pipeline for SciLifeLab SNP&SEQ platform'
66
mainScript = 'main.nf'
77
nextflowVersion = '!>=21.04.1'
8-
version = '1.2.0'
98
}
109

1110
profiles {

tests/unit_tests/test_get_metadata.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,8 @@ def test_get_read_cycles(runfolder_info):
108108
def test_get_info(runfolder_info):
109109
results = runfolder_info.get_info()
110110
assert len(results) == 9
111+
112+
113+
def test_read_run_info(runfolder_info):
114+
run_info = runfolder_info.read_run_info()
115+
assert len(run_info["RunInfo"]["Run"]["Reads"]["Read"]) == 4

0 commit comments

Comments
 (0)