Skip to content

Commit

Permalink
fix: attempt to obviate need for absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kelly-sovacool committed Jan 22, 2025
1 parent b4613b0 commit ea99c0c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
IMAGE_NAME: recap
CONTEXT: "./"
NAMESPACE: nciccbr
VERSION_TAG: 0.3.1
VERSION_TAG: 0.3.2

jobs:
build-docker:
Expand Down
39 changes: 21 additions & 18 deletions RECAP_MACS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@

# ===============================================================
# Script version number
VERSION="1.0.2"
# Provide a variable for the location of this and other scripts
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REMIX_PATH=RECAP_Re-Mix.sh
PERL_PATH=RECAP.pl
VERSION="1.0.2"
# Text display commands
bold=$(tput bold)
normal=$(tput sgr0)
Expand All @@ -62,8 +58,6 @@ then
exit 1
fi

cd $INPUT_DIR

if [[ ! -e $CHIP_NAME ]]
then
echo -e "\nERROR: Treatment bed file does not exist"
Expand Down Expand Up @@ -92,40 +86,49 @@ then
fi

# 1) Re-mix ChIP and control bed files
bash $REMIX_PATH -i $INPUT_DIR -t $CHIP_NAME -c $CONTROL_NAME -o $OUTPUT_DIR -m unequal -b $BOOTSTRAP -s $SEED
mkdir -p $OUTPUT_DIR
RECAP_Re-Mix.sh -i $INPUT_DIR -t $CHIP_NAME -c $CONTROL_NAME -o $OUTPUT_DIR -m unequal -b $BOOTSTRAP -s $SEED

# 2) Call original peaks using MACS
# Please specify your own MACS parameters!
# NOTE: p-value threshold must be set to 0.1 for MACS
cd $INPUT_DIR
mkdir -p $OUTPUT_DIR/MACS_original
macs2 callpeak -t $CHIP_NAME -c $CONTROL_NAME --pvalue 0.10 -n ${CHIP_NAME%.*} --outdir "$OUTPUT_DIR/MACS_original"

# 3) Call re-mixed peaks using MACS specifying desired parameters
# Please specify your own MACS parameters!
# NOTE: p-value threshold must be set to 0.1 for MACS
cd "$OUTPUT_DIR/re-mix"
pushd "$OUTPUT_DIR/re-mix"
for (( i=1; i<=$BOOTSTRAP; i++ ))
do
macs2 callpeak -t "${CHIP_NAME%.bed}.bootstrap_$i.bed" -c "${CONTROL_NAME%.bed}.bootstrap_$i.bed" --pvalue 0.10 -n "${CHIP_NAME%.*}.bootstrap_$i" --outdir "$OUTPUT_DIR/MACS_re-mix"
done
popd

# All non-MACS summary files in MACS_re-mix must be deleted if $BOOTSTRAP > 1
if [ -d "$OUTPUT_DIR/MACS_re-mix" ]
then
cd "$OUTPUT_DIR/MACS_re-mix"
pushd "$OUTPUT_DIR/MACS_re-mix"
find . -type f ! -name '*_peaks.xls' -delete
popd
else
echo "Output directory doesn't exist!"
exit 1
fi

# 4) Recalibrate original peak p-values using RECAP
# NOTE: Check for correct header and p-value column if you obtain any errors here
cd $OUTPUT_DIR
mkdir MACS_RECAP

perl $PERL_PATH --dirOrig "$OUTPUT_DIR/MACS_original" --nameOrig "${CHIP_NAME%.*}_peaks.xls" --dirRemix "$OUTPUT_DIR/MACS_re-mix" --nameRemix "${CHIP_NAME%.*}" --dirOutput "$OUTPUT_DIR/MACS_RECAP" --nameOutput "${CHIP_NAME%.*}.RECAP.bootstrap_${BOOTSTRAP}_peaks.xls" --bootstrap $BOOTSTRAP --header $HEADER --pvalCol 7 --delim t --software M

