diff --git a/.dockstore.yml b/.dockstore.yml index ce35334c..496f3ebd 100644 --- a/.dockstore.yml +++ b/.dockstore.yml @@ -66,6 +66,7 @@ workflows: - dragen-somatic-with-germline-pipeline/4.2.4__20240830041201 - dragen-somatic-with-germline-pipeline/4.2.4__20241107061831 - dragen-somatic-with-germline-pipeline/4.2.4__20241114110541 + - dragen-somatic-with-germline-pipeline/4.2.4__20241210230846 - name: rnasum-pipeline_1_0_0 subclass: CWL primaryDescriptorPath: /.dockstore/rnasum-pipeline/1.0.0/rnasum-pipeline__1.0.0.packed.cwl.json diff --git a/.dockstore/dragen-somatic-with-germline-pipeline/4.2.4/dragen-somatic-with-germline-pipeline__4.2.4.packed.cwl.json b/.dockstore/dragen-somatic-with-germline-pipeline/4.2.4/dragen-somatic-with-germline-pipeline__4.2.4.packed.cwl.json index 3c4591db..f56f9c61 100644 --- a/.dockstore/dragen-somatic-with-germline-pipeline/4.2.4/dragen-somatic-with-germline-pipeline__4.2.4.packed.cwl.json +++ b/.dockstore/dragen-somatic-with-germline-pipeline/4.2.4/dragen-somatic-with-germline-pipeline__4.2.4.packed.cwl.json @@ -138,7 +138,7 @@ "listing": [ { "entryname": "$(get_script_path())", - "entry": "#!/usr/bin/env bash\n\n# Fail on non-zero exit of subshell\nset -euo pipefail\n\n# Run partial reconfig\n/opt/edico/bin/dragen \\\\\n --partial-reconfig HMM \\\\\n --ignore-version-check true\n\n# Create directories\nmkdir --parents \\\\\n \"$(get_ref_mount())\" \\\\\n \"$(get_intermediate_results_dir())\" \\\\\n \"$(inputs.output_directory)\"\n\n# untar ref data into scratch space\ntar \\\\\n --directory \"$(get_ref_mount())\" \\\\\n --extract \\\\\n --file \"$(inputs.reference_tar.path)\"\n\n# Check if ora reference is set\nif [[ \"$(is_not_null(inputs.ora_reference_tar))\" == \"true\" ]]; then\n tar \\\\\n --directory \"$(get_ref_mount())\" \\\\\n --extract \\\\\n --file \"$(inputs.ora_reference_tar.path)\"\nfi\n\n# Confirm either of fastq_list, fastq_list_rows, bam_input or cram_input is defined\nif [[ \"$(boolean_to_int(is_not_null(inputs.fastq_list)) + boolean_to_int(is_not_null(inputs.fastq_list_rows)) + boolean_to_int(is_not_null(inputs.bam_input)) + boolean_to_int(is_not_null(inputs.cram_input)))\" -ne \"1\" ]]; then\n echo \"Please set one and only one of fastq_list, fastq_list_rows and bam_input for normal sample\" 1>&2\n exit 1\nfi\n\n# Run dragen command and import options from cli\n\"$(get_dragen_bin_path())\" \"\\${@}\"\n" + "entry": "#!/usr/bin/env bash\n\n# Fail on non-zero exit of subshell\nset -euo pipefail\n\n# Run partial reconfig\n/opt/edico/bin/dragen \\\\\n --partial-reconfig HMM \\\\\n --ignore-version-check true\n\n# Create directories\nmkdir --parents \\\\\n \"$(get_ref_mount())\" \\\\\n \"$(get_intermediate_results_dir())\" \\\\\n \"$(inputs.output_directory)\"\n\n# untar ref data into scratch space\ntar \\\\\n --directory \"$(get_ref_mount())\" \\\\\n --extract \\\\\n --file \"$(inputs.reference_tar.path)\"\n\n# Check if ora reference is set\nif [[ \"$(is_not_null(inputs.ora_reference_tar))\" == \"true\" ]]; then\n tar \\\\\n --directory \"$(get_ref_mount())\" \\\\\n --extract \\\\\n --file \"$(get_attribute_from_optional_input(inputs.ora_reference_tar, \"path\"))\"\nfi\n\n# Confirm either of fastq_list, fastq_list_rows, bam_input or cram_input is defined\nif [[ \"$(boolean_to_int(is_not_null(inputs.fastq_list)) + boolean_to_int(is_not_null(inputs.fastq_list_rows)) + boolean_to_int(is_not_null(inputs.bam_input)) + boolean_to_int(is_not_null(inputs.cram_input)))\" -ne \"1\" ]]; then\n echo \"Please set one and only one of fastq_list, fastq_list_rows and bam_input for normal sample\" 1>&2\n exit 1\nfi\n\n# Run dragen command and import options from cli\n\"$(get_dragen_bin_path())\" \"\\${@}\"\n" }, "${\n return generate_germline_mount_points(inputs);\n}\n" ], @@ -146,7 +146,7 @@ }, { "expressionLib": [ - "/* Author:Alexis Lucattini */\n/* For assistance on generation of typescript expressions */\n/* In CWL, please visit our wiki page at https://github.com/umccr/cwl-ica/wiki/TypeScript */\n/* Imports */\n/* Functions */\nfunction get_script_path() {\n /*\n Abstract script path, can then be referenced in baseCommand attribute too\n Makes things more readable.\n */\n return \"run-dragen-script.sh\";\n}\nfunction get_scratch_mount() {\n /*\n Return the path of the scratch directory space\n */\n return \"/scratch/\";\n}\nfunction get_intermediate_results_dir() {\n /*\n Get intermediate results directory as /scratch for dragen runs\n */\n return get_scratch_mount() + \"intermediate-results/\";\n}\nfunction get_name_root_from_tarball(basename) {\n var tar_ball_regex = /(\\S+)\\.tar\\.gz/g;\n var tar_ball_expression = tar_ball_regex.exec(basename);\n if (tar_ball_expression === null) {\n throw new Error(\"Could not get nameroot from \".concat(basename));\n }\n return tar_ball_expression[1];\n}\nfunction get_ref_path(reference_input_obj) {\n /*\n Get the reference path\n */\n return get_ref_mount() + get_name_root_from_tarball(reference_input_obj.basename) + \"/\";\n}\nfunction get_ref_mount() {\n /*\n Get the reference mount point\n */\n return get_scratch_mount() + \"ref/\";\n}\nfunction get_dragen_bin_path() {\n /*\n Get dragen bin path\n */\n return \"/opt/edico/bin/dragen\";\n}\nfunction get_dragen_eval_line() {\n /*\n Return string\n */\n return \"eval \\\"\" + get_dragen_bin_path() + \"\\\" '\\\"\\$@\\\"' \\n\";\n}\nfunction get_fastq_list_csv_path() {\n /*\n The fastq list path must be placed in working directory\n */\n return \"fastq_list.csv\";\n}\nfunction get_tumor_fastq_list_csv_path() {\n /*\n The tumor fastq list path must be placed in working directory\n */\n return \"tumor_fastq_list.csv\";\n}\nfunction get_ora_mv_files_script_path() {\n /*\n Get the ora mv files script path\n */\n return \"mv-ora-output-files.sh\";\n}\nfunction get_new_fastq_list_csv_script_path() {\n /*\n Get the new fastq list csv script path\n */\n return \"generate-new-fastq-list-csv.sh\";\n}\nfunction get_fastq_gz_md5sum_files_script_path() {\n /*\n Get the script path to generating the md5sum for each fastq gzip file\n */\n return \"generate-md5sum-for-fastq-gz-files.sh\";\n}\nfunction get_fastq_gz_file_sizes_script_path() {\n /*\n Get the script path to generating the filesizes for each fastq gzip file\n */\n return \"generate-file-sizes-for-fastq-gz-files.sh\";\n}\nfunction get_fastq_ora_md5sum_files_script_path() {\n /*\n Get the script path for generating the md5sum for each fastq ora file\n */\n return \"generate-md5sum-for-fastq-ora-files.sh\";\n}\nfunction get_fastq_ora_file_sizes_script_path() {\n /*\n Get the script path to generating the filesizes for each fastq gzip file\n */\n return \"generate-file-sizes-for-fastq-ora-files.sh\";\n}\nfunction get_normal_name_from_fastq_list_rows(fastq_list_rows) {\n /*\n Get the normal sample name from the fastq list rows object\n */\n /*\n Check fastq list rows is defined\n */\n if (fastq_list_rows === undefined || fastq_list_rows === null) {\n return null;\n }\n /*\n Get RGSM value and return\n */\n return fastq_list_rows[0].rgsm;\n}\nfunction get_normal_name_from_fastq_list_csv(fastq_list_csv) {\n /*\n Get the normal name from the fastq list csv...\n */\n /*\n Check file is defined\n */\n if (fastq_list_csv === undefined || fastq_list_csv === null) {\n return null;\n }\n /*\n Check contents are defined\n */\n if (fastq_list_csv.contents === null || fastq_list_csv.contents === undefined) {\n return null;\n }\n /*\n Confirm fastq list csv is of type File\n */\n if (fastq_list_csv.class !== \"File\") {\n throw new Error(\"Could not confirm input fastq_list_csv is of type File\");\n }\n /*\n Split contents by line\n */\n var contents_by_line = [];\n fastq_list_csv.contents.split(\"\\n\").forEach(function (line_content) {\n var stripped_line_content = line_content.replace(/(\\r\\n|\\n|\\r)/gm, \"\");\n if (stripped_line_content !== \"\") {\n contents_by_line.push(stripped_line_content);\n }\n });\n var column_names = contents_by_line[0].split(\",\");\n /*\n Get RGSM index value (which column is RGSM at?)\n */\n var rgsm_index = column_names.indexOf(\"RGSM\");\n /*\n RGSM is not in index. Return null\n */\n if (rgsm_index === -1) {\n return null;\n }\n /*\n Get RGSM value of first row and return\n */\n return contents_by_line[1].split(\",\")[rgsm_index];\n}\nfunction get_normal_output_prefix(inputs) {\n var _a, _b;\n /*\n Get the normal RGSM value and then add _normal to it\n */\n var normal_name = null;\n var normal_re_replacement = /_normal$/;\n /*\n Check if bam_input is set\n */\n if (inputs.bam_input !== null && inputs.bam_input !== undefined) {\n /* Remove _normal from nameroot if it already exists */\n /* We dont want _normal_normal as a suffix */\n return \"\".concat((_a = inputs.bam_input.nameroot) === null || _a === void 0 ? void 0 :_a.replace(normal_re_replacement, \"\"), \"_normal\");\n }\n /*\n Check if cram_input is set\n */\n if (inputs.cram_input !== null && inputs.cram_input !== undefined) {\n /* Remove _normal from nameroot if it already exists */\n /* We dont want _normal_normal as a suffix */\n return \"\".concat((_b = inputs.cram_input.nameroot) === null || _b === void 0 ? void 0 :_b.replace(normal_re_replacement, \"\"), \"_normal\");\n }\n /*\n Check if fastq list file is set\n */\n if (inputs.fastq_list !== null && inputs.fastq_list !== undefined) {\n normal_name = get_normal_name_from_fastq_list_csv(inputs.fastq_list);\n if (normal_name !== null) {\n return \"\".concat(normal_name, \"_normal\");\n }\n }\n /*\n Otherwise collect and return from schema object\n */\n normal_name = get_normal_name_from_fastq_list_rows(inputs.fastq_list_rows);\n return \"\".concat(normal_name, \"_normal\");\n}\nfunction build_fastq_list_csv_header(header_names) {\n /*\n Convert lowercase labels to uppercase values\n i.e\n [ \"rgid\", \"rglb\", \"rgsm\", \"lane\", \"read_1\", \"read_2\" ]\n to\n \"RGID,RGLB,RGSM,Lane,Read1File,Read2File\"\n */\n var modified_header_names = [];\n for (var _i = 0, header_names_1 = header_names; _i < header_names_1.length; _i++) {\n var header_name = header_names_1[_i];\n if (header_name.indexOf(\"rg\") === 0) {\n /*\n rgid -> RGID\n */\n modified_header_names.push(header_name.toUpperCase());\n }\n else if (header_name.indexOf(\"read\") === 0) {\n /*\n read_1 -> Read1File\n */\n modified_header_names.push(\"Read\" + header_name.charAt(header_name.length - 1) + \"File\");\n }\n else {\n /*\n lane to Lane\n */\n modified_header_names.push(header_name[0].toUpperCase() + header_name.substr(1));\n }\n }\n /*\n Convert array to comma separated strings\n */\n return modified_header_names.join(\",\") + \"\\n\";\n}\nfunction get_fastq_list_row_as_csv_row(fastq_list_row, row_order) {\n var fastq_list_row_values_array = [];\n /* This for loop is here to ensure were assigning values in the same order as the header */\n for (var _i = 0, row_order_1 = row_order; _i < row_order_1.length; _i++) {\n var item_index = row_order_1[_i];\n var found_item = false;\n /* Find matching attribute in this row */\n for (var _a = 0, _b = Object.getOwnPropertyNames(fastq_list_row); _a < _b.length; _a++) {\n var fastq_list_row_field_name = _b[_a];\n var fastq_list_row_field_value = fastq_list_row[fastq_list_row_field_name];\n if (fastq_list_row_field_value === null) {\n /*\n Item not found, add an empty attribute for this cell in the csv\n */\n continue;\n }\n /* The header value matches the name in the item */\n if (fastq_list_row_field_name === item_index) {\n /*\n If the field value has a class attribute then it's either read_1 or read_2\n */\n if (fastq_list_row_field_value.hasOwnProperty(\"class\")) {\n var fastq_list_row_field_value_file = fastq_list_row_field_value;\n /*\n Assert that this is actually of class file\n */\n if (fastq_list_row_field_value_file.class !== \"File\") {\n continue;\n }\n if (fastq_list_row_field_value_file.path !== null && fastq_list_row_field_value_file.path !== undefined) {\n /*\n Push the path attribute to the fastq list csv row if it is not null\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value_file.path);\n }\n else {\n /*\n Otherwise push the location attribute\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value_file.location);\n }\n }\n else {\n /*\n Push the string attribute to the fastq list csv row\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value.toString());\n }\n found_item = true;\n break;\n }\n }\n if (!found_item) {\n /*\n Push blank cell if no item found\n */\n fastq_list_row_values_array.push(\"\");\n }\n }\n /*\n Convert to string and return as string\n */\n return fastq_list_row_values_array.join(\",\") + \"\\n\";\n}\nfunction generate_fastq_list_csv(fastq_list_rows) {\n /*\n Fastq list rows generation\n */\n var fastq_csv_file = {\n class:\"File\",\n basename:get_fastq_list_csv_path()\n };\n /*\n Set the row order\n */\n var row_order = [];\n /*\n Set the array order\n Make sure we iterate through all rows of the array\n */\n for (var _i = 0, fastq_list_rows_1 = fastq_list_rows; _i < fastq_list_rows_1.length; _i++) {\n var fastq_list_row = fastq_list_rows_1[_i];\n for (var _a = 0, _b = Object.getOwnPropertyNames(fastq_list_row); _a < _b.length; _a++) {\n var fastq_list_row_field_name = _b[_a];\n if (row_order.indexOf(fastq_list_row_field_name) === -1) {\n row_order.push(fastq_list_row_field_name);\n }\n }\n }\n /*\n Make header\n */\n fastq_csv_file.contents = build_fastq_list_csv_header(row_order);\n /*\n For each fastq list row,\n collect the values of each attribute but in the order of the header\n */\n for (var _c = 0, fastq_list_rows_2 = fastq_list_rows; _c < fastq_list_rows_2.length; _c++) {\n var fastq_list_row = fastq_list_rows_2[_c];\n /* Add csv row to file contents */\n fastq_csv_file.contents += get_fastq_list_row_as_csv_row(fastq_list_row, row_order);\n }\n return fastq_csv_file;\n}\nfunction generate_germline_mount_points(inputs) {\n /*\n Create and add in the fastq list csv for the input fastqs\n */\n var e = [];\n if (inputs.fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.fastq_list_rows)\n });\n }\n if (inputs.fastq_list !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":inputs.fastq_list\n });\n }\n /*\n Return file paths\n */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\nfunction generate_somatic_mount_points(inputs) {\n /*\n Create and add in the fastq list csv for the input fastqs\n */\n var e = [];\n if (inputs.fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.fastq_list_rows)\n });\n }\n if (inputs.tumor_fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_tumor_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.tumor_fastq_list_rows)\n });\n }\n if (inputs.fastq_list !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":inputs.fastq_list\n });\n }\n if (inputs.tumor_fastq_list !== null) {\n e.push({\n \"entryname\":get_tumor_fastq_list_csv_path(),\n \"entry\":inputs.tumor_fastq_list\n });\n }\n /*\n Return file paths\n */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\nfunction generate_transcriptome_mount_points(inputs) {\n /*\n Calls another function that generates mount points\n */\n return generate_germline_mount_points(inputs);\n}\n/* Custom functions for dragen reference tarball build */\nfunction get_liftover_dir() {\n /* Hardcoded liftover directory in dragen 4.2 */\n return \"/opt/edico/liftover/\";\n}\nfunction get_mask_dir() {\n /* Hardcoded mask directory in dragen 4.2 */\n return \"/opt/edico/fasta_mask/\";\n}\nfunction get_ref_scratch_dir(reference_name) {\n /* We get the reference scratch directory as a combination of */\n /* the dragen scratch mount and the reference name */\n return get_scratch_mount() + reference_name + \"/\";\n}\nfunction get_ora_intermediate_output_dir() {\n return get_scratch_mount() + \"ora-outputs/\";\n}\nfunction generate_ora_mv_files_script(fastq_list_rows, input_directory, output_directory) {\n /*\n Generate the shell script with a list of echo commands to write a new fastq list csv to stdout, however\n the fastq list csv contains the ora files as outputs instead\n */\n var ora_mv_files_script = \"#!/usr/bin/env bash\\n\\n\";\n ora_mv_files_script += \"# Exit on failure\\n\";\n ora_mv_files_script += \"set -euo pipefail\\n\\n\";\n ora_mv_files_script += \"# Get fastq ora paths\\n\";\n ora_mv_files_script += \"FASTQ_ORA_OUTPUT_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_3 = fastq_list_rows; _i < fastq_list_rows_3.length; _i++) {\n var fastq_list_row = fastq_list_rows_3[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n ora_mv_files_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n /* Add relative path of read 2 */\n ora_mv_files_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n ora_mv_files_script += \")\\n\\n\";\n ora_mv_files_script += \"# Move all ora files to the final output directory\\n\";\n ora_mv_files_script += \"for fastq_ora_output_path in \\\"${FASTQ_ORA_OUTPUT_PATHS[@]}\\\"; do\\n\";\n ora_mv_files_script += \" fastq_ora_scratch_path=\\\"\".concat(get_ora_intermediate_output_dir(), \"$(basename \\\"${fastq_ora_output_path}\\\")\\\"\\n\");\n ora_mv_files_script += \" mkdir -p \\\"$(dirname \\\"\".concat(output_directory, \"/${fastq_ora_output_path}\\\")\\\"\\n\");\n ora_mv_files_script += \" rsync --archive \\\\\\n\";\n ora_mv_files_script += \" --remove-source-files \\\\\\n\";\n ora_mv_files_script += \" --include \\\"$(basename \\\"${fastq_ora_output_path}\\\")\\\" \\\\\\n\";\n ora_mv_files_script += \" --exclude \\\"*\\\" \\\\\\n\";\n ora_mv_files_script += \" \\\"$(dirname \\\"${fastq_ora_scratch_path}\\\")/\\\" \\\\\\n\";\n ora_mv_files_script += \" \\\"$(dirname \\\"\".concat(output_directory, \"/${fastq_ora_output_path}\\\")/\\\"\\n\");\n ora_mv_files_script += \"done\\n\\n\";\n ora_mv_files_script += \"# Transfer all other files\\n\";\n ora_mv_files_script += \"mkdir -p \\\"\".concat(output_directory, \"/ora-logs/\\\"\\n\");\n ora_mv_files_script += \"mv \\\"\".concat(get_ora_intermediate_output_dir(), \"\\\" \\\"\").concat(output_directory, \"/ora-logs/compression/\\\"\\n\");\n return {\n class:\"File\",\n basename:get_ora_mv_files_script_path(),\n contents:ora_mv_files_script\n };\n}\nfunction generate_fastq_gz_md5sum_files_script(fastq_list_rows, input_directory) {\n /*\n Generate the fastq gzip md5sum files script command, results are printed to stdout\n */\n var get_md5sum_fastq_gz_script = \"#!/usr/bin/env bash\\n\\n\";\n get_md5sum_fastq_gz_script += \"# Exit on failure\\n\";\n get_md5sum_fastq_gz_script += \"set -euo pipefail\\n\\n\";\n /* Initialise the bash array */\n get_md5sum_fastq_gz_script += \"# Get fastq gz paths\\n\";\n get_md5sum_fastq_gz_script += \"FASTQ_GZ_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_4 = fastq_list_rows; _i < fastq_list_rows_4.length; _i++) {\n var fastq_list_row = fastq_list_rows_4[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n get_md5sum_fastq_gz_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", ''), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n get_md5sum_fastq_gz_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", ''), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n get_md5sum_fastq_gz_script += \")\\n\\n\";\n /* Build the for loop */\n get_md5sum_fastq_gz_script += \"# Generate md5sums for the input fastq gz files\\n\";\n get_md5sum_fastq_gz_script += \"for fastq_gz_path in \\\"${FASTQ_GZ_PATHS[@]}\\\"; do\\n\";\n get_md5sum_fastq_gz_script += \" full_input_path=\\\"\".concat(input_directory.path, \"/${fastq_gz_path}\\\"\\n\");\n get_md5sum_fastq_gz_script += \" md5sum \\\"${full_input_path}\\\" | sed \\\"s%${full_input_path}%${fastq_gz_path}%\\\"\\n\";\n get_md5sum_fastq_gz_script += \"done\\n\\n\";\n get_md5sum_fastq_gz_script += \"# Md5sum script complete\\n\";\n return {\n class:\"File\",\n basename:get_fastq_gz_md5sum_files_script_path(),\n contents:get_md5sum_fastq_gz_script\n };\n}\nfunction generate_fastq_gz_file_sizes_script(fastq_list_rows, input_directory) {\n /*\n Generate the fastq gzip get files sizes, results are printed to stdout\n */\n var get_filesizes_fastq_gz_script = \"#!/usr/bin/env bash\\n\\n\";\n get_filesizes_fastq_gz_script += \"# Exit on failure\\n\";\n get_filesizes_fastq_gz_script += \"set -euo pipefail\\n\\n\";\n /* Initialise the bash array */\n get_filesizes_fastq_gz_script += \"# Get fastq gz paths\\n\";\n get_filesizes_fastq_gz_script += \"FASTQ_GZ_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_5 = fastq_list_rows; _i < fastq_list_rows_5.length; _i++) {\n var fastq_list_row = fastq_list_rows_5[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n get_filesizes_fastq_gz_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", ''), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n get_filesizes_fastq_gz_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", ''), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n get_filesizes_fastq_gz_script += \")\\n\\n\";\n /* Build the for loop */\n /* Initialise the tsv */\n get_filesizes_fastq_gz_script += \"# Initialise the tsv header\\n\";\n get_filesizes_fastq_gz_script += \"echo \\\"fastqPath\\tfileSizeInBytes\\\"\\n\\n\";\n get_filesizes_fastq_gz_script += \"# Generate file sizes for the input fastq gz files\\n\";\n get_filesizes_fastq_gz_script += \"for fastq_gz_path in \\\"${FASTQ_GZ_PATHS[@]}\\\"; do\\n\";\n get_filesizes_fastq_gz_script += \" file_size=\\\"$(wc -c < \\\"\".concat(input_directory.path, \"/${fastq_gz_path}\\\")\\\"\\n\");\n get_filesizes_fastq_gz_script += \" echo \\\"${fastq_gz_path}\\t${file_size}\\\"\\n\";\n get_filesizes_fastq_gz_script += \"done\\n\\n\";\n get_filesizes_fastq_gz_script += \"# file size script complete\\n\";\n return {\n class:\"File\",\n basename:get_fastq_gz_file_sizes_script_path(),\n contents:get_filesizes_fastq_gz_script\n };\n}\nfunction generate_fastq_ora_md5sum_files_script(fastq_list_rows, input_directory, output_directory) {\n /*\n Generate the fastq ora md5sum files script command, results are printed to stdout\n */\n var get_md5sum_fastq_ora_script = \"#!/usr/bin/env bash\\n\\n\";\n get_md5sum_fastq_ora_script += \"# Exit on failure\\n\";\n get_md5sum_fastq_ora_script += \"set -euo pipefail\\n\\n\";\n /* Initialise the bash array */\n get_md5sum_fastq_ora_script += \"# Get fastq ora paths\\n\";\n get_md5sum_fastq_ora_script += \"FASTQ_ORA_OUTPUT_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_6 = fastq_list_rows; _i < fastq_list_rows_6.length; _i++) {\n var fastq_list_row = fastq_list_rows_6[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n get_md5sum_fastq_ora_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n get_md5sum_fastq_ora_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n get_md5sum_fastq_ora_script += \")\\n\\n\";\n get_md5sum_fastq_ora_script += \"# Generate md5sums for the input fastq ora files\\n\";\n get_md5sum_fastq_ora_script += \"for fastq_ora_output_path in \\\"${FASTQ_ORA_OUTPUT_PATHS[@]}\\\"; do\\n\";\n get_md5sum_fastq_ora_script += \" fastq_ora_scratch_path=\\\"\".concat(output_directory, \"$(basename \\\"${fastq_ora_output_path}\\\")\\\"\\n\");\n get_md5sum_fastq_ora_script += \" md5sum \\\"${fastq_ora_scratch_path}\\\" | sed \\\"s%${fastq_ora_scratch_path}%${fastq_ora_output_path}%\\\"\\n\";\n get_md5sum_fastq_ora_script += \"done\\n\\n\";\n get_md5sum_fastq_ora_script += \"# Md5sum script complete\\n\";\n return {\n class:\"File\",\n basename:get_fastq_ora_md5sum_files_script_path(),\n contents:get_md5sum_fastq_ora_script\n };\n}\nfunction generate_fastq_ora_file_sizes_script(fastq_list_rows, input_directory, output_directory) {\n /*\n Generate the fastq ora file size files script command, results are printed to stdout\n */\n var get_filesizes_fastq_ora_script = \"#!/usr/bin/env bash\\n\\n\";\n get_filesizes_fastq_ora_script += \"# Exit on failure\\n\";\n get_filesizes_fastq_ora_script += \"set -euo pipefail\\n\\n\";\n /* Initialise the bash array */\n get_filesizes_fastq_ora_script += \"# Get fastq ora paths\\n\";\n get_filesizes_fastq_ora_script += \"FASTQ_ORA_OUTPUT_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_7 = fastq_list_rows; _i < fastq_list_rows_7.length; _i++) {\n var fastq_list_row = fastq_list_rows_7[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n get_filesizes_fastq_ora_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n get_filesizes_fastq_ora_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n get_filesizes_fastq_ora_script += \")\\n\\n\";\n get_filesizes_fastq_ora_script += \"# Initialise the tsv header\\n\";\n get_filesizes_fastq_ora_script += \"echo \\\"fastqPath\\tfileSizeInBytes\\\"\\n\\n\";\n get_filesizes_fastq_ora_script += \"# Generate file sizes for the output fastq ora files\\n\";\n get_filesizes_fastq_ora_script += \"for fastq_ora_output_path in \\\"${FASTQ_ORA_OUTPUT_PATHS[@]}\\\"; do\\n\";\n get_filesizes_fastq_ora_script += \" fastq_ora_scratch_path=\\\"\".concat(output_directory, \"$(basename \\\"${fastq_ora_output_path}\\\")\\\"\\n\");\n get_filesizes_fastq_ora_script += \" file_size=\\\"$(wc -c < \\\"${fastq_ora_scratch_path}\\\")\\\"\\n\";\n get_filesizes_fastq_ora_script += \" echo \\\"${fastq_ora_output_path}\\t${file_size}\\\"\\n\";\n get_filesizes_fastq_ora_script += \"done\\n\\n\";\n get_filesizes_fastq_ora_script += \"# ORA script complete\\n\";\n return {\n class:\"File\",\n basename:get_fastq_ora_file_sizes_script_path(),\n contents:get_filesizes_fastq_ora_script\n };\n}\nfunction generate_new_fastq_list_csv_script(fastq_list_rows, input_directory) {\n /*\n Generate the shell script with a list of mv commands to move the output files from the scratch space to their\n original location in the working directory\n */\n var new_fastq_list_csv_script = \"#!/usr/bin/env bash\\n\\n\";\n new_fastq_list_csv_script += \"set -euo pipefail\\n\\n\";\n new_fastq_list_csv_script += \"# Generate a new fastq list csv script\\n\";\n new_fastq_list_csv_script += \"# Initialise header\\n\";\n new_fastq_list_csv_script += \"echo \\\"RGID,RGLB,RGSM,Lane,Read1File,Read2File\\\"\\n\";\n for (var _i = 0, fastq_list_rows_8 = fastq_list_rows; _i < fastq_list_rows_8.length; _i++) {\n var fastq_list_row = fastq_list_rows_8[_i];\n /* Initialise echo line */\n var echo_line = \"echo \\\"\".concat(fastq_list_row.rgid, \",\").concat(fastq_list_row.rglb, \",\").concat(fastq_list_row.rgsm, \",\").concat(fastq_list_row.lane, \",\");\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n echo_line += \"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \",\");\n }\n else {\n echo_line += ',';\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n echo_line += \"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"));\n }\n /* Finish off echo line */\n echo_line += \"\\\"\\n\";\n new_fastq_list_csv_script += echo_line;\n }\n return {\n class:\"File\",\n basename:get_new_fastq_list_csv_script_path(),\n contents:new_fastq_list_csv_script\n };\n}\nfunction find_fastq_files_in_directory_recursively_with_regex(input_dir) {\n var _a;\n /*\n Initialise the output file object\n */\n var read_1_file_list = [];\n var read_2_file_list = [];\n var output_file_objs = [];\n var fastq_file_regex = /\\.fastq\\.gz$/;\n var r1_fastq_file_regex = /_R1_001\\.fastq\\.gz$/;\n var r2_fastq_file_regex = /_R2_001\\.fastq\\.gz$/;\n /*\n Check input_dir is a directory and has a listing\n */\n if (input_dir.class === undefined || input_dir.class !== \"Directory\") {\n throw new Error(\"Could not confirm that the first argument was a directory\");\n }\n if (input_dir.listing === undefined || input_dir.listing === null) {\n throw new Error(\"Could not collect listing from directory \\\"\".concat(input_dir.basename, \"\\\"\"));\n }\n /*\n Collect listing as a variable\n */\n var input_listing = input_dir.listing;\n /*\n Iterate through the file listing\n */\n for (var _i = 0, input_listing_1 = input_listing; _i < input_listing_1.length; _i++) {\n var listing_item = input_listing_1[_i];\n if (listing_item.class === \"File\" && fastq_file_regex.test(listing_item.basename)) {\n /*\n Got the file of interest and the file basename matches the file regex\n */\n /*\n Check if the file is read 1 or read 2\n */\n if (r1_fastq_file_regex.test(listing_item.basename)) {\n read_1_file_list.push(listing_item);\n }\n if (r2_fastq_file_regex.test(listing_item.basename)) {\n read_2_file_list.push(listing_item);\n }\n }\n if (listing_item.class === \"Directory\") {\n var subdirectory_list = listing_item;\n try {\n /* Consider that the file might not be in this subdirectory and that is okay */\n output_file_objs.push.apply(output_file_objs, find_fastq_files_in_directory_recursively_with_regex(subdirectory_list));\n }\n catch (error) {\n /* Dont need to report an error though, just continue */\n }\n }\n }\n /* Iterate over all the read 1 files and try to find a matching read 2 file */\n for (var _b = 0, read_1_file_list_1 = read_1_file_list; _b < read_1_file_list_1.length; _b++) {\n var read_1_file = read_1_file_list_1[_b];\n var read_2_file = undefined;\n for (var _c = 0, read_2_file_list_1 = read_2_file_list; _c < read_2_file_list_1.length; _c++) {\n var read_2_file_candidate = read_2_file_list_1[_c];\n if (((_a = read_1_file.basename) === null || _a === void 0 ? void 0 :_a.replace(\"R1_001.fastq.gz\", \"R2_001.fastq.gz\")) === read_2_file_candidate.basename) {\n read_2_file = read_2_file_candidate;\n break;\n }\n }\n output_file_objs.push({ read1obj:read_1_file, read2obj:read_2_file });\n }\n /* Return the output file object */\n return output_file_objs;\n}\nfunction get_rgsm_value_from_fastq_file_name(fastq_file_name) {\n /* Get the RGID value from the fastq file name */\n var rgid_regex = /(.+?)(?:_S\\d+)?(?:_L00\\d)?_R[12]_001\\.fastq\\.gz$/;\n var rgid_expression = rgid_regex.exec(fastq_file_name);\n if (rgid_expression === null) {\n throw new Error(\"Could not get rgid from \".concat(fastq_file_name));\n }\n return rgid_expression[1];\n}\nfunction get_lane_value_from_fastq_file_name(fastq_file_name) {\n /* Get the lane value from the fastq file name */\n var lane_regex = /(?:.+?)(?:_S\\d+)?_L00(\\d)_R[12]_001\\.fastq\\.gz$/;\n var lane_expression = lane_regex.exec(fastq_file_name);\n if (lane_expression === null) {\n return 1;\n }\n else {\n console.log(lane_expression);\n return parseInt(lane_expression[1]);\n }\n}\nfunction generate_ora_mount_points(input_run, output_directory_path, sample_id_list) {\n /*\n Three main parts\n\n 1. Collect the fastq files\n 2. For each fastq file pair, generate the rgid, rgsm, rglb and lane attributes as necessary to make a fastq list row\n 3. Generate the fastq list csv file\n */\n /* Collect the fastq files */\n var fastq_files_pairs = find_fastq_files_in_directory_recursively_with_regex(input_run);\n /* For each fastq file pair, generate the rgid, rgsm, rglb and lane attributes as necessary */\n var fastq_list_rows = [];\n for (var _i = 0, fastq_files_pairs_1 = fastq_files_pairs; _i < fastq_files_pairs_1.length; _i++) {\n var fastq_files_pair = fastq_files_pairs_1[_i];\n var rgsm_value = get_rgsm_value_from_fastq_file_name(fastq_files_pair.read1obj.basename);\n /* Skip fastq list pair if sample_id_list is defined and the rgsm_value is not in the list */\n if (sample_id_list !== undefined && sample_id_list !== null && sample_id_list !== \"\" && sample_id_list.indexOf(rgsm_value) === -1) {\n continue;\n }\n /* Remove undetermined files from the list of fastqs to process (they are often empty) */\n if (rgsm_value === \"Undetermined\") {\n continue;\n }\n /* Check if we have the size attribute and if so check if it is greater than 0 */\n if (fastq_files_pair.read1obj.size !== null && fastq_files_pair.read1obj.size !== undefined && fastq_files_pair.read1obj.size == 0) {\n continue;\n }\n /* Repeat the condition for read 2 although also ensure that read 2 is also actually defined */\n if (fastq_files_pair.read2obj !== undefined && fastq_files_pair.read2obj !== null) {\n if (fastq_files_pair.read2obj.size !== null && fastq_files_pair.read2obj.size !== undefined && fastq_files_pair.read2obj.size == 0) {\n continue;\n }\n }\n var lane_value = get_lane_value_from_fastq_file_name(fastq_files_pair.read1obj.basename);\n var fastq_list_row = {\n rgid:lane_value.toString() + '.' + rgsm_value,\n rgsm:rgsm_value,\n rglb:\"UnknownLibrary\",\n lane:lane_value,\n read_1:fastq_files_pair.read1obj,\n read_2:fastq_files_pair.read2obj\n };\n fastq_list_rows.push(fastq_list_row);\n }\n /* Initialise dirent */\n var e = [];\n /* Generate the fastq list csv file */\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(fastq_list_rows)\n });\n /* Generate the script to then move the files from the scratch space to the working directory */\n e.push({\n \"entryname\":get_ora_mv_files_script_path(),\n \"entry\":generate_ora_mv_files_script(fastq_list_rows, input_run, output_directory_path)\n });\n /* Generate the script to generate the new output fastq list csv */\n e.push({\n \"entryname\":get_new_fastq_list_csv_script_path(),\n \"entry\":generate_new_fastq_list_csv_script(fastq_list_rows, input_run)\n });\n /* Generate the script to generate the md5sums of the input gzipped fastq files */\n e.push({\n \"entryname\":get_fastq_gz_md5sum_files_script_path(),\n \"entry\":generate_fastq_gz_md5sum_files_script(fastq_list_rows, input_run)\n });\n /* Generate the script to generate the filesizes of the input gzipped fastq files */\n e.push({\n \"entryname\":get_fastq_gz_file_sizes_script_path(),\n \"entry\":generate_fastq_gz_file_sizes_script(fastq_list_rows, input_run)\n });\n /* Generate the script to generate the md5sums of the output ora fastq files */\n e.push({\n \"entryname\":get_fastq_ora_md5sum_files_script_path(),\n \"entry\":generate_fastq_ora_md5sum_files_script(fastq_list_rows, input_run, get_ora_intermediate_output_dir())\n });\n /* Generate the script to generate the filesizes of the output ora fastq files */\n e.push({\n \"entryname\":get_fastq_ora_file_sizes_script_path(),\n \"entry\":generate_fastq_ora_file_sizes_script(fastq_list_rows, input_run, get_ora_intermediate_output_dir())\n });\n /* Return the dirent */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\n", + "/* Author:Alexis Lucattini */\n/* For assistance on generation of typescript expressions */\n/* In CWL, please visit our wiki page at https://github.com/umccr/cwl-ica/wiki/TypeScript */\n/* Imports */\n/* Functions */\nfunction get_script_path() {\n /*\n Abstract script path, can then be referenced in baseCommand attribute too\n Makes things more readable.\n */\n return \"run-dragen-script.sh\";\n}\nfunction get_scratch_mount() {\n /*\n Return the path of the scratch directory space\n */\n return \"/scratch/\";\n}\nfunction get_intermediate_results_dir() {\n /*\n Get intermediate results directory as /scratch for dragen runs\n */\n return get_scratch_mount() + \"intermediate-results/\";\n}\nfunction get_name_root_from_tarball(basename) {\n var tar_ball_regex = /(\\S+)\\.tar\\.gz/g;\n var tar_ball_expression = tar_ball_regex.exec(basename);\n if (tar_ball_expression === null) {\n throw new Error(\"Could not get nameroot from \".concat(basename));\n }\n return tar_ball_expression[1];\n}\nfunction get_ref_path(reference_input_obj) {\n /*\n Get the reference path\n */\n return get_ref_mount() + get_name_root_from_tarball(reference_input_obj.basename) + \"/\";\n}\nfunction get_ref_mount() {\n /*\n Get the reference mount point\n */\n return get_scratch_mount() + \"ref/\";\n}\nfunction get_dragen_bin_path() {\n /*\n Get dragen bin path\n */\n return \"/opt/edico/bin/dragen\";\n}\nfunction get_dragen_eval_line() {\n /*\n Return string\n */\n return \"eval \\\"\" + get_dragen_bin_path() + \"\\\" '\\\"\\$@\\\"' \\n\";\n}\nfunction get_fastq_list_csv_path() {\n /*\n The fastq list path must be placed in working directory\n */\n return \"fastq_list.csv\";\n}\nfunction get_tumor_fastq_list_csv_path() {\n /*\n The tumor fastq list path must be placed in working directory\n */\n return \"tumor_fastq_list.csv\";\n}\nfunction get_ora_mv_files_script_path() {\n /*\n Get the ora mv files script path\n */\n return \"mv-ora-output-files.sh\";\n}\nfunction get_new_fastq_list_csv_script_path() {\n /*\n Get the new fastq list csv script path\n */\n return \"generate-new-fastq-list-csv.sh\";\n}\nfunction get_fastq_raw_md5sum_files_script_path() {\n /*\n Get the script path to generating the md5sum for each fastq gzip file\n */\n return \"generate-md5sum-for-fastq-raw-files.sh\";\n}\nfunction get_fastq_gz_file_sizes_script_path() {\n /*\n Get the script path to generating the filesizes for each fastq gzip file\n */\n return \"generate-file-sizes-for-fastq-gz-files.sh\";\n}\nfunction get_fastq_ora_md5sum_files_script_path() {\n /*\n Get the script path for generating the md5sum for each fastq ora file\n */\n return \"generate-md5sum-for-fastq-ora-files.sh\";\n}\nfunction get_fastq_ora_file_sizes_script_path() {\n /*\n Get the script path to generating the filesizes for each fastq gzip file\n */\n return \"generate-file-sizes-for-fastq-ora-files.sh\";\n}\nfunction get_normal_name_from_fastq_list_rows(fastq_list_rows) {\n /*\n Get the normal sample name from the fastq list rows object\n */\n /*\n Check fastq list rows is defined\n */\n if (fastq_list_rows === undefined || fastq_list_rows === null) {\n return null;\n }\n /*\n Get RGSM value and return\n */\n return fastq_list_rows[0].rgsm;\n}\nfunction get_normal_name_from_fastq_list_csv(fastq_list_csv) {\n /*\n Get the normal name from the fastq list csv...\n */\n /*\n Check file is defined\n */\n if (fastq_list_csv === undefined || fastq_list_csv === null) {\n return null;\n }\n /*\n Check contents are defined\n */\n if (fastq_list_csv.contents === null || fastq_list_csv.contents === undefined) {\n return null;\n }\n /*\n Confirm fastq list csv is of type File\n */\n if (fastq_list_csv.class !== \"File\") {\n throw new Error(\"Could not confirm input fastq_list_csv is of type File\");\n }\n /*\n Split contents by line\n */\n var contents_by_line = [];\n fastq_list_csv.contents.split(\"\\n\").forEach(function (line_content) {\n var stripped_line_content = line_content.replace(/(\\r\\n|\\n|\\r)/gm, \"\");\n if (stripped_line_content !== \"\") {\n contents_by_line.push(stripped_line_content);\n }\n });\n var column_names = contents_by_line[0].split(\",\");\n /*\n Get RGSM index value (which column is RGSM at?)\n */\n var rgsm_index = column_names.indexOf(\"RGSM\");\n /*\n RGSM is not in index. Return null\n */\n if (rgsm_index === -1) {\n return null;\n }\n /*\n Get RGSM value of first row and return\n */\n return contents_by_line[1].split(\",\")[rgsm_index];\n}\nfunction get_normal_output_prefix(inputs) {\n var _a, _b;\n /*\n Get the normal RGSM value and then add _normal to it\n */\n var normal_name = null;\n var normal_re_replacement = /_normal$/;\n /*\n Check if bam_input is set\n */\n if (inputs.bam_input !== null && inputs.bam_input !== undefined) {\n /* Remove _normal from nameroot if it already exists */\n /* We dont want _normal_normal as a suffix */\n return \"\".concat((_a = inputs.bam_input.nameroot) === null || _a === void 0 ? void 0 :_a.replace(normal_re_replacement, \"\"), \"_normal\");\n }\n /*\n Check if cram_input is set\n */\n if (inputs.cram_input !== null && inputs.cram_input !== undefined) {\n /* Remove _normal from nameroot if it already exists */\n /* We dont want _normal_normal as a suffix */\n return \"\".concat((_b = inputs.cram_input.nameroot) === null || _b === void 0 ? void 0 :_b.replace(normal_re_replacement, \"\"), \"_normal\");\n }\n /*\n Check if fastq list file is set\n */\n if (inputs.fastq_list !== null && inputs.fastq_list !== undefined) {\n normal_name = get_normal_name_from_fastq_list_csv(inputs.fastq_list);\n if (normal_name !== null) {\n return \"\".concat(normal_name, \"_normal\");\n }\n }\n /*\n Otherwise collect and return from schema object\n */\n normal_name = get_normal_name_from_fastq_list_rows(inputs.fastq_list_rows);\n return \"\".concat(normal_name, \"_normal\");\n}\nfunction build_fastq_list_csv_header(header_names) {\n /*\n Convert lowercase labels to uppercase values\n i.e\n [ \"rgid\", \"rglb\", \"rgsm\", \"lane\", \"read_1\", \"read_2\" ]\n to\n \"RGID,RGLB,RGSM,Lane,Read1File,Read2File\"\n */\n var modified_header_names = [];\n for (var _i = 0, header_names_1 = header_names; _i < header_names_1.length; _i++) {\n var header_name = header_names_1[_i];\n if (header_name.indexOf(\"rg\") === 0) {\n /*\n rgid -> RGID\n */\n modified_header_names.push(header_name.toUpperCase());\n }\n else if (header_name.indexOf(\"read\") === 0) {\n /*\n read_1 -> Read1File\n */\n modified_header_names.push(\"Read\" + header_name.charAt(header_name.length - 1) + \"File\");\n }\n else {\n /*\n lane to Lane\n */\n modified_header_names.push(header_name[0].toUpperCase() + header_name.substr(1));\n }\n }\n /*\n Convert array to comma separated strings\n */\n return modified_header_names.join(\",\") + \"\\n\";\n}\nfunction get_fastq_list_row_as_csv_row(fastq_list_row, row_order) {\n var fastq_list_row_values_array = [];\n /* This for loop is here to ensure were assigning values in the same order as the header */\n for (var _i = 0, row_order_1 = row_order; _i < row_order_1.length; _i++) {\n var item_index = row_order_1[_i];\n var found_item = false;\n /* Find matching attribute in this row */\n for (var _a = 0, _b = Object.getOwnPropertyNames(fastq_list_row); _a < _b.length; _a++) {\n var fastq_list_row_field_name = _b[_a];\n var fastq_list_row_field_value = fastq_list_row[fastq_list_row_field_name];\n if (fastq_list_row_field_value === null) {\n /*\n Item not found, add an empty attribute for this cell in the csv\n */\n continue;\n }\n /* The header value matches the name in the item */\n if (fastq_list_row_field_name === item_index) {\n /*\n If the field value has a class attribute then it's either read_1 or read_2\n */\n if (fastq_list_row_field_value.hasOwnProperty(\"class\")) {\n var fastq_list_row_field_value_file = fastq_list_row_field_value;\n /*\n Assert that this is actually of class file\n */\n if (fastq_list_row_field_value_file.class !== \"File\") {\n continue;\n }\n if (fastq_list_row_field_value_file.path !== null && fastq_list_row_field_value_file.path !== undefined) {\n /*\n Push the path attribute to the fastq list csv row if it is not null\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value_file.path);\n }\n else {\n /*\n Otherwise push the location attribute\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value_file.location);\n }\n }\n else {\n /*\n Push the string attribute to the fastq list csv row\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value.toString());\n }\n found_item = true;\n break;\n }\n }\n if (!found_item) {\n /*\n Push blank cell if no item found\n */\n fastq_list_row_values_array.push(\"\");\n }\n }\n /*\n Convert to string and return as string\n */\n return fastq_list_row_values_array.join(\",\") + \"\\n\";\n}\nfunction generate_fastq_list_csv(fastq_list_rows) {\n /*\n Fastq list rows generation\n */\n var fastq_csv_file = {\n class:\"File\",\n basename:get_fastq_list_csv_path()\n };\n /*\n Set the row order\n */\n var row_order = [];\n /*\n Set the array order\n Make sure we iterate through all rows of the array\n */\n for (var _i = 0, fastq_list_rows_1 = fastq_list_rows; _i < fastq_list_rows_1.length; _i++) {\n var fastq_list_row = fastq_list_rows_1[_i];\n for (var _a = 0, _b = Object.getOwnPropertyNames(fastq_list_row); _a < _b.length; _a++) {\n var fastq_list_row_field_name = _b[_a];\n if (row_order.indexOf(fastq_list_row_field_name) === -1) {\n row_order.push(fastq_list_row_field_name);\n }\n }\n }\n /*\n Make header\n */\n fastq_csv_file.contents = build_fastq_list_csv_header(row_order);\n /*\n For each fastq list row,\n collect the values of each attribute but in the order of the header\n */\n for (var _c = 0, fastq_list_rows_2 = fastq_list_rows; _c < fastq_list_rows_2.length; _c++) {\n var fastq_list_row = fastq_list_rows_2[_c];\n /* Add csv row to file contents */\n fastq_csv_file.contents += get_fastq_list_row_as_csv_row(fastq_list_row, row_order);\n }\n return fastq_csv_file;\n}\nfunction generate_germline_mount_points(inputs) {\n /*\n Create and add in the fastq list csv for the input fastqs\n */\n var e = [];\n if (inputs.fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.fastq_list_rows)\n });\n }\n if (inputs.fastq_list !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":inputs.fastq_list\n });\n }\n /*\n Return file paths\n */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\nfunction generate_somatic_mount_points(inputs) {\n /*\n Create and add in the fastq list csv for the input fastqs\n */\n var e = [];\n if (inputs.fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.fastq_list_rows)\n });\n }\n if (inputs.tumor_fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_tumor_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.tumor_fastq_list_rows)\n });\n }\n if (inputs.fastq_list !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":inputs.fastq_list\n });\n }\n if (inputs.tumor_fastq_list !== null) {\n e.push({\n \"entryname\":get_tumor_fastq_list_csv_path(),\n \"entry\":inputs.tumor_fastq_list\n });\n }\n /*\n Return file paths\n */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\nfunction generate_transcriptome_mount_points(inputs) {\n /*\n Calls another function that generates mount points\n */\n return generate_germline_mount_points(inputs);\n}\n/* Custom functions for dragen reference tarball build */\nfunction get_liftover_dir() {\n /* Hardcoded liftover directory in dragen 4.2 */\n return \"/opt/edico/liftover/\";\n}\nfunction get_mask_dir() {\n /* Hardcoded mask directory in dragen 4.2 */\n return \"/opt/edico/fasta_mask/\";\n}\nfunction get_ref_scratch_dir(reference_name) {\n /* We get the reference scratch directory as a combination of */\n /* the dragen scratch mount and the reference name */\n return get_scratch_mount() + reference_name + \"/\";\n}\nfunction get_ora_intermediate_output_dir() {\n return get_scratch_mount() + \"ora-outputs/\";\n}\nfunction generate_ora_mv_files_script(fastq_list_rows, input_directory, output_directory) {\n /*\n Generate the shell script with a list of echo commands to write a new fastq list csv to stdout, however\n the fastq list csv contains the ora files as outputs instead\n */\n var ora_mv_files_script = \"#!/usr/bin/env bash\\n\\n\";\n ora_mv_files_script += \"# Exit on failure\\n\";\n ora_mv_files_script += \"set -euo pipefail\\n\\n\";\n ora_mv_files_script += \"# Get fastq ora paths\\n\";\n ora_mv_files_script += \"FASTQ_ORA_OUTPUT_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_3 = fastq_list_rows; _i < fastq_list_rows_3.length; _i++) {\n var fastq_list_row = fastq_list_rows_3[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n ora_mv_files_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n /* Add relative path of read 2 */\n ora_mv_files_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n ora_mv_files_script += \")\\n\\n\";\n ora_mv_files_script += \"# Move all ora files to the final output directory\\n\";\n ora_mv_files_script += \"xargs \\\\\\n\";\n ora_mv_files_script += \" --max-args=1 \\\\\\n\";\n ora_mv_files_script += \" --max-procs=16 \\\\\\n\";\n ora_mv_files_script += \" bash -c \\\\\\n\";\n ora_mv_files_script += \" '\\n\";\n ora_mv_files_script += \" fastq_ora_scratch_path=\\\"\".concat(get_ora_intermediate_output_dir(), \"$(basename \\\"$@\\\")\\\"\\n\");\n ora_mv_files_script += \" mkdir -p \\\"$(dirname \\\"\".concat(output_directory, \"/$@\\\")\\\"\\n\");\n ora_mv_files_script += \" rsync \\\\\\n\";\n ora_mv_files_script += \" --archive \\\\\\n\";\n ora_mv_files_script += \" --remove-source-files \\\\\\n\";\n ora_mv_files_script += \" --include \\\"$(basename \\\"$@\\\")\\\" \\\\\\n\";\n ora_mv_files_script += \" --exclude \\\"*\\\" \\\\\\n\";\n ora_mv_files_script += \" \\\"$(dirname \\\"${fastq_ora_scratch_path}\\\")/\\\" \\\\\\n\";\n ora_mv_files_script += \" \\\"$(dirname \\\"\".concat(output_directory, \"/$@\\\")/\\\"\\n\");\n ora_mv_files_script += \" ' \\\\\\n\";\n ora_mv_files_script += \" _ \\\\\\n\";\n ora_mv_files_script += \" <<< \\\"${FASTQ_ORA_OUTPUT_PATHS[@]}\\\"\\n\\n\";\n ora_mv_files_script += \"# Transfer all other files\\n\";\n ora_mv_files_script += \"mkdir -p \\\"\".concat(output_directory, \"/ora-logs/\\\"\\n\");\n ora_mv_files_script += \"mv \\\"\".concat(get_ora_intermediate_output_dir(), \"\\\" \\\"\").concat(output_directory, \"/ora-logs/compression/\\\"\\n\");\n return {\n class:\"File\",\n basename:get_ora_mv_files_script_path(),\n contents:ora_mv_files_script\n };\n}\nfunction generate_new_fastq_list_csv_script(fastq_list_rows, input_directory) {\n /*\n Generate the shell script with a list of mv commands to move the output files from the scratch space to their\n original location in the working directory\n */\n var new_fastq_list_csv_script = \"#!/usr/bin/env bash\\n\\n\";\n new_fastq_list_csv_script += \"set -euo pipefail\\n\\n\";\n new_fastq_list_csv_script += \"# Generate a new fastq list csv script\\n\";\n new_fastq_list_csv_script += \"# Initialise header\\n\";\n new_fastq_list_csv_script += \"echo \\\"RGID,RGLB,RGSM,Lane,Read1File,Read2File\\\"\\n\";\n for (var _i = 0, fastq_list_rows_4 = fastq_list_rows; _i < fastq_list_rows_4.length; _i++) {\n var fastq_list_row = fastq_list_rows_4[_i];\n /* Initialise echo line */\n var echo_line = \"echo \\\"\".concat(fastq_list_row.rgid, \",\").concat(fastq_list_row.rglb, \",\").concat(fastq_list_row.rgsm, \",\").concat(fastq_list_row.lane, \",\");\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n echo_line += \"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \",\");\n }\n else {\n echo_line += ',';\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n echo_line += \"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"));\n }\n /* Finish off echo line */\n echo_line += \"\\\"\\n\";\n new_fastq_list_csv_script += echo_line;\n }\n return {\n class:\"File\",\n basename:get_new_fastq_list_csv_script_path(),\n contents:new_fastq_list_csv_script\n };\n}\nfunction find_fastq_files_in_directory_recursively_with_regex(input_dir) {\n var _a;\n /*\n Initialise the output file object\n */\n var read_1_file_list = [];\n var read_2_file_list = [];\n var output_file_objs = [];\n var fastq_file_regex = /\\.fastq\\.gz$/;\n var r1_fastq_file_regex = /_R1_001\\.fastq\\.gz$/;\n var r2_fastq_file_regex = /_R2_001\\.fastq\\.gz$/;\n /*\n Check input_dir is a directory and has a listing\n */\n if (input_dir.class === undefined || input_dir.class !== \"Directory\") {\n throw new Error(\"Could not confirm that the first argument was a directory\");\n }\n if (input_dir.listing === undefined || input_dir.listing === null) {\n throw new Error(\"Could not collect listing from directory \\\"\".concat(input_dir.basename, \"\\\"\"));\n }\n /*\n Collect listing as a variable\n */\n var input_listing = input_dir.listing;\n /*\n Iterate through the file listing\n */\n for (var _i = 0, input_listing_1 = input_listing; _i < input_listing_1.length; _i++) {\n var listing_item = input_listing_1[_i];\n if (listing_item.class === \"File\" && fastq_file_regex.test(listing_item.basename)) {\n /*\n Got the file of interest and the file basename matches the file regex\n */\n /*\n Check if the file is read 1 or read 2\n */\n if (r1_fastq_file_regex.test(listing_item.basename)) {\n read_1_file_list.push(listing_item);\n }\n if (r2_fastq_file_regex.test(listing_item.basename)) {\n read_2_file_list.push(listing_item);\n }\n }\n if (listing_item.class === \"Directory\") {\n var subdirectory_list = listing_item;\n try {\n /* Consider that the file might not be in this subdirectory and that is okay */\n output_file_objs.push.apply(output_file_objs, find_fastq_files_in_directory_recursively_with_regex(subdirectory_list));\n }\n catch (error) {\n /* Dont need to report an error though, just continue */\n }\n }\n }\n /* Iterate over all the read 1 files and try to find a matching read 2 file */\n for (var _b = 0, read_1_file_list_1 = read_1_file_list; _b < read_1_file_list_1.length; _b++) {\n var read_1_file = read_1_file_list_1[_b];\n var read_2_file = undefined;\n for (var _c = 0, read_2_file_list_1 = read_2_file_list; _c < read_2_file_list_1.length; _c++) {\n var read_2_file_candidate = read_2_file_list_1[_c];\n if (((_a = read_1_file.basename) === null || _a === void 0 ? void 0 :_a.replace(\"R1_001.fastq.gz\", \"R2_001.fastq.gz\")) === read_2_file_candidate.basename) {\n read_2_file = read_2_file_candidate;\n break;\n }\n }\n output_file_objs.push({ read1obj:read_1_file, read2obj:read_2_file });\n }\n /* Return the output file object */\n return output_file_objs;\n}\nfunction get_rgsm_value_from_fastq_file_name(fastq_file_name) {\n /* Get the RGID value from the fastq file name */\n var rgid_regex = /(.+?)(?:_S\\d+)?(?:_L00\\d)?_R[12]_001\\.fastq\\.gz$/;\n var rgid_expression = rgid_regex.exec(fastq_file_name);\n if (rgid_expression === null) {\n throw new Error(\"Could not get rgid from \".concat(fastq_file_name));\n }\n return rgid_expression[1];\n}\nfunction get_lane_value_from_fastq_file_name(fastq_file_name) {\n /* Get the lane value from the fastq file name */\n var lane_regex = /(?:.+?)(?:_S\\d+)?_L00(\\d)_R[12]_001\\.fastq\\.gz$/;\n var lane_expression = lane_regex.exec(fastq_file_name);\n if (lane_expression === null) {\n return 1;\n }\n else {\n console.log(lane_expression);\n return parseInt(lane_expression[1]);\n }\n}\nfunction generate_ora_mount_points(input_run, output_directory_path, sample_id_list) {\n /*\n Three main parts\n\n 1. Collect the fastq files\n 2. For each fastq file pair, generate the rgid, rgsm, rglb and lane attributes as necessary to make a fastq list row\n 3. Generate the fastq list csv file\n */\n /* Collect the fastq files */\n var fastq_files_pairs = find_fastq_files_in_directory_recursively_with_regex(input_run);\n /* For each fastq file pair, generate the rgid, rgsm, rglb and lane attributes as necessary */\n var fastq_list_rows = [];\n for (var _i = 0, fastq_files_pairs_1 = fastq_files_pairs; _i < fastq_files_pairs_1.length; _i++) {\n var fastq_files_pair = fastq_files_pairs_1[_i];\n var rgsm_value = get_rgsm_value_from_fastq_file_name(fastq_files_pair.read1obj.basename);\n /* Skip fastq list pair if sample_id_list is defined and the rgsm_value is not in the list */\n if (sample_id_list !== undefined && sample_id_list !== null && sample_id_list !== \"\" && sample_id_list.indexOf(rgsm_value) === -1) {\n continue;\n }\n /* Remove undetermined files from the list of fastqs to process (they are often empty) */\n if (rgsm_value === \"Undetermined\") {\n continue;\n }\n /* Check if we have the size attribute and if so check if it is greater than 0 */\n if (fastq_files_pair.read1obj.size !== null && fastq_files_pair.read1obj.size !== undefined && fastq_files_pair.read1obj.size == 0) {\n continue;\n }\n /* Repeat the condition for read 2 although also ensure that read 2 is also actually defined */\n if (fastq_files_pair.read2obj !== undefined && fastq_files_pair.read2obj !== null) {\n if (fastq_files_pair.read2obj.size !== null && fastq_files_pair.read2obj.size !== undefined && fastq_files_pair.read2obj.size == 0) {\n continue;\n }\n }\n var lane_value = get_lane_value_from_fastq_file_name(fastq_files_pair.read1obj.basename);\n var fastq_list_row = {\n rgid:lane_value.toString() + '.' + rgsm_value,\n rgsm:rgsm_value,\n rglb:\"UnknownLibrary\",\n lane:lane_value,\n read_1:fastq_files_pair.read1obj,\n read_2:fastq_files_pair.read2obj\n };\n fastq_list_rows.push(fastq_list_row);\n }\n /* Initialise dirent */\n var e = [];\n /* Generate the fastq list csv file */\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(fastq_list_rows)\n });\n /* Generate the script to then move the files from the scratch space to the working directory */\n e.push({\n \"entryname\":get_ora_mv_files_script_path(),\n \"entry\":generate_ora_mv_files_script(fastq_list_rows, input_run, output_directory_path)\n });\n /* Generate the script to generate the new output fastq list csv */\n e.push({\n \"entryname\":get_new_fastq_list_csv_script_path(),\n \"entry\":generate_new_fastq_list_csv_script(fastq_list_rows, input_run)\n });\n /* Return the dirent */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\n", "/* Author:Alexis Lucattini */\n/* For assistance on generation of typescript expressions */\n/* In CWL, please visit our wiki page at https://github.com/umccr/cwl-ica/wiki/TypeScript */\n/* Imports */\n/* Functions */\nfunction is_not_null(input_obj) {\n /*\n Determine if input object is defined and is not null\n */\n return !(input_obj === null || input_obj === undefined);\n}\nfunction get_attribute_from_optional_input(input_object, attribute) {\n /*\n Get attribute from optional input -\n If input is not defined, then return null\n */\n if (input_object === null || input_object === undefined) {\n return null;\n }\n else {\n return get_optional_attribute_from_object(input_object, attribute);\n }\n}\nfunction get_optional_attribute_from_object(input_object, attribute) {\n /*\n Get attribute from object, if attribute is not defined return null\n Assume the input object is an object of key value pairs where we know the key is of type string\n stackoverflow.com/questions/56833469/typescript-error-ts7053-element-implicitly-has-an-any-type\n */\n if (input_object.hasOwnProperty(attribute)) {\n return input_object[attribute];\n }\n else {\n return null;\n }\n}\nfunction get_bool_value_as_str(input_bool) {\n if (is_not_null(input_bool) && input_bool) {\n return \"true\";\n }\n else {\n return \"false\";\n }\n}\nfunction boolean_to_int(input_bool) {\n if (is_not_null(input_bool) && String(input_bool).toLowerCase() === \"true\") {\n return 1;\n }\n else {\n return 0;\n }\n}\nfunction get_optional_attribute_from_multi_type_input_object(object, attribute) {\n /*\n Get attribute from optional input\n */\n if (object === null || object === undefined) {\n return null;\n }\n else if (typeof object === \"object\") {\n /* Get attribute from optional input */\n return get_attribute_from_optional_input(object, attribute);\n }\n else {\n /* Object is likely actually a str */\n return object;\n }\n}\nfunction get_source_a_or_b(input_a, input_b) {\n /*\n Get the first input parameter if it is not null\n Otherwise return the second parameter\n Otherwise return null\n */\n if (is_not_null(input_a)) {\n return input_a;\n }\n else if (is_not_null(input_b)) {\n return input_b;\n }\n else {\n return null;\n }\n}\nfunction get_first_non_null_input(inputs) {\n /*\n Get first element of the array that is not null\n */\n for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {\n var input_element = inputs_1[_i];\n if (is_not_null(input_element)) {\n return input_element;\n }\n }\n return null;\n}\nfunction get_attribute_list_from_object_list(obj_list, attribute) {\n /*\n Get attribute from list of objects\n If an object is null, it is not included in the return list\n */\n return obj_list.filter(function (x) { return x !== null; }).map(function (x) { return get_optional_attribute_from_object(x, attribute); });\n}\nfunction get_str_list_as_bash_array(input_list, item_wrap) {\n /*\n Convert a list of strings to a bash array, if the list is not defined return null\n */\n if (input_list === null) {\n return null;\n }\n if (item_wrap === null) {\n return \"( \".concat(input_list.map(function (x) { return \"'\".concat(item_wrap).concat(x).concat(item_wrap, \"'\"); }).join(' '), \" )\");\n }\n return \"( \".concat(input_list.map(function (x) { return \"'\".concat(x, \"'\"); }).join(' '), \" )\");\n}\nfunction get_object_attribute_list_as_bash_array(obj_list, attribute) {\n /*\n Get attribute from list of objects and convert to a bash array\n Do not include null values in the array\n */\n return get_str_list_as_bash_array(get_attribute_list_from_object_list(obj_list, attribute).filter(function (x) { return x !== null; }));\n}\n" ], "class": "InlineJavascriptRequirement" @@ -1273,7 +1273,7 @@ "listing": [ { "entryname": "$(get_script_path())", - "entry": "#!/usr/bin/env bash\n\n# Fail on non-zero exit of subshell\nset -euo pipefail\n\n# Confirm not more than one of fastq_list, fastq_list_rows, bam_input and cram_input are defined\nif [[ \"$(boolean_to_int(is_not_null(inputs.fastq_list)) + boolean_to_int(is_not_null(inputs.fastq_list_rows)) + boolean_to_int(is_not_null(inputs.bam_input)) + boolean_to_int(is_not_null(inputs.cram_input)))\" -gt \"1\" ]]; then\n echo \"Please set no more than one of fastq_list, fastq_list_rows, bam_input or cram_input for normal sample\" 1>&2\n exit 1\nfi\n\n# Ensure that at least one (and only one) of tumor_fastq_list, tumor_fastq_list_rows, tumor_bam_input and tumor_cram_input are defined but not both defined (XOR)\nif [[ \"$(boolean_to_int(is_not_null(inputs.tumor_fastq_list)) + boolean_to_int(is_not_null(inputs.tumor_fastq_list_rows)) + boolean_to_int(is_not_null(inputs.tumor_bam_input)) + boolean_to_int(is_not_null(inputs.tumor_cram_input)))\" -ne \"1\" ]]; then\n echo \"One and only one of inputs tumor_fastq_list, tumor_fastq_list_rows, tumor_bam_input, tumor_cram_input must be defined\" 1>&2\n exit 1\nfi\n\n# Reset dragen\n/opt/edico/bin/dragen \\\\\n --partial-reconfig HMM \\\\\n --ignore-version-check true\n\n# Create directories\nmkdir --parents \\\\\n \"$(get_ref_mount())\" \\\\\n \"$(get_intermediate_results_dir())\" \\\\\n \"$(inputs.output_directory)\"\n\n# untar ref data into scratch space\ntar \\\\\n --directory \"$(get_ref_mount())\" \\\\\n --extract \\\\\n --file \"$(inputs.reference_tar.path)\"\n\n# Check if ora reference is set\nif [[ \"$(is_not_null(inputs.ora_reference_tar))\" == \"true\" ]]; then\n tar \\\\\n --directory \"$(get_ref_mount())\" \\\\\n --extract \\\\\n --file \"$(inputs.ora_reference_tar.path)\"\nfi\n\n# Check if both bam inputs are set\nif [[ \"$(is_not_null(inputs.bam_input))\" == \"true\" && \"$(is_not_null(inputs.tumor_bam_input))\" == \"true\" && ( \"$(get_bool_value_as_str(inputs.enable_map_align))\" == \"true\" || \"$(get_bool_value_as_str(inputs.enable_map_align_output))\" == \"true\" ) ]]; then\n echo \"More than one bam input is set, need to run enable map align first beforehand then run variant calling in a separate step\" 1>&2\n\n # Collect options relating to map alignment (these options will be popped from the args list and not used in the variant calling step)\n enable_sort_parameter=\"\"\n enable_duplicate_marking_parameter=\"\"\n dedup_min_qual_parameter=\"\"\n\n # Pop arguments\n # Get args from command line\n # But capture them again since we need them when we actually run dragen\n existing_args_array=()\n while [ $# -gt 0 ]; do\n case \"$1\" in\n --enable-sort=*)\n enable_sort_parameter=\"$1\"\n ;;\n --enable-duplicate-marking=*)\n enable_duplicate_marking_parameter=\"\\${1}\"\n ;;\n --enable-map-align=*)\n : # Just popping from array, we set this by default in these steps but dont want it in final dragen call\n ;;\n --enable-map-align-output=*)\n : # Just popping from array, we set this by default in these steps but dont want it in final dragen call\n ;;\n --dedup-min-qual=*)\n dedup_min_qual_parameter=\"\\${1}\"\n ;;\n --bam-input=*)\n : # Just popping from array as we set the new location elsewhere\n ;;\n --tumor-bam-input=*)\n : # Just popping from array as we set the new location elsewhere\n ;;\n *)\n existing_args_array+=(\"\\${1}\")\n esac\n shift 1\n done\n\n # Then run dragen map-align and place the files in the output directories\n # Tumor Then Normal\n echo \"Aligning tumor\" 1>&2\n # Eval prefix required here as some parameters are empty\n eval /opt/edico/bin/dragen \\\\\n --enable-map-align=true \\\\\n --enable-map-align-output=true \\\\\n \"\\${enable_sort_parameter}\" \\\\\n \"\\${enable_duplicate_marking_parameter}\" \\\\\n \"\\${dedup_min_qual_parameter}\" \\\\\n \"--ref-dir=$(get_ref_path(inputs.reference_tar))\" \\\\\n \"--output-directory=$(inputs.output_directory)\" \\\\\n \"--output-file-prefix=$(inputs.output_file_prefix)\" \\\\\n \"--intermediate-results-dir=$(get_intermediate_results_dir())\" \\\\\n \"--lic-instance-id-location=$(get_optional_attribute_from_multi_type_input_object(inputs.lic_instance_id_location, \"path\"))\" \\\\\n \"--tumor-bam-input=$(get_attribute_from_optional_input(inputs.tumor_bam_input, \"path\"))\"\n\n echo \"Aligning normal\" 1>&2\n # Eval prefix required here as some parameters are empty\n eval /opt/edico/bin/dragen \\\\\n --enable-map-align=true \\\\\n --enable-map-align-output=true \\\\\n \"\\${enable_sort_parameter}\" \\\\\n \"\\${enable_duplicate_marking_parameter}\" \\\\\n \"\\${dedup_min_qual_parameter}\" \\\\\n \"--ref-dir=$(get_ref_path(inputs.reference_tar))\" \\\\\n \"--output-directory=$(inputs.output_directory)\" \\\\\n \"--output-file-prefix=$(inputs.output_file_prefix)\" \\\\\n \"--intermediate-results-dir=$(get_intermediate_results_dir())\" \\\\\n \"--lic-instance-id-location=$(get_optional_attribute_from_multi_type_input_object(inputs.lic_instance_id_location, \"path\"))\" \\\\\n \"--bam-input=$(get_attribute_from_optional_input(inputs.bam_input, \"path\"))\"\n\n # Pop back in existing arguments into \\${@}\n for existing_arg in \"\\${existing_args_array[@]}\"; do\n set -- \"\\${@}\" \"\\${existing_arg}\"\n done\n\n # Update bam input and tumor bam input parameters\n set -- \"\\${@}\" \"--bam-input=$(inputs.output_directory)/$(inputs.output_file_prefix).bam\"\n set -- \"\\${@}\" \"--tumor-bam-input=$(inputs.output_directory)/$(inputs.output_file_prefix)_tumor.bam\"\n\n # Explicity set enable map align to false\n # Setting --enable-map-align to false, sets --enable-map-align-output to false as well\n set -- \"\\${@}\" \"--enable-map-align=false\"\nfi\n\n# Check if cram inputs are set and enable map align output is set\n# Like bam inputs, we need to run map align first before running variant calling\nif [[ \"$(is_not_null(inputs.cram_input))\" == \"true\" && \"$(is_not_null(inputs.tumor_cram_input))\" == \"true\" && ( \"$(get_bool_value_as_str(inputs.enable_map_align))\" == \"true\" || \"$(get_bool_value_as_str(inputs.enable_map_align_output))\" == \"true\" ) ]]; then\n echo \"More than one cram input is set, need to run enable map align first beforehand then run variant calling in a separate step\" 1>&2\n\n # Collect options relating to map alignment (these options will be popped from the args list and not used in the variant calling step)\n enable_sort_parameter=\"\"\n enable_duplicate_marking_parameter=\"\"\n dedup_min_qual_parameter=\"\"\n cram_reference_parameter=\"\"\n\n # Pop arguments\n # Get args from command line\n # But capture them again since we need them when we actually run dragen\n existing_args_array=()\n while [ $# -gt 0 ]; do\n case \"$1\" in\n --enable-sort=*)\n enable_sort_parameter=\"$1\"\n ;;\n --enable-duplicate-marking=*)\n enable_duplicate_marking_parameter=\"\\${1}\"\n ;;\n --enable-map-align=*)\n : # Just popping from array, we set this by default in these steps but dont want it in final dragen call\n ;;\n --enable-map-align-output=*)\n : # Just popping from array, we set this by default in these steps but dont want it in final dragen call\n ;;\n --dedup-min-qual=*)\n dedup_min_qual_parameter=\"\\${1}\"\n ;;\n --cram-input=*)\n : # Just popping from array as we set the new location elsewhere\n ;;\n --tumor-cram-input=*)\n : # Just popping from array as we set the new location elsewhere\n ;;\n --cram-reference=*)\n cram_reference_parameter=\"\\${1}\"\n ;;\n *)\n existing_args_array+=(\"\\${1}\")\n esac\n shift 1\n done\n\n # Then run dragen map-align and place the files in the output directories\n # Tumor Then Normal\n echo \"Aligning tumor\" 1>&2\n # Eval prefix required here as some parameters are empty\n eval /opt/edico/bin/dragen \\\\\n --enable-map-align=true \\\\\n --enable-map-align-output=true \\\\\n \"\\${enable_sort_parameter}\" \\\\\n \"\\${enable_duplicate_marking_parameter}\" \\\\\n \"\\${dedup_min_qual_parameter}\" \\\\\n \"\\${cram_reference_parameter}\" \\\\\n \"--ref-dir=$(get_ref_path(inputs.reference_tar))\" \\\\\n \"--output-directory=$(inputs.output_directory)\" \\\\\n \"--output-file-prefix=$(inputs.output_file_prefix)\" \\\\\n \"--intermediate-results-dir=$(get_intermediate_results_dir())\" \\\\\n \"--lic-instance-id-location=$(get_optional_attribute_from_multi_type_input_object(inputs.lic_instance_id_location, \"path\"))\" \\\\\n \"--tumor-cram-input=$(get_attribute_from_optional_input(inputs.tumor_cram_input, \"path\"))\"\n\n echo \"Aligning normal\" 1>&2\n # Eval prefix required here as some parameters are empty\n eval /opt/edico/bin/dragen \\\\\n --enable-map-align=true \\\\\n --enable-map-align-output=true \\\\\n \"\\${enable_sort_parameter}\" \\\\\n \"\\${enable_duplicate_marking_parameter}\" \\\\\n \"\\${dedup_min_qual_parameter}\" \\\\\n \"\\${cram_reference_parameter}\" \\\\\n \"--ref-dir=$(get_ref_path(inputs.reference_tar))\" \\\\\n \"--output-directory=$(inputs.output_directory)\" \\\\\n \"--output-file-prefix=$(inputs.output_file_prefix)\" \\\\\n \"--intermediate-results-dir=$(get_intermediate_results_dir())\" \\\\\n \"--lic-instance-id-location=$(get_optional_attribute_from_multi_type_input_object(inputs.lic_instance_id_location, \"path\"))\" \\\\\n \"--cram-input=$(get_attribute_from_optional_input(inputs.cram_input, \"path\"))\"\n\n # Pop back in existing arguments into \\${@}\n for existing_arg in \"\\${existing_args_array[@]}\"; do\n set -- \"\\${@}\" \"\\${existing_arg}\"\n done\n\n # Update bam input and tumor bam input parameters\n # Note that we output bams by default\n set -- \"\\${@}\" \"--bam-input=$(inputs.output_directory)/$(inputs.output_file_prefix).bam\"\n set -- \"\\${@}\" \"--tumor-bam-input=$(inputs.output_directory)/$(inputs.output_file_prefix)_tumor.bam\"\n\n # Explicity set enable map align to false since we have already done the alignment\n # Setting --enable-map-align to false, sets --enable-map-align-output to false as well\n set -- \"\\${@}\" \"--enable-map-align=false\"\nfi\n\n# Run dragen command and import options from cli\necho \"Running dragen variant calling\" 1>&2\n\"$(get_dragen_bin_path())\" \"\\${@}\"\n\n# Check if a normal input is set\nif [[ \"$(is_not_null(inputs.fastq_list))\" == \"true\" || \"$(is_not_null(inputs.fastq_list_rows))\" == \"true\" || \"$(is_not_null(inputs.bam_input))\" == \"true\" || \"$(is_not_null(inputs.cram_input))\" == \"true\" ]]; then\n # --enable-map-align-output is set to false\n if [[ \"$(get_bool_value_as_str(inputs.enable_map_align_output))\" == \"false\" ]]; then\n # No bams output if -enable-map-align-output is false and --enable-map-align is also false\n # if --enable-map-align-output is false and --enable-map-align is false, no bam output\n if [[ \"$(get_bool_value_as_str(inputs.enable_map_align))\" == \"false\" ]]; then\n echo \"--enable-map-align-output and --enable-map-align set to false, no bam output\" 1>&2\n\n # Bams output if --enable-map-align-output is false but --enable-map-align is true\n # And one of tumor_bam_input or tumor_cram_input is set\n # And one of bam_input or cram_input is set\n # Then bam is generated even when --enable-map-align-output is explicitly set to false\n # Since we needed to align the tumor and normal prior to running the variant calling step\n # So when --enable-map-align-output is false under these conditions, we should delete the normal bam file rather than move it\n elif [[ \"$(get_bool_value_as_str(inputs.enable_map_align))\" == \"true\" && ( \"$(is_not_null(inputs.tumor_bam_input))\" == \"true\" || \"$(is_not_null(inputs.tumor_cram_input))\" == \"true\" ) && ( \"$(is_not_null(inputs.bam_input))\" == \"true\" || \"$(is_not_null(inputs.cram_input))\" == \"true\" ) ]]; then\n echo \"--enable-map-align is set to true but --enable-map-align-output is set to false, but we ignored --enable-map-align-output=false because one both tumor and normal inputs were set to true and thus needed to be aligned separately, deleting tumor and normal bam files\" 1>&2\n rm -f \"$(inputs.output_directory)/$(inputs.output_file_prefix).bam\" \"$(inputs.output_directory)/$(inputs.output_file_prefix).bam.bai\" \"$(inputs.output_directory)/$(inputs.output_file_prefix).bam.md5sum\"\n rm -f \"$(inputs.output_directory)/$(inputs.output_file_prefix)_tumor.bam\" \"$(inputs.output_directory)/$(inputs.output_file_prefix)_tumor.bam.bai\" \"$(inputs.output_directory)/$(inputs.output_file_prefix)_tumor.bam.md5sum\"\n fi\n\n # No action required otherwise --enable-map-align-output is false\n\n # --enable-map-align-output is true\n # Move normal bam file to new normal bam file name prefix\n else\n # Ensure that we have a normal RGSM value, otherwise exit.\n if [[ \"$(is_not_null(get_normal_output_prefix(inputs)))\" == \"false\" ]]; then\n echo \"Could not get the normal bam file prefix\" 1>&2\n echo \"Exiting\" 1>&2\n exit\n fi\n\n # Get new normal file name prefix from the fastq_list.csv\n new_normal_file_name_prefix=\"$(get_normal_output_prefix(inputs))\"\n\n # Ensure output normal bam file exists and the destination normal bam file also does not exist yet\n if [[ -f \"$(inputs.output_directory)/$(inputs.output_file_prefix).bam\" && ! -f \"$(inputs.output_directory)/\\${new_normal_file_name_prefix}.bam\" ]]; then\n # Move normal bam, normal bam index and normal bam md5sum\n (\n cd \"$(inputs.output_directory)\"\n mv \"$(inputs.output_file_prefix).bam\" \"\\${new_normal_file_name_prefix}.bam\"\n mv \"$(inputs.output_file_prefix).bam.bai\" \"\\${new_normal_file_name_prefix}.bam.bai\"\n mv \"$(inputs.output_file_prefix).bam.md5sum\" \"\\${new_normal_file_name_prefix}.bam.md5sum\"\n )\n else\n echo \"Error! Expected to move file from $(inputs.output_file_prefix).bam to \\${new_normal_file_name_prefix}.bam but either $(inputs.output_file_prefix).bam does not exist or \\${new_normal_file_name_prefix}.bam already exists\" 1>&2\n fi\n fi\nfi\n\n# If --enable-sv has been selected, we need to remove the empty genomeDepth directory\n# https://github.com/umccr-illumina/ica_v2/issues/131\nif [[ \"$(is_not_null(inputs.enable_sv))\" == \"true\" && \"$(get_bool_value_as_str(inputs.enable_sv))\" == \"true\" && -d \"$(inputs.output_directory)/sv/\" ]]; then\n find \"$(inputs.output_directory)/sv/\" -type d -empty -delete\nfi\n" + "entry": "#!/usr/bin/env bash\n\n# Fail on non-zero exit of subshell\nset -euo pipefail\n\n# Confirm not more than one of fastq_list, fastq_list_rows, bam_input and cram_input are defined\nif [[ \"$(boolean_to_int(is_not_null(inputs.fastq_list)) + boolean_to_int(is_not_null(inputs.fastq_list_rows)) + boolean_to_int(is_not_null(inputs.bam_input)) + boolean_to_int(is_not_null(inputs.cram_input)))\" -gt \"1\" ]]; then\n echo \"Please set no more than one of fastq_list, fastq_list_rows, bam_input or cram_input for normal sample\" 1>&2\n exit 1\nfi\n\n# Ensure that at least one (and only one) of tumor_fastq_list, tumor_fastq_list_rows, tumor_bam_input and tumor_cram_input are defined but not both defined (XOR)\nif [[ \"$(boolean_to_int(is_not_null(inputs.tumor_fastq_list)) + boolean_to_int(is_not_null(inputs.tumor_fastq_list_rows)) + boolean_to_int(is_not_null(inputs.tumor_bam_input)) + boolean_to_int(is_not_null(inputs.tumor_cram_input)))\" -ne \"1\" ]]; then\n echo \"One and only one of inputs tumor_fastq_list, tumor_fastq_list_rows, tumor_bam_input, tumor_cram_input must be defined\" 1>&2\n exit 1\nfi\n\n# Reset dragen\n/opt/edico/bin/dragen \\\\\n --partial-reconfig HMM \\\\\n --ignore-version-check true\n\n# Create directories\nmkdir --parents \\\\\n \"$(get_ref_mount())\" \\\\\n \"$(get_intermediate_results_dir())\" \\\\\n \"$(inputs.output_directory)\"\n\n# untar ref data into scratch space\ntar \\\\\n --directory \"$(get_ref_mount())\" \\\\\n --extract \\\\\n --file \"$(inputs.reference_tar.path)\"\n\n# Check if ora reference is set\nif [[ \"$(is_not_null(inputs.ora_reference_tar))\" == \"true\" ]]; then\n tar \\\\\n --directory \"$(get_ref_mount())\" \\\\\n --extract \\\\\n --file \"$(get_attribute_from_optional_input(inputs.ora_reference_tar, \"path\"))\"\nfi\n\n# Check if both bam inputs are set\nif [[ \"$(is_not_null(inputs.bam_input))\" == \"true\" && \"$(is_not_null(inputs.tumor_bam_input))\" == \"true\" && ( \"$(get_bool_value_as_str(inputs.enable_map_align))\" == \"true\" || \"$(get_bool_value_as_str(inputs.enable_map_align_output))\" == \"true\" ) ]]; then\n echo \"More than one bam input is set, need to run enable map align first beforehand then run variant calling in a separate step\" 1>&2\n\n # Collect options relating to map alignment (these options will be popped from the args list and not used in the variant calling step)\n enable_sort_parameter=\"\"\n enable_duplicate_marking_parameter=\"\"\n dedup_min_qual_parameter=\"\"\n\n # Pop arguments\n # Get args from command line\n # But capture them again since we need them when we actually run dragen\n existing_args_array=()\n while [ $# -gt 0 ]; do\n case \"$1\" in\n --enable-sort=*)\n enable_sort_parameter=\"$1\"\n ;;\n --enable-duplicate-marking=*)\n enable_duplicate_marking_parameter=\"\\${1}\"\n ;;\n --enable-map-align=*)\n : # Just popping from array, we set this by default in these steps but dont want it in final dragen call\n ;;\n --enable-map-align-output=*)\n : # Just popping from array, we set this by default in these steps but dont want it in final dragen call\n ;;\n --dedup-min-qual=*)\n dedup_min_qual_parameter=\"\\${1}\"\n ;;\n --bam-input=*)\n : # Just popping from array as we set the new location elsewhere\n ;;\n --tumor-bam-input=*)\n : # Just popping from array as we set the new location elsewhere\n ;;\n *)\n existing_args_array+=(\"\\${1}\")\n esac\n shift 1\n done\n\n # Then run dragen map-align and place the files in the output directories\n # Tumor Then Normal\n echo \"Aligning tumor\" 1>&2\n # Eval prefix required here as some parameters are empty\n eval /opt/edico/bin/dragen \\\\\n --enable-map-align=true \\\\\n --enable-map-align-output=true \\\\\n \"\\${enable_sort_parameter}\" \\\\\n \"\\${enable_duplicate_marking_parameter}\" \\\\\n \"\\${dedup_min_qual_parameter}\" \\\\\n \"--ref-dir=$(get_ref_path(inputs.reference_tar))\" \\\\\n \"--output-directory=$(inputs.output_directory)\" \\\\\n \"--output-file-prefix=$(inputs.output_file_prefix)\" \\\\\n \"--intermediate-results-dir=$(get_intermediate_results_dir())\" \\\\\n \"--lic-instance-id-location=$(get_optional_attribute_from_multi_type_input_object(inputs.lic_instance_id_location, \"path\"))\" \\\\\n \"--tumor-bam-input=$(get_attribute_from_optional_input(inputs.tumor_bam_input, \"path\"))\"\n\n echo \"Aligning normal\" 1>&2\n # Eval prefix required here as some parameters are empty\n eval /opt/edico/bin/dragen \\\\\n --enable-map-align=true \\\\\n --enable-map-align-output=true \\\\\n \"\\${enable_sort_parameter}\" \\\\\n \"\\${enable_duplicate_marking_parameter}\" \\\\\n \"\\${dedup_min_qual_parameter}\" \\\\\n \"--ref-dir=$(get_ref_path(inputs.reference_tar))\" \\\\\n \"--output-directory=$(inputs.output_directory)\" \\\\\n \"--output-file-prefix=$(inputs.output_file_prefix)\" \\\\\n \"--intermediate-results-dir=$(get_intermediate_results_dir())\" \\\\\n \"--lic-instance-id-location=$(get_optional_attribute_from_multi_type_input_object(inputs.lic_instance_id_location, \"path\"))\" \\\\\n \"--bam-input=$(get_attribute_from_optional_input(inputs.bam_input, \"path\"))\"\n\n # Pop back in existing arguments into \\${@}\n for existing_arg in \"\\${existing_args_array[@]}\"; do\n set -- \"\\${@}\" \"\\${existing_arg}\"\n done\n\n # Update bam input and tumor bam input parameters\n set -- \"\\${@}\" \"--bam-input=$(inputs.output_directory)/$(inputs.output_file_prefix).bam\"\n set -- \"\\${@}\" \"--tumor-bam-input=$(inputs.output_directory)/$(inputs.output_file_prefix)_tumor.bam\"\n\n # Explicity set enable map align to false\n # Setting --enable-map-align to false, sets --enable-map-align-output to false as well\n set -- \"\\${@}\" \"--enable-map-align=false\"\nfi\n\n# Check if cram inputs are set and enable map align output is set\n# Like bam inputs, we need to run map align first before running variant calling\nif [[ \"$(is_not_null(inputs.cram_input))\" == \"true\" && \"$(is_not_null(inputs.tumor_cram_input))\" == \"true\" && ( \"$(get_bool_value_as_str(inputs.enable_map_align))\" == \"true\" || \"$(get_bool_value_as_str(inputs.enable_map_align_output))\" == \"true\" ) ]]; then\n echo \"More than one cram input is set, need to run enable map align first beforehand then run variant calling in a separate step\" 1>&2\n\n # Collect options relating to map alignment (these options will be popped from the args list and not used in the variant calling step)\n enable_sort_parameter=\"\"\n enable_duplicate_marking_parameter=\"\"\n dedup_min_qual_parameter=\"\"\n cram_reference_parameter=\"\"\n\n # Pop arguments\n # Get args from command line\n # But capture them again since we need them when we actually run dragen\n existing_args_array=()\n while [ $# -gt 0 ]; do\n case \"$1\" in\n --enable-sort=*)\n enable_sort_parameter=\"$1\"\n ;;\n --enable-duplicate-marking=*)\n enable_duplicate_marking_parameter=\"\\${1}\"\n ;;\n --enable-map-align=*)\n : # Just popping from array, we set this by default in these steps but dont want it in final dragen call\n ;;\n --enable-map-align-output=*)\n : # Just popping from array, we set this by default in these steps but dont want it in final dragen call\n ;;\n --dedup-min-qual=*)\n dedup_min_qual_parameter=\"\\${1}\"\n ;;\n --cram-input=*)\n : # Just popping from array as we set the new location elsewhere\n ;;\n --tumor-cram-input=*)\n : # Just popping from array as we set the new location elsewhere\n ;;\n --cram-reference=*)\n cram_reference_parameter=\"\\${1}\"\n ;;\n *)\n existing_args_array+=(\"\\${1}\")\n esac\n shift 1\n done\n\n # Then run dragen map-align and place the files in the output directories\n # Tumor Then Normal\n echo \"Aligning tumor\" 1>&2\n # Eval prefix required here as some parameters are empty\n eval /opt/edico/bin/dragen \\\\\n --enable-map-align=true \\\\\n --enable-map-align-output=true \\\\\n \"\\${enable_sort_parameter}\" \\\\\n \"\\${enable_duplicate_marking_parameter}\" \\\\\n \"\\${dedup_min_qual_parameter}\" \\\\\n \"\\${cram_reference_parameter}\" \\\\\n \"--ref-dir=$(get_ref_path(inputs.reference_tar))\" \\\\\n \"--output-directory=$(inputs.output_directory)\" \\\\\n \"--output-file-prefix=$(inputs.output_file_prefix)\" \\\\\n \"--intermediate-results-dir=$(get_intermediate_results_dir())\" \\\\\n \"--lic-instance-id-location=$(get_optional_attribute_from_multi_type_input_object(inputs.lic_instance_id_location, \"path\"))\" \\\\\n \"--tumor-cram-input=$(get_attribute_from_optional_input(inputs.tumor_cram_input, \"path\"))\"\n\n echo \"Aligning normal\" 1>&2\n # Eval prefix required here as some parameters are empty\n eval /opt/edico/bin/dragen \\\\\n --enable-map-align=true \\\\\n --enable-map-align-output=true \\\\\n \"\\${enable_sort_parameter}\" \\\\\n \"\\${enable_duplicate_marking_parameter}\" \\\\\n \"\\${dedup_min_qual_parameter}\" \\\\\n \"\\${cram_reference_parameter}\" \\\\\n \"--ref-dir=$(get_ref_path(inputs.reference_tar))\" \\\\\n \"--output-directory=$(inputs.output_directory)\" \\\\\n \"--output-file-prefix=$(inputs.output_file_prefix)\" \\\\\n \"--intermediate-results-dir=$(get_intermediate_results_dir())\" \\\\\n \"--lic-instance-id-location=$(get_optional_attribute_from_multi_type_input_object(inputs.lic_instance_id_location, \"path\"))\" \\\\\n \"--cram-input=$(get_attribute_from_optional_input(inputs.cram_input, \"path\"))\"\n\n # Pop back in existing arguments into \\${@}\n for existing_arg in \"\\${existing_args_array[@]}\"; do\n set -- \"\\${@}\" \"\\${existing_arg}\"\n done\n\n # Update bam input and tumor bam input parameters\n # Note that we output bams by default\n set -- \"\\${@}\" \"--bam-input=$(inputs.output_directory)/$(inputs.output_file_prefix).bam\"\n set -- \"\\${@}\" \"--tumor-bam-input=$(inputs.output_directory)/$(inputs.output_file_prefix)_tumor.bam\"\n\n # Explicity set enable map align to false since we have already done the alignment\n # Setting --enable-map-align to false, sets --enable-map-align-output to false as well\n set -- \"\\${@}\" \"--enable-map-align=false\"\nfi\n\n# Run dragen command and import options from cli\necho \"Running dragen variant calling\" 1>&2\n\"$(get_dragen_bin_path())\" \"\\${@}\"\n\n# Check if a normal input is set\nif [[ \"$(is_not_null(inputs.fastq_list))\" == \"true\" || \"$(is_not_null(inputs.fastq_list_rows))\" == \"true\" || \"$(is_not_null(inputs.bam_input))\" == \"true\" || \"$(is_not_null(inputs.cram_input))\" == \"true\" ]]; then\n # --enable-map-align-output is set to false\n if [[ \"$(get_bool_value_as_str(inputs.enable_map_align_output))\" == \"false\" ]]; then\n # No bams output if -enable-map-align-output is false and --enable-map-align is also false\n # if --enable-map-align-output is false and --enable-map-align is false, no bam output\n if [[ \"$(get_bool_value_as_str(inputs.enable_map_align))\" == \"false\" ]]; then\n echo \"--enable-map-align-output and --enable-map-align set to false, no bam output\" 1>&2\n\n # Bams output if --enable-map-align-output is false but --enable-map-align is true\n # And one of tumor_bam_input or tumor_cram_input is set\n # And one of bam_input or cram_input is set\n # Then bam is generated even when --enable-map-align-output is explicitly set to false\n # Since we needed to align the tumor and normal prior to running the variant calling step\n # So when --enable-map-align-output is false under these conditions, we should delete the normal bam file rather than move it\n elif [[ \"$(get_bool_value_as_str(inputs.enable_map_align))\" == \"true\" && ( \"$(is_not_null(inputs.tumor_bam_input))\" == \"true\" || \"$(is_not_null(inputs.tumor_cram_input))\" == \"true\" ) && ( \"$(is_not_null(inputs.bam_input))\" == \"true\" || \"$(is_not_null(inputs.cram_input))\" == \"true\" ) ]]; then\n echo \"--enable-map-align is set to true but --enable-map-align-output is set to false, but we ignored --enable-map-align-output=false because one both tumor and normal inputs were set to true and thus needed to be aligned separately, deleting tumor and normal bam files\" 1>&2\n rm -f \"$(inputs.output_directory)/$(inputs.output_file_prefix).bam\" \"$(inputs.output_directory)/$(inputs.output_file_prefix).bam.bai\" \"$(inputs.output_directory)/$(inputs.output_file_prefix).bam.md5sum\"\n rm -f \"$(inputs.output_directory)/$(inputs.output_file_prefix)_tumor.bam\" \"$(inputs.output_directory)/$(inputs.output_file_prefix)_tumor.bam.bai\" \"$(inputs.output_directory)/$(inputs.output_file_prefix)_tumor.bam.md5sum\"\n fi\n\n # No action required otherwise --enable-map-align-output is false\n\n # --enable-map-align-output is true\n # Move normal bam file to new normal bam file name prefix\n else\n # Ensure that we have a normal RGSM value, otherwise exit.\n if [[ \"$(is_not_null(get_normal_output_prefix(inputs)))\" == \"false\" ]]; then\n echo \"Could not get the normal bam file prefix\" 1>&2\n echo \"Exiting\" 1>&2\n exit\n fi\n\n # Get new normal file name prefix from the fastq_list.csv\n new_normal_file_name_prefix=\"$(get_normal_output_prefix(inputs))\"\n\n # Ensure output normal bam file exists and the destination normal bam file also does not exist yet\n if [[ -f \"$(inputs.output_directory)/$(inputs.output_file_prefix).bam\" && ! -f \"$(inputs.output_directory)/\\${new_normal_file_name_prefix}.bam\" ]]; then\n # Move normal bam, normal bam index and normal bam md5sum\n (\n cd \"$(inputs.output_directory)\"\n mv \"$(inputs.output_file_prefix).bam\" \"\\${new_normal_file_name_prefix}.bam\"\n mv \"$(inputs.output_file_prefix).bam.bai\" \"\\${new_normal_file_name_prefix}.bam.bai\"\n mv \"$(inputs.output_file_prefix).bam.md5sum\" \"\\${new_normal_file_name_prefix}.bam.md5sum\"\n )\n else\n echo \"Error! Expected to move file from $(inputs.output_file_prefix).bam to \\${new_normal_file_name_prefix}.bam but either $(inputs.output_file_prefix).bam does not exist or \\${new_normal_file_name_prefix}.bam already exists\" 1>&2\n fi\n fi\nfi\n\n# If --enable-sv has been selected, we need to remove the empty genomeDepth directory\n# https://github.com/umccr-illumina/ica_v2/issues/131\nif [[ \"$(is_not_null(inputs.enable_sv))\" == \"true\" && \"$(get_bool_value_as_str(inputs.enable_sv))\" == \"true\" && -d \"$(inputs.output_directory)/sv/\" ]]; then\n find \"$(inputs.output_directory)/sv/\" -type d -empty -delete\nfi\n" }, "${\n return generate_somatic_mount_points(inputs);\n}\n" ], @@ -1281,7 +1281,7 @@ }, { "expressionLib": [ - "/* Author:Alexis Lucattini */\n/* For assistance on generation of typescript expressions */\n/* In CWL, please visit our wiki page at https://github.com/umccr/cwl-ica/wiki/TypeScript */\n/* Imports */\n/* Functions */\nfunction get_script_path() {\n /*\n Abstract script path, can then be referenced in baseCommand attribute too\n Makes things more readable.\n */\n return \"run-dragen-script.sh\";\n}\nfunction get_scratch_mount() {\n /*\n Return the path of the scratch directory space\n */\n return \"/scratch/\";\n}\nfunction get_intermediate_results_dir() {\n /*\n Get intermediate results directory as /scratch for dragen runs\n */\n return get_scratch_mount() + \"intermediate-results/\";\n}\nfunction get_name_root_from_tarball(basename) {\n var tar_ball_regex = /(\\S+)\\.tar\\.gz/g;\n var tar_ball_expression = tar_ball_regex.exec(basename);\n if (tar_ball_expression === null) {\n throw new Error(\"Could not get nameroot from \".concat(basename));\n }\n return tar_ball_expression[1];\n}\nfunction get_ref_path(reference_input_obj) {\n /*\n Get the reference path\n */\n return get_ref_mount() + get_name_root_from_tarball(reference_input_obj.basename) + \"/\";\n}\nfunction get_ref_mount() {\n /*\n Get the reference mount point\n */\n return get_scratch_mount() + \"ref/\";\n}\nfunction get_dragen_bin_path() {\n /*\n Get dragen bin path\n */\n return \"/opt/edico/bin/dragen\";\n}\nfunction get_dragen_eval_line() {\n /*\n Return string\n */\n return \"eval \\\"\" + get_dragen_bin_path() + \"\\\" '\\\"\\$@\\\"' \\n\";\n}\nfunction get_fastq_list_csv_path() {\n /*\n The fastq list path must be placed in working directory\n */\n return \"fastq_list.csv\";\n}\nfunction get_tumor_fastq_list_csv_path() {\n /*\n The tumor fastq list path must be placed in working directory\n */\n return \"tumor_fastq_list.csv\";\n}\nfunction get_ora_mv_files_script_path() {\n /*\n Get the ora mv files script path\n */\n return \"mv-ora-output-files.sh\";\n}\nfunction get_new_fastq_list_csv_script_path() {\n /*\n Get the new fastq list csv script path\n */\n return \"generate-new-fastq-list-csv.sh\";\n}\nfunction get_fastq_gz_md5sum_files_script_path() {\n /*\n Get the script path to generating the md5sum for each fastq gzip file\n */\n return \"generate-md5sum-for-fastq-gz-files.sh\";\n}\nfunction get_fastq_gz_file_sizes_script_path() {\n /*\n Get the script path to generating the filesizes for each fastq gzip file\n */\n return \"generate-file-sizes-for-fastq-gz-files.sh\";\n}\nfunction get_fastq_ora_md5sum_files_script_path() {\n /*\n Get the script path for generating the md5sum for each fastq ora file\n */\n return \"generate-md5sum-for-fastq-ora-files.sh\";\n}\nfunction get_fastq_ora_file_sizes_script_path() {\n /*\n Get the script path to generating the filesizes for each fastq gzip file\n */\n return \"generate-file-sizes-for-fastq-ora-files.sh\";\n}\nfunction get_normal_name_from_fastq_list_rows(fastq_list_rows) {\n /*\n Get the normal sample name from the fastq list rows object\n */\n /*\n Check fastq list rows is defined\n */\n if (fastq_list_rows === undefined || fastq_list_rows === null) {\n return null;\n }\n /*\n Get RGSM value and return\n */\n return fastq_list_rows[0].rgsm;\n}\nfunction get_normal_name_from_fastq_list_csv(fastq_list_csv) {\n /*\n Get the normal name from the fastq list csv...\n */\n /*\n Check file is defined\n */\n if (fastq_list_csv === undefined || fastq_list_csv === null) {\n return null;\n }\n /*\n Check contents are defined\n */\n if (fastq_list_csv.contents === null || fastq_list_csv.contents === undefined) {\n return null;\n }\n /*\n Confirm fastq list csv is of type File\n */\n if (fastq_list_csv.class !== \"File\") {\n throw new Error(\"Could not confirm input fastq_list_csv is of type File\");\n }\n /*\n Split contents by line\n */\n var contents_by_line = [];\n fastq_list_csv.contents.split(\"\\n\").forEach(function (line_content) {\n var stripped_line_content = line_content.replace(/(\\r\\n|\\n|\\r)/gm, \"\");\n if (stripped_line_content !== \"\") {\n contents_by_line.push(stripped_line_content);\n }\n });\n var column_names = contents_by_line[0].split(\",\");\n /*\n Get RGSM index value (which column is RGSM at?)\n */\n var rgsm_index = column_names.indexOf(\"RGSM\");\n /*\n RGSM is not in index. Return null\n */\n if (rgsm_index === -1) {\n return null;\n }\n /*\n Get RGSM value of first row and return\n */\n return contents_by_line[1].split(\",\")[rgsm_index];\n}\nfunction get_normal_output_prefix(inputs) {\n var _a, _b;\n /*\n Get the normal RGSM value and then add _normal to it\n */\n var normal_name = null;\n var normal_re_replacement = /_normal$/;\n /*\n Check if bam_input is set\n */\n if (inputs.bam_input !== null && inputs.bam_input !== undefined) {\n /* Remove _normal from nameroot if it already exists */\n /* We dont want _normal_normal as a suffix */\n return \"\".concat((_a = inputs.bam_input.nameroot) === null || _a === void 0 ? void 0 :_a.replace(normal_re_replacement, \"\"), \"_normal\");\n }\n /*\n Check if cram_input is set\n */\n if (inputs.cram_input !== null && inputs.cram_input !== undefined) {\n /* Remove _normal from nameroot if it already exists */\n /* We dont want _normal_normal as a suffix */\n return \"\".concat((_b = inputs.cram_input.nameroot) === null || _b === void 0 ? void 0 :_b.replace(normal_re_replacement, \"\"), \"_normal\");\n }\n /*\n Check if fastq list file is set\n */\n if (inputs.fastq_list !== null && inputs.fastq_list !== undefined) {\n normal_name = get_normal_name_from_fastq_list_csv(inputs.fastq_list);\n if (normal_name !== null) {\n return \"\".concat(normal_name, \"_normal\");\n }\n }\n /*\n Otherwise collect and return from schema object\n */\n normal_name = get_normal_name_from_fastq_list_rows(inputs.fastq_list_rows);\n return \"\".concat(normal_name, \"_normal\");\n}\nfunction build_fastq_list_csv_header(header_names) {\n /*\n Convert lowercase labels to uppercase values\n i.e\n [ \"rgid\", \"rglb\", \"rgsm\", \"lane\", \"read_1\", \"read_2\" ]\n to\n \"RGID,RGLB,RGSM,Lane,Read1File,Read2File\"\n */\n var modified_header_names = [];\n for (var _i = 0, header_names_1 = header_names; _i < header_names_1.length; _i++) {\n var header_name = header_names_1[_i];\n if (header_name.indexOf(\"rg\") === 0) {\n /*\n rgid -> RGID\n */\n modified_header_names.push(header_name.toUpperCase());\n }\n else if (header_name.indexOf(\"read\") === 0) {\n /*\n read_1 -> Read1File\n */\n modified_header_names.push(\"Read\" + header_name.charAt(header_name.length - 1) + \"File\");\n }\n else {\n /*\n lane to Lane\n */\n modified_header_names.push(header_name[0].toUpperCase() + header_name.substr(1));\n }\n }\n /*\n Convert array to comma separated strings\n */\n return modified_header_names.join(\",\") + \"\\n\";\n}\nfunction get_fastq_list_row_as_csv_row(fastq_list_row, row_order) {\n var fastq_list_row_values_array = [];\n /* This for loop is here to ensure were assigning values in the same order as the header */\n for (var _i = 0, row_order_1 = row_order; _i < row_order_1.length; _i++) {\n var item_index = row_order_1[_i];\n var found_item = false;\n /* Find matching attribute in this row */\n for (var _a = 0, _b = Object.getOwnPropertyNames(fastq_list_row); _a < _b.length; _a++) {\n var fastq_list_row_field_name = _b[_a];\n var fastq_list_row_field_value = fastq_list_row[fastq_list_row_field_name];\n if (fastq_list_row_field_value === null) {\n /*\n Item not found, add an empty attribute for this cell in the csv\n */\n continue;\n }\n /* The header value matches the name in the item */\n if (fastq_list_row_field_name === item_index) {\n /*\n If the field value has a class attribute then it's either read_1 or read_2\n */\n if (fastq_list_row_field_value.hasOwnProperty(\"class\")) {\n var fastq_list_row_field_value_file = fastq_list_row_field_value;\n /*\n Assert that this is actually of class file\n */\n if (fastq_list_row_field_value_file.class !== \"File\") {\n continue;\n }\n if (fastq_list_row_field_value_file.path !== null && fastq_list_row_field_value_file.path !== undefined) {\n /*\n Push the path attribute to the fastq list csv row if it is not null\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value_file.path);\n }\n else {\n /*\n Otherwise push the location attribute\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value_file.location);\n }\n }\n else {\n /*\n Push the string attribute to the fastq list csv row\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value.toString());\n }\n found_item = true;\n break;\n }\n }\n if (!found_item) {\n /*\n Push blank cell if no item found\n */\n fastq_list_row_values_array.push(\"\");\n }\n }\n /*\n Convert to string and return as string\n */\n return fastq_list_row_values_array.join(\",\") + \"\\n\";\n}\nfunction generate_fastq_list_csv(fastq_list_rows) {\n /*\n Fastq list rows generation\n */\n var fastq_csv_file = {\n class:\"File\",\n basename:get_fastq_list_csv_path()\n };\n /*\n Set the row order\n */\n var row_order = [];\n /*\n Set the array order\n Make sure we iterate through all rows of the array\n */\n for (var _i = 0, fastq_list_rows_1 = fastq_list_rows; _i < fastq_list_rows_1.length; _i++) {\n var fastq_list_row = fastq_list_rows_1[_i];\n for (var _a = 0, _b = Object.getOwnPropertyNames(fastq_list_row); _a < _b.length; _a++) {\n var fastq_list_row_field_name = _b[_a];\n if (row_order.indexOf(fastq_list_row_field_name) === -1) {\n row_order.push(fastq_list_row_field_name);\n }\n }\n }\n /*\n Make header\n */\n fastq_csv_file.contents = build_fastq_list_csv_header(row_order);\n /*\n For each fastq list row,\n collect the values of each attribute but in the order of the header\n */\n for (var _c = 0, fastq_list_rows_2 = fastq_list_rows; _c < fastq_list_rows_2.length; _c++) {\n var fastq_list_row = fastq_list_rows_2[_c];\n /* Add csv row to file contents */\n fastq_csv_file.contents += get_fastq_list_row_as_csv_row(fastq_list_row, row_order);\n }\n return fastq_csv_file;\n}\nfunction generate_germline_mount_points(inputs) {\n /*\n Create and add in the fastq list csv for the input fastqs\n */\n var e = [];\n if (inputs.fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.fastq_list_rows)\n });\n }\n if (inputs.fastq_list !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":inputs.fastq_list\n });\n }\n /*\n Return file paths\n */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\nfunction generate_somatic_mount_points(inputs) {\n /*\n Create and add in the fastq list csv for the input fastqs\n */\n var e = [];\n if (inputs.fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.fastq_list_rows)\n });\n }\n if (inputs.tumor_fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_tumor_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.tumor_fastq_list_rows)\n });\n }\n if (inputs.fastq_list !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":inputs.fastq_list\n });\n }\n if (inputs.tumor_fastq_list !== null) {\n e.push({\n \"entryname\":get_tumor_fastq_list_csv_path(),\n \"entry\":inputs.tumor_fastq_list\n });\n }\n /*\n Return file paths\n */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\nfunction generate_transcriptome_mount_points(inputs) {\n /*\n Calls another function that generates mount points\n */\n return generate_germline_mount_points(inputs);\n}\n/* Custom functions for dragen reference tarball build */\nfunction get_liftover_dir() {\n /* Hardcoded liftover directory in dragen 4.2 */\n return \"/opt/edico/liftover/\";\n}\nfunction get_mask_dir() {\n /* Hardcoded mask directory in dragen 4.2 */\n return \"/opt/edico/fasta_mask/\";\n}\nfunction get_ref_scratch_dir(reference_name) {\n /* We get the reference scratch directory as a combination of */\n /* the dragen scratch mount and the reference name */\n return get_scratch_mount() + reference_name + \"/\";\n}\nfunction get_ora_intermediate_output_dir() {\n return get_scratch_mount() + \"ora-outputs/\";\n}\nfunction generate_ora_mv_files_script(fastq_list_rows, input_directory, output_directory) {\n /*\n Generate the shell script with a list of echo commands to write a new fastq list csv to stdout, however\n the fastq list csv contains the ora files as outputs instead\n */\n var ora_mv_files_script = \"#!/usr/bin/env bash\\n\\n\";\n ora_mv_files_script += \"# Exit on failure\\n\";\n ora_mv_files_script += \"set -euo pipefail\\n\\n\";\n ora_mv_files_script += \"# Get fastq ora paths\\n\";\n ora_mv_files_script += \"FASTQ_ORA_OUTPUT_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_3 = fastq_list_rows; _i < fastq_list_rows_3.length; _i++) {\n var fastq_list_row = fastq_list_rows_3[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n ora_mv_files_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n /* Add relative path of read 2 */\n ora_mv_files_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n ora_mv_files_script += \")\\n\\n\";\n ora_mv_files_script += \"# Move all ora files to the final output directory\\n\";\n ora_mv_files_script += \"for fastq_ora_output_path in \\\"${FASTQ_ORA_OUTPUT_PATHS[@]}\\\"; do\\n\";\n ora_mv_files_script += \" fastq_ora_scratch_path=\\\"\".concat(get_ora_intermediate_output_dir(), \"$(basename \\\"${fastq_ora_output_path}\\\")\\\"\\n\");\n ora_mv_files_script += \" mkdir -p \\\"$(dirname \\\"\".concat(output_directory, \"/${fastq_ora_output_path}\\\")\\\"\\n\");\n ora_mv_files_script += \" rsync --archive \\\\\\n\";\n ora_mv_files_script += \" --remove-source-files \\\\\\n\";\n ora_mv_files_script += \" --include \\\"$(basename \\\"${fastq_ora_output_path}\\\")\\\" \\\\\\n\";\n ora_mv_files_script += \" --exclude \\\"*\\\" \\\\\\n\";\n ora_mv_files_script += \" \\\"$(dirname \\\"${fastq_ora_scratch_path}\\\")/\\\" \\\\\\n\";\n ora_mv_files_script += \" \\\"$(dirname \\\"\".concat(output_directory, \"/${fastq_ora_output_path}\\\")/\\\"\\n\");\n ora_mv_files_script += \"done\\n\\n\";\n ora_mv_files_script += \"# Transfer all other files\\n\";\n ora_mv_files_script += \"mkdir -p \\\"\".concat(output_directory, \"/ora-logs/\\\"\\n\");\n ora_mv_files_script += \"mv \\\"\".concat(get_ora_intermediate_output_dir(), \"\\\" \\\"\").concat(output_directory, \"/ora-logs/compression/\\\"\\n\");\n return {\n class:\"File\",\n basename:get_ora_mv_files_script_path(),\n contents:ora_mv_files_script\n };\n}\nfunction generate_fastq_gz_md5sum_files_script(fastq_list_rows, input_directory) {\n /*\n Generate the fastq gzip md5sum files script command, results are printed to stdout\n */\n var get_md5sum_fastq_gz_script = \"#!/usr/bin/env bash\\n\\n\";\n get_md5sum_fastq_gz_script += \"# Exit on failure\\n\";\n get_md5sum_fastq_gz_script += \"set -euo pipefail\\n\\n\";\n /* Initialise the bash array */\n get_md5sum_fastq_gz_script += \"# Get fastq gz paths\\n\";\n get_md5sum_fastq_gz_script += \"FASTQ_GZ_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_4 = fastq_list_rows; _i < fastq_list_rows_4.length; _i++) {\n var fastq_list_row = fastq_list_rows_4[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n get_md5sum_fastq_gz_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", ''), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n get_md5sum_fastq_gz_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", ''), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n get_md5sum_fastq_gz_script += \")\\n\\n\";\n /* Build the for loop */\n get_md5sum_fastq_gz_script += \"# Generate md5sums for the input fastq gz files\\n\";\n get_md5sum_fastq_gz_script += \"for fastq_gz_path in \\\"${FASTQ_GZ_PATHS[@]}\\\"; do\\n\";\n get_md5sum_fastq_gz_script += \" full_input_path=\\\"\".concat(input_directory.path, \"/${fastq_gz_path}\\\"\\n\");\n get_md5sum_fastq_gz_script += \" md5sum \\\"${full_input_path}\\\" | sed \\\"s%${full_input_path}%${fastq_gz_path}%\\\"\\n\";\n get_md5sum_fastq_gz_script += \"done\\n\\n\";\n get_md5sum_fastq_gz_script += \"# Md5sum script complete\\n\";\n return {\n class:\"File\",\n basename:get_fastq_gz_md5sum_files_script_path(),\n contents:get_md5sum_fastq_gz_script\n };\n}\nfunction generate_fastq_gz_file_sizes_script(fastq_list_rows, input_directory) {\n /*\n Generate the fastq gzip get files sizes, results are printed to stdout\n */\n var get_filesizes_fastq_gz_script = \"#!/usr/bin/env bash\\n\\n\";\n get_filesizes_fastq_gz_script += \"# Exit on failure\\n\";\n get_filesizes_fastq_gz_script += \"set -euo pipefail\\n\\n\";\n /* Initialise the bash array */\n get_filesizes_fastq_gz_script += \"# Get fastq gz paths\\n\";\n get_filesizes_fastq_gz_script += \"FASTQ_GZ_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_5 = fastq_list_rows; _i < fastq_list_rows_5.length; _i++) {\n var fastq_list_row = fastq_list_rows_5[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n get_filesizes_fastq_gz_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", ''), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n get_filesizes_fastq_gz_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", ''), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n get_filesizes_fastq_gz_script += \")\\n\\n\";\n /* Build the for loop */\n /* Initialise the tsv */\n get_filesizes_fastq_gz_script += \"# Initialise the tsv header\\n\";\n get_filesizes_fastq_gz_script += \"echo \\\"fastqPath\\tfileSizeInBytes\\\"\\n\\n\";\n get_filesizes_fastq_gz_script += \"# Generate file sizes for the input fastq gz files\\n\";\n get_filesizes_fastq_gz_script += \"for fastq_gz_path in \\\"${FASTQ_GZ_PATHS[@]}\\\"; do\\n\";\n get_filesizes_fastq_gz_script += \" file_size=\\\"$(wc -c < \\\"\".concat(input_directory.path, \"/${fastq_gz_path}\\\")\\\"\\n\");\n get_filesizes_fastq_gz_script += \" echo \\\"${fastq_gz_path}\\t${file_size}\\\"\\n\";\n get_filesizes_fastq_gz_script += \"done\\n\\n\";\n get_filesizes_fastq_gz_script += \"# file size script complete\\n\";\n return {\n class:\"File\",\n basename:get_fastq_gz_file_sizes_script_path(),\n contents:get_filesizes_fastq_gz_script\n };\n}\nfunction generate_fastq_ora_md5sum_files_script(fastq_list_rows, input_directory, output_directory) {\n /*\n Generate the fastq ora md5sum files script command, results are printed to stdout\n */\n var get_md5sum_fastq_ora_script = \"#!/usr/bin/env bash\\n\\n\";\n get_md5sum_fastq_ora_script += \"# Exit on failure\\n\";\n get_md5sum_fastq_ora_script += \"set -euo pipefail\\n\\n\";\n /* Initialise the bash array */\n get_md5sum_fastq_ora_script += \"# Get fastq ora paths\\n\";\n get_md5sum_fastq_ora_script += \"FASTQ_ORA_OUTPUT_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_6 = fastq_list_rows; _i < fastq_list_rows_6.length; _i++) {\n var fastq_list_row = fastq_list_rows_6[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n get_md5sum_fastq_ora_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n get_md5sum_fastq_ora_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n get_md5sum_fastq_ora_script += \")\\n\\n\";\n get_md5sum_fastq_ora_script += \"# Generate md5sums for the input fastq ora files\\n\";\n get_md5sum_fastq_ora_script += \"for fastq_ora_output_path in \\\"${FASTQ_ORA_OUTPUT_PATHS[@]}\\\"; do\\n\";\n get_md5sum_fastq_ora_script += \" fastq_ora_scratch_path=\\\"\".concat(output_directory, \"$(basename \\\"${fastq_ora_output_path}\\\")\\\"\\n\");\n get_md5sum_fastq_ora_script += \" md5sum \\\"${fastq_ora_scratch_path}\\\" | sed \\\"s%${fastq_ora_scratch_path}%${fastq_ora_output_path}%\\\"\\n\";\n get_md5sum_fastq_ora_script += \"done\\n\\n\";\n get_md5sum_fastq_ora_script += \"# Md5sum script complete\\n\";\n return {\n class:\"File\",\n basename:get_fastq_ora_md5sum_files_script_path(),\n contents:get_md5sum_fastq_ora_script\n };\n}\nfunction generate_fastq_ora_file_sizes_script(fastq_list_rows, input_directory, output_directory) {\n /*\n Generate the fastq ora file size files script command, results are printed to stdout\n */\n var get_filesizes_fastq_ora_script = \"#!/usr/bin/env bash\\n\\n\";\n get_filesizes_fastq_ora_script += \"# Exit on failure\\n\";\n get_filesizes_fastq_ora_script += \"set -euo pipefail\\n\\n\";\n /* Initialise the bash array */\n get_filesizes_fastq_ora_script += \"# Get fastq ora paths\\n\";\n get_filesizes_fastq_ora_script += \"FASTQ_ORA_OUTPUT_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_7 = fastq_list_rows; _i < fastq_list_rows_7.length; _i++) {\n var fastq_list_row = fastq_list_rows_7[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n get_filesizes_fastq_ora_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n get_filesizes_fastq_ora_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n get_filesizes_fastq_ora_script += \")\\n\\n\";\n get_filesizes_fastq_ora_script += \"# Initialise the tsv header\\n\";\n get_filesizes_fastq_ora_script += \"echo \\\"fastqPath\\tfileSizeInBytes\\\"\\n\\n\";\n get_filesizes_fastq_ora_script += \"# Generate file sizes for the output fastq ora files\\n\";\n get_filesizes_fastq_ora_script += \"for fastq_ora_output_path in \\\"${FASTQ_ORA_OUTPUT_PATHS[@]}\\\"; do\\n\";\n get_filesizes_fastq_ora_script += \" fastq_ora_scratch_path=\\\"\".concat(output_directory, \"$(basename \\\"${fastq_ora_output_path}\\\")\\\"\\n\");\n get_filesizes_fastq_ora_script += \" file_size=\\\"$(wc -c < \\\"${fastq_ora_scratch_path}\\\")\\\"\\n\";\n get_filesizes_fastq_ora_script += \" echo \\\"${fastq_ora_output_path}\\t${file_size}\\\"\\n\";\n get_filesizes_fastq_ora_script += \"done\\n\\n\";\n get_filesizes_fastq_ora_script += \"# ORA script complete\\n\";\n return {\n class:\"File\",\n basename:get_fastq_ora_file_sizes_script_path(),\n contents:get_filesizes_fastq_ora_script\n };\n}\nfunction generate_new_fastq_list_csv_script(fastq_list_rows, input_directory) {\n /*\n Generate the shell script with a list of mv commands to move the output files from the scratch space to their\n original location in the working directory\n */\n var new_fastq_list_csv_script = \"#!/usr/bin/env bash\\n\\n\";\n new_fastq_list_csv_script += \"set -euo pipefail\\n\\n\";\n new_fastq_list_csv_script += \"# Generate a new fastq list csv script\\n\";\n new_fastq_list_csv_script += \"# Initialise header\\n\";\n new_fastq_list_csv_script += \"echo \\\"RGID,RGLB,RGSM,Lane,Read1File,Read2File\\\"\\n\";\n for (var _i = 0, fastq_list_rows_8 = fastq_list_rows; _i < fastq_list_rows_8.length; _i++) {\n var fastq_list_row = fastq_list_rows_8[_i];\n /* Initialise echo line */\n var echo_line = \"echo \\\"\".concat(fastq_list_row.rgid, \",\").concat(fastq_list_row.rglb, \",\").concat(fastq_list_row.rgsm, \",\").concat(fastq_list_row.lane, \",\");\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n echo_line += \"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \",\");\n }\n else {\n echo_line += ',';\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n echo_line += \"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"));\n }\n /* Finish off echo line */\n echo_line += \"\\\"\\n\";\n new_fastq_list_csv_script += echo_line;\n }\n return {\n class:\"File\",\n basename:get_new_fastq_list_csv_script_path(),\n contents:new_fastq_list_csv_script\n };\n}\nfunction find_fastq_files_in_directory_recursively_with_regex(input_dir) {\n var _a;\n /*\n Initialise the output file object\n */\n var read_1_file_list = [];\n var read_2_file_list = [];\n var output_file_objs = [];\n var fastq_file_regex = /\\.fastq\\.gz$/;\n var r1_fastq_file_regex = /_R1_001\\.fastq\\.gz$/;\n var r2_fastq_file_regex = /_R2_001\\.fastq\\.gz$/;\n /*\n Check input_dir is a directory and has a listing\n */\n if (input_dir.class === undefined || input_dir.class !== \"Directory\") {\n throw new Error(\"Could not confirm that the first argument was a directory\");\n }\n if (input_dir.listing === undefined || input_dir.listing === null) {\n throw new Error(\"Could not collect listing from directory \\\"\".concat(input_dir.basename, \"\\\"\"));\n }\n /*\n Collect listing as a variable\n */\n var input_listing = input_dir.listing;\n /*\n Iterate through the file listing\n */\n for (var _i = 0, input_listing_1 = input_listing; _i < input_listing_1.length; _i++) {\n var listing_item = input_listing_1[_i];\n if (listing_item.class === \"File\" && fastq_file_regex.test(listing_item.basename)) {\n /*\n Got the file of interest and the file basename matches the file regex\n */\n /*\n Check if the file is read 1 or read 2\n */\n if (r1_fastq_file_regex.test(listing_item.basename)) {\n read_1_file_list.push(listing_item);\n }\n if (r2_fastq_file_regex.test(listing_item.basename)) {\n read_2_file_list.push(listing_item);\n }\n }\n if (listing_item.class === \"Directory\") {\n var subdirectory_list = listing_item;\n try {\n /* Consider that the file might not be in this subdirectory and that is okay */\n output_file_objs.push.apply(output_file_objs, find_fastq_files_in_directory_recursively_with_regex(subdirectory_list));\n }\n catch (error) {\n /* Dont need to report an error though, just continue */\n }\n }\n }\n /* Iterate over all the read 1 files and try to find a matching read 2 file */\n for (var _b = 0, read_1_file_list_1 = read_1_file_list; _b < read_1_file_list_1.length; _b++) {\n var read_1_file = read_1_file_list_1[_b];\n var read_2_file = undefined;\n for (var _c = 0, read_2_file_list_1 = read_2_file_list; _c < read_2_file_list_1.length; _c++) {\n var read_2_file_candidate = read_2_file_list_1[_c];\n if (((_a = read_1_file.basename) === null || _a === void 0 ? void 0 :_a.replace(\"R1_001.fastq.gz\", \"R2_001.fastq.gz\")) === read_2_file_candidate.basename) {\n read_2_file = read_2_file_candidate;\n break;\n }\n }\n output_file_objs.push({ read1obj:read_1_file, read2obj:read_2_file });\n }\n /* Return the output file object */\n return output_file_objs;\n}\nfunction get_rgsm_value_from_fastq_file_name(fastq_file_name) {\n /* Get the RGID value from the fastq file name */\n var rgid_regex = /(.+?)(?:_S\\d+)?(?:_L00\\d)?_R[12]_001\\.fastq\\.gz$/;\n var rgid_expression = rgid_regex.exec(fastq_file_name);\n if (rgid_expression === null) {\n throw new Error(\"Could not get rgid from \".concat(fastq_file_name));\n }\n return rgid_expression[1];\n}\nfunction get_lane_value_from_fastq_file_name(fastq_file_name) {\n /* Get the lane value from the fastq file name */\n var lane_regex = /(?:.+?)(?:_S\\d+)?_L00(\\d)_R[12]_001\\.fastq\\.gz$/;\n var lane_expression = lane_regex.exec(fastq_file_name);\n if (lane_expression === null) {\n return 1;\n }\n else {\n console.log(lane_expression);\n return parseInt(lane_expression[1]);\n }\n}\nfunction generate_ora_mount_points(input_run, output_directory_path, sample_id_list) {\n /*\n Three main parts\n\n 1. Collect the fastq files\n 2. For each fastq file pair, generate the rgid, rgsm, rglb and lane attributes as necessary to make a fastq list row\n 3. Generate the fastq list csv file\n */\n /* Collect the fastq files */\n var fastq_files_pairs = find_fastq_files_in_directory_recursively_with_regex(input_run);\n /* For each fastq file pair, generate the rgid, rgsm, rglb and lane attributes as necessary */\n var fastq_list_rows = [];\n for (var _i = 0, fastq_files_pairs_1 = fastq_files_pairs; _i < fastq_files_pairs_1.length; _i++) {\n var fastq_files_pair = fastq_files_pairs_1[_i];\n var rgsm_value = get_rgsm_value_from_fastq_file_name(fastq_files_pair.read1obj.basename);\n /* Skip fastq list pair if sample_id_list is defined and the rgsm_value is not in the list */\n if (sample_id_list !== undefined && sample_id_list !== null && sample_id_list !== \"\" && sample_id_list.indexOf(rgsm_value) === -1) {\n continue;\n }\n /* Remove undetermined files from the list of fastqs to process (they are often empty) */\n if (rgsm_value === \"Undetermined\") {\n continue;\n }\n /* Check if we have the size attribute and if so check if it is greater than 0 */\n if (fastq_files_pair.read1obj.size !== null && fastq_files_pair.read1obj.size !== undefined && fastq_files_pair.read1obj.size == 0) {\n continue;\n }\n /* Repeat the condition for read 2 although also ensure that read 2 is also actually defined */\n if (fastq_files_pair.read2obj !== undefined && fastq_files_pair.read2obj !== null) {\n if (fastq_files_pair.read2obj.size !== null && fastq_files_pair.read2obj.size !== undefined && fastq_files_pair.read2obj.size == 0) {\n continue;\n }\n }\n var lane_value = get_lane_value_from_fastq_file_name(fastq_files_pair.read1obj.basename);\n var fastq_list_row = {\n rgid:lane_value.toString() + '.' + rgsm_value,\n rgsm:rgsm_value,\n rglb:\"UnknownLibrary\",\n lane:lane_value,\n read_1:fastq_files_pair.read1obj,\n read_2:fastq_files_pair.read2obj\n };\n fastq_list_rows.push(fastq_list_row);\n }\n /* Initialise dirent */\n var e = [];\n /* Generate the fastq list csv file */\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(fastq_list_rows)\n });\n /* Generate the script to then move the files from the scratch space to the working directory */\n e.push({\n \"entryname\":get_ora_mv_files_script_path(),\n \"entry\":generate_ora_mv_files_script(fastq_list_rows, input_run, output_directory_path)\n });\n /* Generate the script to generate the new output fastq list csv */\n e.push({\n \"entryname\":get_new_fastq_list_csv_script_path(),\n \"entry\":generate_new_fastq_list_csv_script(fastq_list_rows, input_run)\n });\n /* Generate the script to generate the md5sums of the input gzipped fastq files */\n e.push({\n \"entryname\":get_fastq_gz_md5sum_files_script_path(),\n \"entry\":generate_fastq_gz_md5sum_files_script(fastq_list_rows, input_run)\n });\n /* Generate the script to generate the filesizes of the input gzipped fastq files */\n e.push({\n \"entryname\":get_fastq_gz_file_sizes_script_path(),\n \"entry\":generate_fastq_gz_file_sizes_script(fastq_list_rows, input_run)\n });\n /* Generate the script to generate the md5sums of the output ora fastq files */\n e.push({\n \"entryname\":get_fastq_ora_md5sum_files_script_path(),\n \"entry\":generate_fastq_ora_md5sum_files_script(fastq_list_rows, input_run, get_ora_intermediate_output_dir())\n });\n /* Generate the script to generate the filesizes of the output ora fastq files */\n e.push({\n \"entryname\":get_fastq_ora_file_sizes_script_path(),\n \"entry\":generate_fastq_ora_file_sizes_script(fastq_list_rows, input_run, get_ora_intermediate_output_dir())\n });\n /* Return the dirent */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\n", + "/* Author:Alexis Lucattini */\n/* For assistance on generation of typescript expressions */\n/* In CWL, please visit our wiki page at https://github.com/umccr/cwl-ica/wiki/TypeScript */\n/* Imports */\n/* Functions */\nfunction get_script_path() {\n /*\n Abstract script path, can then be referenced in baseCommand attribute too\n Makes things more readable.\n */\n return \"run-dragen-script.sh\";\n}\nfunction get_scratch_mount() {\n /*\n Return the path of the scratch directory space\n */\n return \"/scratch/\";\n}\nfunction get_intermediate_results_dir() {\n /*\n Get intermediate results directory as /scratch for dragen runs\n */\n return get_scratch_mount() + \"intermediate-results/\";\n}\nfunction get_name_root_from_tarball(basename) {\n var tar_ball_regex = /(\\S+)\\.tar\\.gz/g;\n var tar_ball_expression = tar_ball_regex.exec(basename);\n if (tar_ball_expression === null) {\n throw new Error(\"Could not get nameroot from \".concat(basename));\n }\n return tar_ball_expression[1];\n}\nfunction get_ref_path(reference_input_obj) {\n /*\n Get the reference path\n */\n return get_ref_mount() + get_name_root_from_tarball(reference_input_obj.basename) + \"/\";\n}\nfunction get_ref_mount() {\n /*\n Get the reference mount point\n */\n return get_scratch_mount() + \"ref/\";\n}\nfunction get_dragen_bin_path() {\n /*\n Get dragen bin path\n */\n return \"/opt/edico/bin/dragen\";\n}\nfunction get_dragen_eval_line() {\n /*\n Return string\n */\n return \"eval \\\"\" + get_dragen_bin_path() + \"\\\" '\\\"\\$@\\\"' \\n\";\n}\nfunction get_fastq_list_csv_path() {\n /*\n The fastq list path must be placed in working directory\n */\n return \"fastq_list.csv\";\n}\nfunction get_tumor_fastq_list_csv_path() {\n /*\n The tumor fastq list path must be placed in working directory\n */\n return \"tumor_fastq_list.csv\";\n}\nfunction get_ora_mv_files_script_path() {\n /*\n Get the ora mv files script path\n */\n return \"mv-ora-output-files.sh\";\n}\nfunction get_new_fastq_list_csv_script_path() {\n /*\n Get the new fastq list csv script path\n */\n return \"generate-new-fastq-list-csv.sh\";\n}\nfunction get_fastq_raw_md5sum_files_script_path() {\n /*\n Get the script path to generating the md5sum for each fastq gzip file\n */\n return \"generate-md5sum-for-fastq-raw-files.sh\";\n}\nfunction get_fastq_gz_file_sizes_script_path() {\n /*\n Get the script path to generating the filesizes for each fastq gzip file\n */\n return \"generate-file-sizes-for-fastq-gz-files.sh\";\n}\nfunction get_fastq_ora_md5sum_files_script_path() {\n /*\n Get the script path for generating the md5sum for each fastq ora file\n */\n return \"generate-md5sum-for-fastq-ora-files.sh\";\n}\nfunction get_fastq_ora_file_sizes_script_path() {\n /*\n Get the script path to generating the filesizes for each fastq gzip file\n */\n return \"generate-file-sizes-for-fastq-ora-files.sh\";\n}\nfunction get_normal_name_from_fastq_list_rows(fastq_list_rows) {\n /*\n Get the normal sample name from the fastq list rows object\n */\n /*\n Check fastq list rows is defined\n */\n if (fastq_list_rows === undefined || fastq_list_rows === null) {\n return null;\n }\n /*\n Get RGSM value and return\n */\n return fastq_list_rows[0].rgsm;\n}\nfunction get_normal_name_from_fastq_list_csv(fastq_list_csv) {\n /*\n Get the normal name from the fastq list csv...\n */\n /*\n Check file is defined\n */\n if (fastq_list_csv === undefined || fastq_list_csv === null) {\n return null;\n }\n /*\n Check contents are defined\n */\n if (fastq_list_csv.contents === null || fastq_list_csv.contents === undefined) {\n return null;\n }\n /*\n Confirm fastq list csv is of type File\n */\n if (fastq_list_csv.class !== \"File\") {\n throw new Error(\"Could not confirm input fastq_list_csv is of type File\");\n }\n /*\n Split contents by line\n */\n var contents_by_line = [];\n fastq_list_csv.contents.split(\"\\n\").forEach(function (line_content) {\n var stripped_line_content = line_content.replace(/(\\r\\n|\\n|\\r)/gm, \"\");\n if (stripped_line_content !== \"\") {\n contents_by_line.push(stripped_line_content);\n }\n });\n var column_names = contents_by_line[0].split(\",\");\n /*\n Get RGSM index value (which column is RGSM at?)\n */\n var rgsm_index = column_names.indexOf(\"RGSM\");\n /*\n RGSM is not in index. Return null\n */\n if (rgsm_index === -1) {\n return null;\n }\n /*\n Get RGSM value of first row and return\n */\n return contents_by_line[1].split(\",\")[rgsm_index];\n}\nfunction get_normal_output_prefix(inputs) {\n var _a, _b;\n /*\n Get the normal RGSM value and then add _normal to it\n */\n var normal_name = null;\n var normal_re_replacement = /_normal$/;\n /*\n Check if bam_input is set\n */\n if (inputs.bam_input !== null && inputs.bam_input !== undefined) {\n /* Remove _normal from nameroot if it already exists */\n /* We dont want _normal_normal as a suffix */\n return \"\".concat((_a = inputs.bam_input.nameroot) === null || _a === void 0 ? void 0 :_a.replace(normal_re_replacement, \"\"), \"_normal\");\n }\n /*\n Check if cram_input is set\n */\n if (inputs.cram_input !== null && inputs.cram_input !== undefined) {\n /* Remove _normal from nameroot if it already exists */\n /* We dont want _normal_normal as a suffix */\n return \"\".concat((_b = inputs.cram_input.nameroot) === null || _b === void 0 ? void 0 :_b.replace(normal_re_replacement, \"\"), \"_normal\");\n }\n /*\n Check if fastq list file is set\n */\n if (inputs.fastq_list !== null && inputs.fastq_list !== undefined) {\n normal_name = get_normal_name_from_fastq_list_csv(inputs.fastq_list);\n if (normal_name !== null) {\n return \"\".concat(normal_name, \"_normal\");\n }\n }\n /*\n Otherwise collect and return from schema object\n */\n normal_name = get_normal_name_from_fastq_list_rows(inputs.fastq_list_rows);\n return \"\".concat(normal_name, \"_normal\");\n}\nfunction build_fastq_list_csv_header(header_names) {\n /*\n Convert lowercase labels to uppercase values\n i.e\n [ \"rgid\", \"rglb\", \"rgsm\", \"lane\", \"read_1\", \"read_2\" ]\n to\n \"RGID,RGLB,RGSM,Lane,Read1File,Read2File\"\n */\n var modified_header_names = [];\n for (var _i = 0, header_names_1 = header_names; _i < header_names_1.length; _i++) {\n var header_name = header_names_1[_i];\n if (header_name.indexOf(\"rg\") === 0) {\n /*\n rgid -> RGID\n */\n modified_header_names.push(header_name.toUpperCase());\n }\n else if (header_name.indexOf(\"read\") === 0) {\n /*\n read_1 -> Read1File\n */\n modified_header_names.push(\"Read\" + header_name.charAt(header_name.length - 1) + \"File\");\n }\n else {\n /*\n lane to Lane\n */\n modified_header_names.push(header_name[0].toUpperCase() + header_name.substr(1));\n }\n }\n /*\n Convert array to comma separated strings\n */\n return modified_header_names.join(\",\") + \"\\n\";\n}\nfunction get_fastq_list_row_as_csv_row(fastq_list_row, row_order) {\n var fastq_list_row_values_array = [];\n /* This for loop is here to ensure were assigning values in the same order as the header */\n for (var _i = 0, row_order_1 = row_order; _i < row_order_1.length; _i++) {\n var item_index = row_order_1[_i];\n var found_item = false;\n /* Find matching attribute in this row */\n for (var _a = 0, _b = Object.getOwnPropertyNames(fastq_list_row); _a < _b.length; _a++) {\n var fastq_list_row_field_name = _b[_a];\n var fastq_list_row_field_value = fastq_list_row[fastq_list_row_field_name];\n if (fastq_list_row_field_value === null) {\n /*\n Item not found, add an empty attribute for this cell in the csv\n */\n continue;\n }\n /* The header value matches the name in the item */\n if (fastq_list_row_field_name === item_index) {\n /*\n If the field value has a class attribute then it's either read_1 or read_2\n */\n if (fastq_list_row_field_value.hasOwnProperty(\"class\")) {\n var fastq_list_row_field_value_file = fastq_list_row_field_value;\n /*\n Assert that this is actually of class file\n */\n if (fastq_list_row_field_value_file.class !== \"File\") {\n continue;\n }\n if (fastq_list_row_field_value_file.path !== null && fastq_list_row_field_value_file.path !== undefined) {\n /*\n Push the path attribute to the fastq list csv row if it is not null\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value_file.path);\n }\n else {\n /*\n Otherwise push the location attribute\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value_file.location);\n }\n }\n else {\n /*\n Push the string attribute to the fastq list csv row\n */\n fastq_list_row_values_array.push(fastq_list_row_field_value.toString());\n }\n found_item = true;\n break;\n }\n }\n if (!found_item) {\n /*\n Push blank cell if no item found\n */\n fastq_list_row_values_array.push(\"\");\n }\n }\n /*\n Convert to string and return as string\n */\n return fastq_list_row_values_array.join(\",\") + \"\\n\";\n}\nfunction generate_fastq_list_csv(fastq_list_rows) {\n /*\n Fastq list rows generation\n */\n var fastq_csv_file = {\n class:\"File\",\n basename:get_fastq_list_csv_path()\n };\n /*\n Set the row order\n */\n var row_order = [];\n /*\n Set the array order\n Make sure we iterate through all rows of the array\n */\n for (var _i = 0, fastq_list_rows_1 = fastq_list_rows; _i < fastq_list_rows_1.length; _i++) {\n var fastq_list_row = fastq_list_rows_1[_i];\n for (var _a = 0, _b = Object.getOwnPropertyNames(fastq_list_row); _a < _b.length; _a++) {\n var fastq_list_row_field_name = _b[_a];\n if (row_order.indexOf(fastq_list_row_field_name) === -1) {\n row_order.push(fastq_list_row_field_name);\n }\n }\n }\n /*\n Make header\n */\n fastq_csv_file.contents = build_fastq_list_csv_header(row_order);\n /*\n For each fastq list row,\n collect the values of each attribute but in the order of the header\n */\n for (var _c = 0, fastq_list_rows_2 = fastq_list_rows; _c < fastq_list_rows_2.length; _c++) {\n var fastq_list_row = fastq_list_rows_2[_c];\n /* Add csv row to file contents */\n fastq_csv_file.contents += get_fastq_list_row_as_csv_row(fastq_list_row, row_order);\n }\n return fastq_csv_file;\n}\nfunction generate_germline_mount_points(inputs) {\n /*\n Create and add in the fastq list csv for the input fastqs\n */\n var e = [];\n if (inputs.fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.fastq_list_rows)\n });\n }\n if (inputs.fastq_list !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":inputs.fastq_list\n });\n }\n /*\n Return file paths\n */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\nfunction generate_somatic_mount_points(inputs) {\n /*\n Create and add in the fastq list csv for the input fastqs\n */\n var e = [];\n if (inputs.fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.fastq_list_rows)\n });\n }\n if (inputs.tumor_fastq_list_rows !== null) {\n e.push({\n \"entryname\":get_tumor_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(inputs.tumor_fastq_list_rows)\n });\n }\n if (inputs.fastq_list !== null) {\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":inputs.fastq_list\n });\n }\n if (inputs.tumor_fastq_list !== null) {\n e.push({\n \"entryname\":get_tumor_fastq_list_csv_path(),\n \"entry\":inputs.tumor_fastq_list\n });\n }\n /*\n Return file paths\n */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\nfunction generate_transcriptome_mount_points(inputs) {\n /*\n Calls another function that generates mount points\n */\n return generate_germline_mount_points(inputs);\n}\n/* Custom functions for dragen reference tarball build */\nfunction get_liftover_dir() {\n /* Hardcoded liftover directory in dragen 4.2 */\n return \"/opt/edico/liftover/\";\n}\nfunction get_mask_dir() {\n /* Hardcoded mask directory in dragen 4.2 */\n return \"/opt/edico/fasta_mask/\";\n}\nfunction get_ref_scratch_dir(reference_name) {\n /* We get the reference scratch directory as a combination of */\n /* the dragen scratch mount and the reference name */\n return get_scratch_mount() + reference_name + \"/\";\n}\nfunction get_ora_intermediate_output_dir() {\n return get_scratch_mount() + \"ora-outputs/\";\n}\nfunction generate_ora_mv_files_script(fastq_list_rows, input_directory, output_directory) {\n /*\n Generate the shell script with a list of echo commands to write a new fastq list csv to stdout, however\n the fastq list csv contains the ora files as outputs instead\n */\n var ora_mv_files_script = \"#!/usr/bin/env bash\\n\\n\";\n ora_mv_files_script += \"# Exit on failure\\n\";\n ora_mv_files_script += \"set -euo pipefail\\n\\n\";\n ora_mv_files_script += \"# Get fastq ora paths\\n\";\n ora_mv_files_script += \"FASTQ_ORA_OUTPUT_PATHS=(\\n\";\n /* Iterate over all files */\n for (var _i = 0, fastq_list_rows_3 = fastq_list_rows; _i < fastq_list_rows_3.length; _i++) {\n var fastq_list_row = fastq_list_rows_3[_i];\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n /* Add relative path of read 1 */\n ora_mv_files_script += \" \\\"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n /* Add relative path of read 2 */\n ora_mv_files_script += \" \\\"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \"\\\" \\\\\\n\");\n }\n }\n /* Complete the bash array */\n ora_mv_files_script += \")\\n\\n\";\n ora_mv_files_script += \"# Move all ora files to the final output directory\\n\";\n ora_mv_files_script += \"xargs \\\\\\n\";\n ora_mv_files_script += \" --max-args=1 \\\\\\n\";\n ora_mv_files_script += \" --max-procs=16 \\\\\\n\";\n ora_mv_files_script += \" bash -c \\\\\\n\";\n ora_mv_files_script += \" '\\n\";\n ora_mv_files_script += \" fastq_ora_scratch_path=\\\"\".concat(get_ora_intermediate_output_dir(), \"$(basename \\\"$@\\\")\\\"\\n\");\n ora_mv_files_script += \" mkdir -p \\\"$(dirname \\\"\".concat(output_directory, \"/$@\\\")\\\"\\n\");\n ora_mv_files_script += \" rsync \\\\\\n\";\n ora_mv_files_script += \" --archive \\\\\\n\";\n ora_mv_files_script += \" --remove-source-files \\\\\\n\";\n ora_mv_files_script += \" --include \\\"$(basename \\\"$@\\\")\\\" \\\\\\n\";\n ora_mv_files_script += \" --exclude \\\"*\\\" \\\\\\n\";\n ora_mv_files_script += \" \\\"$(dirname \\\"${fastq_ora_scratch_path}\\\")/\\\" \\\\\\n\";\n ora_mv_files_script += \" \\\"$(dirname \\\"\".concat(output_directory, \"/$@\\\")/\\\"\\n\");\n ora_mv_files_script += \" ' \\\\\\n\";\n ora_mv_files_script += \" _ \\\\\\n\";\n ora_mv_files_script += \" <<< \\\"${FASTQ_ORA_OUTPUT_PATHS[@]}\\\"\\n\\n\";\n ora_mv_files_script += \"# Transfer all other files\\n\";\n ora_mv_files_script += \"mkdir -p \\\"\".concat(output_directory, \"/ora-logs/\\\"\\n\");\n ora_mv_files_script += \"mv \\\"\".concat(get_ora_intermediate_output_dir(), \"\\\" \\\"\").concat(output_directory, \"/ora-logs/compression/\\\"\\n\");\n return {\n class:\"File\",\n basename:get_ora_mv_files_script_path(),\n contents:ora_mv_files_script\n };\n}\nfunction generate_new_fastq_list_csv_script(fastq_list_rows, input_directory) {\n /*\n Generate the shell script with a list of mv commands to move the output files from the scratch space to their\n original location in the working directory\n */\n var new_fastq_list_csv_script = \"#!/usr/bin/env bash\\n\\n\";\n new_fastq_list_csv_script += \"set -euo pipefail\\n\\n\";\n new_fastq_list_csv_script += \"# Generate a new fastq list csv script\\n\";\n new_fastq_list_csv_script += \"# Initialise header\\n\";\n new_fastq_list_csv_script += \"echo \\\"RGID,RGLB,RGSM,Lane,Read1File,Read2File\\\"\\n\";\n for (var _i = 0, fastq_list_rows_4 = fastq_list_rows; _i < fastq_list_rows_4.length; _i++) {\n var fastq_list_row = fastq_list_rows_4[_i];\n /* Initialise echo line */\n var echo_line = \"echo \\\"\".concat(fastq_list_row.rgid, \",\").concat(fastq_list_row.rglb, \",\").concat(fastq_list_row.rgsm, \",\").concat(fastq_list_row.lane, \",\");\n /* Confirm read 1 is a file type */\n if (\"class\" in fastq_list_row.read_1 && fastq_list_row.read_1.class === \"File\") {\n echo_line += \"\".concat(fastq_list_row.read_1.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"), \",\");\n }\n else {\n echo_line += ',';\n }\n /* Confirm read 2 is a file type */\n if (fastq_list_row.read_2 !== null && \"class\" in fastq_list_row.read_2 && fastq_list_row.read_2.class === \"File\") {\n echo_line += \"\".concat(fastq_list_row.read_2.path.replace(input_directory.path + \"/\", '').replace(\".gz\", \".ora\"));\n }\n /* Finish off echo line */\n echo_line += \"\\\"\\n\";\n new_fastq_list_csv_script += echo_line;\n }\n return {\n class:\"File\",\n basename:get_new_fastq_list_csv_script_path(),\n contents:new_fastq_list_csv_script\n };\n}\nfunction find_fastq_files_in_directory_recursively_with_regex(input_dir) {\n var _a;\n /*\n Initialise the output file object\n */\n var read_1_file_list = [];\n var read_2_file_list = [];\n var output_file_objs = [];\n var fastq_file_regex = /\\.fastq\\.gz$/;\n var r1_fastq_file_regex = /_R1_001\\.fastq\\.gz$/;\n var r2_fastq_file_regex = /_R2_001\\.fastq\\.gz$/;\n /*\n Check input_dir is a directory and has a listing\n */\n if (input_dir.class === undefined || input_dir.class !== \"Directory\") {\n throw new Error(\"Could not confirm that the first argument was a directory\");\n }\n if (input_dir.listing === undefined || input_dir.listing === null) {\n throw new Error(\"Could not collect listing from directory \\\"\".concat(input_dir.basename, \"\\\"\"));\n }\n /*\n Collect listing as a variable\n */\n var input_listing = input_dir.listing;\n /*\n Iterate through the file listing\n */\n for (var _i = 0, input_listing_1 = input_listing; _i < input_listing_1.length; _i++) {\n var listing_item = input_listing_1[_i];\n if (listing_item.class === \"File\" && fastq_file_regex.test(listing_item.basename)) {\n /*\n Got the file of interest and the file basename matches the file regex\n */\n /*\n Check if the file is read 1 or read 2\n */\n if (r1_fastq_file_regex.test(listing_item.basename)) {\n read_1_file_list.push(listing_item);\n }\n if (r2_fastq_file_regex.test(listing_item.basename)) {\n read_2_file_list.push(listing_item);\n }\n }\n if (listing_item.class === \"Directory\") {\n var subdirectory_list = listing_item;\n try {\n /* Consider that the file might not be in this subdirectory and that is okay */\n output_file_objs.push.apply(output_file_objs, find_fastq_files_in_directory_recursively_with_regex(subdirectory_list));\n }\n catch (error) {\n /* Dont need to report an error though, just continue */\n }\n }\n }\n /* Iterate over all the read 1 files and try to find a matching read 2 file */\n for (var _b = 0, read_1_file_list_1 = read_1_file_list; _b < read_1_file_list_1.length; _b++) {\n var read_1_file = read_1_file_list_1[_b];\n var read_2_file = undefined;\n for (var _c = 0, read_2_file_list_1 = read_2_file_list; _c < read_2_file_list_1.length; _c++) {\n var read_2_file_candidate = read_2_file_list_1[_c];\n if (((_a = read_1_file.basename) === null || _a === void 0 ? void 0 :_a.replace(\"R1_001.fastq.gz\", \"R2_001.fastq.gz\")) === read_2_file_candidate.basename) {\n read_2_file = read_2_file_candidate;\n break;\n }\n }\n output_file_objs.push({ read1obj:read_1_file, read2obj:read_2_file });\n }\n /* Return the output file object */\n return output_file_objs;\n}\nfunction get_rgsm_value_from_fastq_file_name(fastq_file_name) {\n /* Get the RGID value from the fastq file name */\n var rgid_regex = /(.+?)(?:_S\\d+)?(?:_L00\\d)?_R[12]_001\\.fastq\\.gz$/;\n var rgid_expression = rgid_regex.exec(fastq_file_name);\n if (rgid_expression === null) {\n throw new Error(\"Could not get rgid from \".concat(fastq_file_name));\n }\n return rgid_expression[1];\n}\nfunction get_lane_value_from_fastq_file_name(fastq_file_name) {\n /* Get the lane value from the fastq file name */\n var lane_regex = /(?:.+?)(?:_S\\d+)?_L00(\\d)_R[12]_001\\.fastq\\.gz$/;\n var lane_expression = lane_regex.exec(fastq_file_name);\n if (lane_expression === null) {\n return 1;\n }\n else {\n console.log(lane_expression);\n return parseInt(lane_expression[1]);\n }\n}\nfunction generate_ora_mount_points(input_run, output_directory_path, sample_id_list) {\n /*\n Three main parts\n\n 1. Collect the fastq files\n 2. For each fastq file pair, generate the rgid, rgsm, rglb and lane attributes as necessary to make a fastq list row\n 3. Generate the fastq list csv file\n */\n /* Collect the fastq files */\n var fastq_files_pairs = find_fastq_files_in_directory_recursively_with_regex(input_run);\n /* For each fastq file pair, generate the rgid, rgsm, rglb and lane attributes as necessary */\n var fastq_list_rows = [];\n for (var _i = 0, fastq_files_pairs_1 = fastq_files_pairs; _i < fastq_files_pairs_1.length; _i++) {\n var fastq_files_pair = fastq_files_pairs_1[_i];\n var rgsm_value = get_rgsm_value_from_fastq_file_name(fastq_files_pair.read1obj.basename);\n /* Skip fastq list pair if sample_id_list is defined and the rgsm_value is not in the list */\n if (sample_id_list !== undefined && sample_id_list !== null && sample_id_list !== \"\" && sample_id_list.indexOf(rgsm_value) === -1) {\n continue;\n }\n /* Remove undetermined files from the list of fastqs to process (they are often empty) */\n if (rgsm_value === \"Undetermined\") {\n continue;\n }\n /* Check if we have the size attribute and if so check if it is greater than 0 */\n if (fastq_files_pair.read1obj.size !== null && fastq_files_pair.read1obj.size !== undefined && fastq_files_pair.read1obj.size == 0) {\n continue;\n }\n /* Repeat the condition for read 2 although also ensure that read 2 is also actually defined */\n if (fastq_files_pair.read2obj !== undefined && fastq_files_pair.read2obj !== null) {\n if (fastq_files_pair.read2obj.size !== null && fastq_files_pair.read2obj.size !== undefined && fastq_files_pair.read2obj.size == 0) {\n continue;\n }\n }\n var lane_value = get_lane_value_from_fastq_file_name(fastq_files_pair.read1obj.basename);\n var fastq_list_row = {\n rgid:lane_value.toString() + '.' + rgsm_value,\n rgsm:rgsm_value,\n rglb:\"UnknownLibrary\",\n lane:lane_value,\n read_1:fastq_files_pair.read1obj,\n read_2:fastq_files_pair.read2obj\n };\n fastq_list_rows.push(fastq_list_row);\n }\n /* Initialise dirent */\n var e = [];\n /* Generate the fastq list csv file */\n e.push({\n \"entryname\":get_fastq_list_csv_path(),\n \"entry\":generate_fastq_list_csv(fastq_list_rows)\n });\n /* Generate the script to then move the files from the scratch space to the working directory */\n e.push({\n \"entryname\":get_ora_mv_files_script_path(),\n \"entry\":generate_ora_mv_files_script(fastq_list_rows, input_run, output_directory_path)\n });\n /* Generate the script to generate the new output fastq list csv */\n e.push({\n \"entryname\":get_new_fastq_list_csv_script_path(),\n \"entry\":generate_new_fastq_list_csv_script(fastq_list_rows, input_run)\n });\n /* Return the dirent */\n /* @ts-ignore Type '{ entryname:string; entry:FileProperties; }[]' is not assignable to type 'DirentProperties[]' */\n return e;\n}\n", "/* Author:Alexis Lucattini */\n/* For assistance on generation of typescript expressions */\n/* In CWL, please visit our wiki page at https://github.com/umccr/cwl-ica/wiki/TypeScript */\n/* Imports */\n/* Functions */\nfunction is_not_null(input_obj) {\n /*\n Determine if input object is defined and is not null\n */\n return !(input_obj === null || input_obj === undefined);\n}\nfunction get_attribute_from_optional_input(input_object, attribute) {\n /*\n Get attribute from optional input -\n If input is not defined, then return null\n */\n if (input_object === null || input_object === undefined) {\n return null;\n }\n else {\n return get_optional_attribute_from_object(input_object, attribute);\n }\n}\nfunction get_optional_attribute_from_object(input_object, attribute) {\n /*\n Get attribute from object, if attribute is not defined return null\n Assume the input object is an object of key value pairs where we know the key is of type string\n stackoverflow.com/questions/56833469/typescript-error-ts7053-element-implicitly-has-an-any-type\n */\n if (input_object.hasOwnProperty(attribute)) {\n return input_object[attribute];\n }\n else {\n return null;\n }\n}\nfunction get_bool_value_as_str(input_bool) {\n if (is_not_null(input_bool) && input_bool) {\n return \"true\";\n }\n else {\n return \"false\";\n }\n}\nfunction boolean_to_int(input_bool) {\n if (is_not_null(input_bool) && String(input_bool).toLowerCase() === \"true\") {\n return 1;\n }\n else {\n return 0;\n }\n}\nfunction get_optional_attribute_from_multi_type_input_object(object, attribute) {\n /*\n Get attribute from optional input\n */\n if (object === null || object === undefined) {\n return null;\n }\n else if (typeof object === \"object\") {\n /* Get attribute from optional input */\n return get_attribute_from_optional_input(object, attribute);\n }\n else {\n /* Object is likely actually a str */\n return object;\n }\n}\nfunction get_source_a_or_b(input_a, input_b) {\n /*\n Get the first input parameter if it is not null\n Otherwise return the second parameter\n Otherwise return null\n */\n if (is_not_null(input_a)) {\n return input_a;\n }\n else if (is_not_null(input_b)) {\n return input_b;\n }\n else {\n return null;\n }\n}\nfunction get_first_non_null_input(inputs) {\n /*\n Get first element of the array that is not null\n */\n for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {\n var input_element = inputs_1[_i];\n if (is_not_null(input_element)) {\n return input_element;\n }\n }\n return null;\n}\nfunction get_attribute_list_from_object_list(obj_list, attribute) {\n /*\n Get attribute from list of objects\n If an object is null, it is not included in the return list\n */\n return obj_list.filter(function (x) { return x !== null; }).map(function (x) { return get_optional_attribute_from_object(x, attribute); });\n}\nfunction get_str_list_as_bash_array(input_list, item_wrap) {\n /*\n Convert a list of strings to a bash array, if the list is not defined return null\n */\n if (input_list === null) {\n return null;\n }\n if (item_wrap === null) {\n return \"( \".concat(input_list.map(function (x) { return \"'\".concat(item_wrap).concat(x).concat(item_wrap, \"'\"); }).join(' '), \" )\");\n }\n return \"( \".concat(input_list.map(function (x) { return \"'\".concat(x, \"'\"); }).join(' '), \" )\");\n}\nfunction get_object_attribute_list_as_bash_array(obj_list, attribute) {\n /*\n Get attribute from list of objects and convert to a bash array\n Do not include null values in the array\n */\n return get_str_list_as_bash_array(get_attribute_list_from_object_list(obj_list, attribute).filter(function (x) { return x !== null; }));\n}\n" ], "class": "InlineJavascriptRequirement"