|
| 1 | +from pipeline_tools import dcp_utils |
| 2 | + |
| 3 | + |
| 4 | +def get_sample_id(metadata, version='4'): |
| 5 | + """Return the sample id from the given metadata""" |
| 6 | + if version == '4': |
| 7 | + return _get_sample_id_v4(metadata) |
| 8 | + else: |
| 9 | + raise NotImplementedError('Only implemented for v4 metadata') |
| 10 | + |
| 11 | + |
| 12 | +def _get_sample_id_v4(assay_json): |
| 13 | + """Return sample id from assay json""" |
| 14 | + return assay_json["has_input"] |
| 15 | + |
| 16 | + |
| 17 | +def get_input_metadata_file_uuid(manifest_files, version='4'): |
| 18 | + """Get the uuid of the file containing metadata about pipeline input files, |
| 19 | + e.g. assay.json in v4""" |
| 20 | + if version == '5': |
| 21 | + return _get_input_metadata_file_uuid_v5(manifest_files) |
| 22 | + elif version == '4': |
| 23 | + return _get_input_metadata_file_uuid_v4(manifest_files) |
| 24 | + else: |
| 25 | + raise NotImplementedError('Only implemented for v4 and v5 metadata') |
| 26 | + |
| 27 | + |
| 28 | +def _get_input_metadata_file_uuid_v5(manifest_files): |
| 29 | + """Get the uuid of the files.json file""" |
| 30 | + return dcp_utils.get_file_uuid(manifest_files, 'files.json') |
| 31 | + |
| 32 | + |
| 33 | +def _get_input_metadata_file_uuid_v4(manifest_files): |
| 34 | + """Get the uuid of the assay.json file""" |
| 35 | + return dcp_utils.get_file_uuid(manifest_files, 'assay.json') |
| 36 | + |
| 37 | + |
| 38 | +def get_smart_seq_2_fastq_names(metadata, version='4'): |
| 39 | + """Get the fastq file names from the given metadata""" |
| 40 | + if version == '5': |
| 41 | + return _get_smart_seq_2_fastq_names_v5(metadata) |
| 42 | + elif version == '4': |
| 43 | + return _get_smart_seq_2_fastq_names_v4(metadata) |
| 44 | + else: |
| 45 | + raise NotImplementedError('Only implemented for v4 and v5 metadata') |
| 46 | + |
| 47 | + |
| 48 | +def _get_smart_seq_2_fastq_names_v5(files_json): |
| 49 | + """Return fastq file names from files json""" |
| 50 | + index_to_name = {} |
| 51 | + for f in files_json['files']: |
| 52 | + index = f['content']['read_index'] |
| 53 | + file_name = f['content']['file_core']['file_name'] |
| 54 | + index_to_name[index] = file_name |
| 55 | + return index_to_name['read1'], index_to_name['read2'] |
| 56 | + |
| 57 | + |
| 58 | +def _get_smart_seq_2_fastq_names_v4(assay_json): |
| 59 | + """Return fastq file names from assay json""" |
| 60 | + fastq_1_name = assay_json["content"]["seq"]["lanes"][0]["r1"] |
| 61 | + fastq_2_name = assay_json["content"]["seq"]["lanes"][0]["r2"] |
| 62 | + return fastq_1_name, fastq_2_name |
| 63 | + |
| 64 | + |
| 65 | +def get_optimus_lanes(metadata_json, version='4'): |
| 66 | + """Get the lane metadata""" |
| 67 | + if version == '4': |
| 68 | + return _get_optimus_lanes_v4(metadata_json) |
| 69 | + else: |
| 70 | + raise NotImplementedError('Only implemented for v4 metadata') |
| 71 | + |
| 72 | + |
| 73 | +def _get_optimus_lanes_v4(assay_json): |
| 74 | + """Return the lane metadata from the assay json""" |
| 75 | + lanes = assay_json['content']['seq']['lanes'] |
| 76 | + return lanes |
| 77 | + |
| 78 | + |
| 79 | +def get_optimus_inputs(lanes, manifest_files): |
| 80 | + """Return three lists of urls, representing fastqs for r1, r2, and i1, respectively. |
| 81 | + In each list, the first item is for the first lane, the second item is for the second lane, etc. |
| 82 | + """ |
| 83 | + r1 = [manifest_files['name_to_meta'][lane['r1']]['url'] for lane in lanes] |
| 84 | + r2 = [manifest_files['name_to_meta'][lane['r2']]['url'] for lane in lanes] |
| 85 | + i1 = [manifest_files['name_to_meta'][lane['i1']]['url'] for lane in lanes] |
| 86 | + |
| 87 | + return r1, r2, i1 |
0 commit comments