mkdir -p $OUTPUT_DIR/MACS_RECAP
pushd $OUTPUT_DIR
RECAP.pl \
--dirOrig "$(realpath $OUTPUT_DIR/MACS_original)" \
--nameOrig "${CHIP_NAME%.*}_peaks.xls" \
--dirRemix "$(realpath $OUTPUT_DIR/MACS_re-mix)" \
--nameRemix "${CHIP_NAME%.*}" \
--dirOutput "$(realpath $OUTPUT_DIR/MACS_RECAP)" \
--nameOutput "${CHIP_NAME%.*}.RECAP.bootstrap_${BOOTSTRAP}_peaks.xls" \
--bootstrap $BOOTSTRAP --header $HEADER --pvalCol 7 --delim t --software M
popd
#################################################################
######################## End Script Here ########################
}
Expand All @@ -139,10 +142,10 @@ usage() {
[Output directory] [Bootstrap] [Header]
${bold}USAGE:${normal}
-i, --input Input file directory (absolute path)
-i, --input Input file directory
-t, --treatment Treatment file (full name with extension)
-c, --control Control file (full name with extension)
-o, --output Output file directory (absolute path)
-o, --output Output file directory
-b, --bootstrap Number of re-mixes
-e, --header Header number of peak calling output files
Expand Down
27 changes: 10 additions & 17 deletions RECAP_Re-Mix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ echo "##################################################"
echo "###### RECAP RE-MIX v$VERSION ######"
echo "##################################################"
echo ""
echo "Input directory (absolute path): $INPUT_DIR"
echo "Input directory: $INPUT_DIR"
echo "Treatment library: $TREATMENT_NAME"
echo "Control library: $CONTROL_NAME"
echo "Output directory (absolute path): $OUTPUT_DIR"
echo "Output directory: $OUTPUT_DIR"
echo "Re-mix method: $METHOD_NAME"
echo "Number of re-mixes: $BOOTSTRAP"
echo "Random seed: $SEED"
Expand All @@ -73,8 +73,6 @@ then
exit 1
fi

cd $INPUT_DIR

if [[ ! -e $TREATMENT_NAME || ! $TREATMENT_NAME == *.bed ]]
then
echo -e "\nERROR: Treatment bed file does not exist"
Expand All @@ -97,14 +95,13 @@ fi
# Base names of treatment and control libraries
TREATMENT_NAME_BASE="${TREATMENT_NAME%.*}"
CONTROL_NAME_BASE="${CONTROL_NAME%.*}"


mkdir -p $OUTPUT_DIR/re-mix
for (( BOOTSTRAP_COUNT=1; BOOTSTRAP_COUNT<=$BOOTSTRAP; BOOTSTRAP_COUNT++ ))
do
cd $INPUT_DIR
echo ""
echo "${bold}Starting Re-Mixing Procedure #$BOOTSTRAP_COUNT ${normal}"
echo "Creating directory for re-mix files:"
mkdir -p $OUTPUT_DIR/re-mix
echo "Check!"

echo "Concatenating treatment and control libraries"
Expand All @@ -117,38 +114,34 @@ do
echo "Unequal mixing method selected"
FIRST_LINES=$( wc -l < $TREATMENT_NAME )
LAST_LINES=$( wc -l < $CONTROL_NAME )
cd $OUTPUT_DIR/re-mix

# If method is equal
elif [ $METHOD = 1 ]
then
echo "Equal mixing method selected"
cd $OUTPUT_DIR/re-mix
COMBINED_LINES=$(wc -l < $TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp)
FIRST_LINES=$(( COMBINED_LINES / 2 ))
LAST_LINES=$(( COMBINED_LINES - FIRST_LINES ))
fi

echo "Re-mixing..."
shuf --random-source=<(get_seeded_random $SEED) -o $TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp < $TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp
shuf --random-source=<(get_seeded_random $SEED) -o $OUTPUT_DIR/re-mix/$TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp < $TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp
echo "Check!"

echo "Creating re-mixed treatment library"
head -n $FIRST_LINES $TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp > $TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.bed
head -n $FIRST_LINES $TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp > $OUTPUT_DIR/re-mix/$TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.bed
echo "Check!"

echo "Creating re-mixed control library"
tail -n $LAST_LINES $TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp > $CONTROL_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.bed
tail -n $LAST_LINES $TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp > $OUTPUT_DIR/re-mix/$CONTROL_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.bed
echo "Check!"

echo "Deleting temporary files"
rm $TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp
rm $OUTPUT_DIR/re-mix/$TREATMENT_NAME_BASE.bootstrap_$BOOTSTRAP_COUNT.tmp
echo "Check!"
echo "Completed re-mix #$BOOTSTRAP_COUNT"
done

cd $INPUT_DIR

end_time=`date +%s`
echo RECAP RE-MIX execution time: `expr $end_time - $start_time`s.

Expand All @@ -165,10 +158,10 @@ usage() {
[Output directory] [Re-mix method] [Bootstrap]
${bold}USAGE:${normal}
-i, --input Input file directory (absolute path)
-i, --input Input file directory
-t, --treatment Treatment bed file
-c, --control Control bed file
-o, --output Output file directory (absolute path)
-o, --output Output file directory
-m, --method Method of re-mixing (equal) or (unequal)
-b, --bootstrap Number of re-mixes
Expand Down

0 comments on commit ea99c0c

Please sign in to comment.