Skip to content

Instantly share code, notes, and snippets.

@sahilseth
Created November 3, 2015 18:28
Show Gist options
  • Select an option

  • Save sahilseth/f91553f6f617f91363e7 to your computer and use it in GitHub Desktop.

Select an option

Save sahilseth/f91553f6f617f91363e7 to your computer and use it in GitHub Desktop.
Adding chr to a GTF file
awk '{ if($1 !~ /^#/){print "chr"$0} else{print $0} }' Homo_sapiens.GRCh37.75.gtf
@junjieahaha

Copy link
Copy Markdown

Thanks.It worked.

@alexlenail

Copy link
Copy Markdown

This will add chr in front of every line, irrespective of what's on that line, though....

@whappycoffee

Copy link
Copy Markdown

Thank you!

@diazdc

diazdc commented Jan 31, 2019

Copy link
Copy Markdown

Thanks. For avoiding non-chromosomal regions, like repeats or mitochondrial, I just added an "or" (pipe) [A-Z ] to the regex:
/^#|[A-Z]/
These regions usually start with a capital letter instead of a number.

@aseetharam

Copy link
Copy Markdown

X and Y would be excluded with that. Instead, you can use this:

awk '{ if($1 ~ /^[0-9]+$/ || $1 ~ /^(X|Y)$/){print "chr"$0} else{print $0} }' yourfile.gtf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment