Skip to content

Commit

Permalink
Update access_nucleo.py
Browse files Browse the repository at this point in the history
  • Loading branch information
buehlere committed Dec 16, 2024
1 parent f90d421 commit 9514221
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions runner/operator/access/v2_1_0/nucleo/access_nucleo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,37 @@ def group_by_sample_id(samples):
return sample_pairs


def group_by_run(samples):
samples.sort(key=lambda s: s["path"].split("/")[-1])
fastqs = zip(samples[::2], samples[1::2])
return list(fastqs)
def pair_samples(fastqs):
"""
pair sample fastqs based on the delivery directory.
Parameters:
fastqs (list): A list of a samples fastq files.
Returns:
float: A list of tuples containing a samples paired fastqs
"""
sample_pairs = []
expected_pair = set(["R1", "R2"])
# match R1 and R2 based on delivery directory
# sorting on file names is not enough as they are non-unique
for i, fastq in enumerate(fastqs):
dir = "/".join(fastq["path"].split("/")[0:-1])
for compare in fastqs[i + 1 :]:
compare_dir = "/".join(compare["path"].split("/")[0:-1])
if dir == compare_dir:
# check if R1 and R2 are present
r_check = set([fastq["metadata"]["R"], compare["metadata"]["R"]])
if r_check.issubset(expected_pair):
# Keep ordering consistent
if fastq["metadata"]["R"] == "R1":
sample_pairs.append((fastq, compare))
else:
sample_pairs.append((compare, fastq))
else:
sample_name = fastq["metadata"]["cmoSampleName"]
raise Exception(f"Improper pairing for: {sample_name}")
return sample_pairs


def calc_avg(sample_files, field):
Expand Down Expand Up @@ -85,7 +112,7 @@ def construct_sample_inputs(samples, request_id):
sample_group = list(sample_group)
sample_id = sample_group[0]["metadata"][settings.CMO_SAMPLE_NAME_METADATA_KEY]

fgbio_fastq_to_bam_input = group_by_run(sample_group)
fgbio_fastq_to_bam_input = pair_samples(sample_group)
fgbio_fastq_to_bam_input = [
[
{"class": "File", "location": "juno://" + s[0]["path"]},
Expand Down

0 comments on commit 9514221

Please sign in to comment.