Skip to content

Instantly share code, notes, and snippets.

@klmr
Last active August 29, 2015 14:00
Show Gist options
  • Save klmr/11235107 to your computer and use it in GitHub Desktop.
Save klmr/11235107 to your computer and use it in GitHub Desktop.
Rename full reference in BAM file
mv "$input" "$input.tmp"
samtools view -h "$input.tmp" \
| awk -F '\t' -v OFS='\t' '
/^@SQ/ {
$2 = "SN:chr" substr($2, 4, match($2, " ") - 4)
print
}
/^@/ && !/^@SQ/ { print }
!/^@/ {
$3 = "chr" substr($3, 0, match($3, " "))
print
}' \
| samtools view -Sb - \
> "$output"
rm "$input.tmp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment