File Info

Filename
.command.sh
Full Path
s3://natera-rnd-pltf-dev-nextflow-scratch-01/work/ff/db66215cf34f4876d0c78098323f14/.command.sh
Size
663 bytes
Attempt
#!/bin/bash -Ceuo pipefail
samtools idxstats 1173_NMN-N1-BDNA-01_A23MHW3LT4_1.recalibrated.bam > idxstats.txt

x_map=$(grep -E "^chrX\s|^X\s" idxstats.txt | cut -f 3)
x_len=$(grep -E "^chrX\s|^X\s" idxstats.txt | cut -f 2)
y_map=$(grep -E "^chrY\s|^Y\s" idxstats.txt | cut -f 3)
y_len=$(grep -E "^chrY\s|^Y\s" idxstats.txt | cut -f 2)

awk -v xm="$x_map" -v xl="$x_len" -v ym="$y_map" -v yl="$y_len" '
BEGIN {
    if (ym == 0 || yl == 0) {
        print "XX"
    } else {
        x_cov = xm / xl
        y_cov = ym / yl
        ratio = x_cov / y_cov
        if (ratio > 50.0) print "XX"
        else print "XY"
    }
}' > 1173_NMN-N1-BDNA-01_A23MHW3LT4_1.sex.txt