### Bits for script #FILEA="General ROH file" #FILEB="Inbred ROH file" # 1 - Split ${FILEA} and ${FILEB} per chromosome for chr in {1..22}; do grep -w "^${chr}" ${FILEA} > ${FILEA%.*}-${chr}.txt; grep "^${chr}" ${FILEB} > ${FILEB%.*}-${chr}.txt; done awk -v var="${chr}" {'if ($2==var) print $0'} # 2 - search each RHO from ${FILEB} against each RHO from ${FILEA} # 2.1. Extract positions ${C} and ${D} from ${FILEB} and positions ${A} and ${B} from ${FILEB} # save it on one script named - e.g. COMPARE-ROHs.sh #CHR_TO_PROCESS="$(seq 1 22) X Y" #THREADS=12 #parallel -j ${THREADS} A=${FILEA%.*}-{}.txt B=${FILEB%.*}-{}.txt .\COMPARE-ROHS.sh ::: ${CHR_TO_PROCESS} ##!/bin/bash # Usage ${FILEA} ${FILEB} ./COMPARE-ROHS.sh FILEA="${A}" FILEB="${B}" OUTFILE="outfile.${A}.txt" ## Output file while read -r ROHA; do A=`echo ${ROHA} | cut -d " " -f 8`; ## ROH Start B=`echo ${ROHA} | cut -d " " -f 9`; ## ROH End while read -r ROHB; do C=`echo ${ROH} | cut -d " " -f 8`; ## ROH Start D=`echo ${ROHB} | cut -d " " -f 9 `; ## ROH End # option1 if [[(${C} -lt ${A}) && (${D} -gt ${A}) && (${D} -lt ${B})]]; then echo -e "${RHOB} DOWSNTREAM-intercal ${RHOA}" >> ${OUTFILE} elif [[(${C} -gt ${A}) && (${C} -lt ${B}) && (${D} -gt ${B})]]; then echo -e "${RHOB} UPSTREAM-intercal $ {RHOA}" >> ${OUTFILE} # option2 elif [[(${C} -eq ${A}) && (${D} -lt ${B})]]; then echo -e "${RHOB} DOWNSTREAM-anchor-inside ${RHOA}" >> ${OUTFILE} elif [[(${C} -gt ${A}) && (${D} -eq ${B})]]; then echo -e "${RHOB} UPSTREAM-anchor-inside ${RHOA}" >> ${OUTFILE} # option3 elif [[(${D} -eq ${A}) ]]; then echo -e "${RHOB} DOWNSTREAM-anchor-out ${RHOA}" >> ${OUTFILE} elif [[(${C} -eq ${B}) ]]; then echo -e "${RHOB} UPSTREAM-anchor-out ${RHOA}" >> ${OUTFILE} # option4 elif [[(${C} -gt ${A}) && (${D} -lt ${B})]]; then echo -e "${RHOB} INTERIOR ${RHOA}" >> ${OUTFILE} elif [[(${C} -lt ${A}) && (${D} -gt ${B})]]; then echo -e "${RHOB} LARGER ${RHOA}" >> ${OUTFILE} #option5 elif [[(${C} -eq ${A}) && (${D} -eq ${B})]]; then echo -e "${RHOB} EQUAL ${RHOA}" >> ${OUTFILE} #option6 elif [[(${C} -lt ${A}) && (${D} -eq ${B})]]; then echo -e "${RHOB} LARGER-anchor-down ${RHOA}" >> ${OUTFILE} # option7 elif [[(${C} -eq ${A}) && (${D} -gt ${B})]]; then echo -e "${RHOB} LARGER-anchor-up ${RHOA}" >> ${OUTFILE} # else echo "this is not a match" >> ${OUTFILE} fi done< ${FILEB} done< ${FILEA}