Hi there,
I’m working on a pipeline (see below) where I defined a few environment variables. Also, I’m creating some on the way.
In particular, I have a CONTIG variable which I wish to make univocal for each sample (ID), haplotype (HAP), and chromosome (CHR_P/M) combination; however, I’m not sure how to do it… simply defining CONTIG as CONTIG_$ID_$h_$c sounds wrong to me but I have never done this before, so I have no prior knowledge and could not find very helpful, succinct documentation on this.
This is the part of the pipeline of interest:
#!/bin/bash
#SBATCH --nodes=1 --ntasks=1 --cpus-per-task=12
#SBATCH --time=2-00:00:00
#SBATCH --mem=50gb
#
#SBATCH --job-name=name_test
#SBATCH --output=name_test.out
#SBATCH --array=[1-232]%1
#
#SBATCH --partition=DSS,NBFC
NAMES=$1
d=$(sed -n "$SLURM_ARRAY_TASK_ID"p $NAMES)
ID="$(echo ${d}/*_hap1_hprc_r2.fa.gz | sed 's#/path/to/hprc_y2_assemblies/[A-Z,0-9]\+_[a-z]/##' | sed 's#_hap1_hprc_r2.fa.gz##')"
HAP=( "hap1" "hap2")
SEX="$(echo ${d} | sed 's#/path/to/hprc_y2_assemblies/[A-Z,0-9]\+_##')"
CHR_P=("chr1" "chr2" "chr3" "chr4" "chr5" "chr6" "chr7" "chr8" "chr9" "chr10" "chr11" "chr12" "chr13" "chr14" "chr15" "chr16" "chr17" "chr18" "chr19" "chr20" "chr21" "chr22" "chrY" )
CHR_M=("chr1" "chr2" "chr3" "chr4" "chr5" "chr6" "chr7" "chr8" "chr9" "chr10" "chr11" "chr12" "chr13" "chr14" "chr15" "chr16" "chr17" "chr18" "chr19" "chr20" "chr21" "chr22" "chrX" )
BEDTOOLS="./tools/bedtools"
MINIMAP="./tools/minimap2"
SEQKIT="./tools/seqkit"
BGZIP="./tools/bgzip"
DNABRNN="./tools/dna-nn/dna-brnn"
MODELS="./tools/dna-nn/models/attcc-alpha.knm"
cd ~
#PREPARES THE INPUT
if [ -e $d/select.done ]
then
echo "regions selecion done!"
else
for h in "${HAP[@]}"; do
${MINIMAP} -cx asm5 -t 12 CHM13v2.0.fna.gz $d/${ID}_${h}_hprc_r2.fa.gz > $d/${ID}_${h}.paf && \
if [ "$SEX" == "m" ]
then
if [ "$HAP" == "hap1" ]
then
for c in "${CHR_P[@]}"; do
CONTIG=$(grep -w "${c}" $d/${ID}_${h}.paf | awk '{print $1}' | uniq) && \
for s in "${CONTIG[@]}"; do
###generate chromosome FASTA
printf "%s\n" ${s} > $d/list_${h}_${c}.txt && ${SEQKIT} grep -f $d/list_${h}_${c}.txt $d/${ID}_${h}_hprc_r2.fa.gz -j 12 | ${BGZIP} -@12 > $d/${ID}_${h}_${c}-chm13.fna.gz
###generate centromere FASTA
${DNABRNN} -Ai ${MODELS} -t32 $d/${ID}_${h}_${c}-chm13.fna.gz > $d/$h/cent/${ID}_${h}_${c}.bed && awk -F '\t' '$4==2' $d/$h/cent/${ID}_${h}_${c}.bed > $d/$h/cent/${ID}_${h}_${c}_cent.bed && ${BEDTOOLS} getfasta -fi $d/${ID}_${h}_${c}-chm13.fna.gz -bed $d/$h/cent/${ID}_${h}_${c}_cent.bed | ${BGZIP} -@12 > $d/$h/cent/${ID}_${h}_${c}_cent.fna.gz;
done
done
#some other operations here
Until now, I have never had issues but I’m afraid the CONTIG variable would get overwritten if not created with the specific ID_HAP_CHR combination. Sill, if this is not a problem I would like to know how to do it for the sake of improving my scripting. Thanks!