def run_gatk_preprocessing(job, bam, bai, ref, ref_dict, fai, g1k, mills, dbsnp, realign=False, unsafe=False):
<EOL>mdups_disk = PromisedRequirement(lambda bam_, bai_: <NUM_LIT:2> * (bam_.size + bai_.size), bam, bai)<EOL>mdups = job.wrapJobFn(picard_mark_duplicates,<EOL>bam,<EOL>bai,<EOL>cores=job.cores,<EOL>disk=mdups_disk,<EOL>memory=job.memory)<EOL>bqsr_input_bam = mdups.rv(<NUM_LIT:0>)<EOL>bqsr_input_bai = mdups.rv(<NUM_LIT:1>)<EOL>genome_ref_size = ref.size + ref_dict.size + fai.size<EOL>if realign:<EOL><INDENT>indel_ref_size = mills.size + g1k.size + genome_ref_size<EOL>realigner_target_disk = PromisedRequirement(lambda bam_, bai_, ref_size:<EOL>bam_.size + bai_.size + <NUM_LIT:2> * ref_size,<EOL>mdups.rv(<NUM_LIT:0>),<EOL>mdups.rv(<NUM_LIT:1>),<EOL>indel_ref_size)<EOL>realigner_target = job.wrapJobFn(run_realigner_target_creator,<EOL>mdups.rv(<NUM_LIT:0>),<EOL>mdups.rv(<NUM_LIT:1>),<EOL>ref, ref_dict, fai,<EOL>g1k, mills,<EOL>unsafe=unsafe,<EOL>cores=<NUM_LIT:1>,  <EOL>disk=realigner_target_disk,<EOL>memory=job.memory)<EOL>indel_realign_disk = PromisedRequirement(lambda bam_, bai_, intervals, ref_size:<EOL><NUM_LIT:2> * (bam_.size + bai_.size) + intervals.size + ref_size,<EOL>mdups.rv(<NUM_LIT:0>),<EOL>mdups.rv(<NUM_LIT:1>),<EOL>realigner_target.rv(),<EOL>indel_ref_size)<EOL>indel_realign = job.wrapJobFn(run_indel_realignment,<EOL>realigner_target.rv(),<EOL>mdups.rv(<NUM_LIT:0>),<EOL>mdups.rv(<NUM_LIT:1>),<EOL>ref, ref_dict, fai,<EOL>g1k, mills,<EOL>unsafe=unsafe,<EOL>cores=<NUM_LIT:1>,  <EOL>disk=indel_realign_disk,<EOL>memory=job.memory)<EOL>mdups.addChild(realigner_target)<EOL>realigner_target.addChild(indel_realign)<EOL>bqsr_input_bam = indel_realign.rv(<NUM_LIT:0>)<EOL>bqsr_input_bai = indel_realign.rv(<NUM_LIT:1>)<EOL><DEDENT>bqsr_ref_size = dbsnp.size + mills.size + genome_ref_size<EOL>base_recal_disk = PromisedRequirement(lambda bam_, bai_, ref_size:<EOL>bam_.size + bai_.size + <NUM_LIT:2> * ref_size,<EOL>bqsr_input_bam,<EOL>bqsr_input_bai,<EOL>bqsr_ref_size)<EOL>base_recal = job.wrapJobFn(run_base_recalibration,<EOL>bqsr_input_bam,<EOL>bqsr_input_bai,<EOL>ref, ref_dict, fai,<EOL>dbsnp, mills,<EOL>unsafe=unsafe,<EOL>cores=job.cores,<EOL>disk=base_recal_disk,<EOL>memory=job.memory)<EOL>recalibrate_reads_disk = PromisedRequirement(lambda bam_, bai_, recal, ref_size:<EOL><NUM_LIT:2> * (bam_.size + bai_.size) + recal.size + ref_size,<EOL>bqsr_input_bam,<EOL>bqsr_input_bai,<EOL>base_recal.rv(),<EOL>genome_ref_size)<EOL>recalibrate_reads = job.wrapJobFn(apply_bqsr_recalibration,<EOL>base_recal.rv(),<EOL>bqsr_input_bam,<EOL>bqsr_input_bai,<EOL>ref, ref_dict, fai,<EOL>unsafe=unsafe,<EOL>cores=job.cores,<EOL>disk=recalibrate_reads_disk,<EOL>memory=job.memory)<EOL>job.addChild(mdups)<EOL>mdups.addFollowOn(base_recal)<EOL>base_recal.addChild(recalibrate_reads)<EOL>return recalibrate_reads.rv(<NUM_LIT:0>), recalibrate_reads.rv(<NUM_LIT:1>)<EOL>
GATK Preprocessing Pipeline
0: Mark duplicates
1: Create INDEL realignment intervals
2: Realign INDELs
3: Recalibrate base quality scores
4: Apply base score recalibration

:param JobFunctionWrappingJob job: passed automatically by Toil
:param str bam: FileStoreID for BAM file
:param str bai: FileStoreID for BAM index file
:param str ref: FileStoreID for reference genome fasta file
:param str ref_dict: FileStoreID for reference sequence dictionary file
:param str fai: FileStoreID for reference fasta index file
:param str g1k: FileStoreID for 1000 Genomes VCF file
:param str mills: FileStoreID for Mills VCF file
:param str dbsnp: FileStoreID for dbSNP VCF file
:param bool realign: If True, then runs GATK INDEL realignment"
:param bool unsafe: If True, runs GATK tools in UNSAFE mode: "-U ALLOW_SEQ_DICT_INCOMPATIBILITY"
:return: FileStoreIDs for BAM and BAI files
:rtype: tuple(str, str)