Created
April 2, 2025 15:14
-
-
Save PoisonAlien/766eeb92dbada43a52d17629d5304366 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#A minimal shell script to split the bedgraph with H/M info into H and M bedgraghs | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <input_file.tsv>" | |
exit 1 | |
fi | |
#input file and two H/M files | |
INPUT_FILE=$1 | |
H_OUTPUT="${INPUT_FILE%.tsv}_h.tsv" | |
M_OUTPUT="${INPUT_FILE%.tsv}_m.tsv" | |
# Process the file line by line | |
line_num=0 | |
while IFS= read -r line; do | |
# First line is the header - write to both files | |
if [ $line_num -eq 0 ]; then | |
echo "$line" > "$H_OUTPUT" | |
echo "$line" > "$M_OUTPUT" | |
else | |
# Extract the 4th field (mod column) | |
mod_value=$(echo "$line" | awk -F'\t' '{print $4}') | |
# Send to appropriate output file | |
if [ "$mod_value" = "h" ]; then | |
echo "$line" >> "$H_OUTPUT" | |
elif [ "$mod_value" = "m" ]; then | |
echo "$line" >> "$M_OUTPUT" | |
fi | |
fi | |
line_num=$((line_num + 1)) | |
done < "$INPUT_FILE" | |
echo "Done!" | |
echo "H output: $H_OUTPUT" | |
echo "M output: $M_OUTPUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment