<p>Getting the non coding regions of a protein coding transcript, sounds like you are looking for <a href="https://en.wikipedia.org/wiki/Untranslated_region" rel="nofollow noreferrer">UTR</a>.</p>
<p><code>UTR</code> has its own feature in the gtf file. So you can do this:</p>
<pre><code><span class="math-container">$ awk -v FS="\t" '$</span>3==&quot;UTR&quot;' gencode.gtf
</code></pre>
<p>If the gtf file is compressed use this instead:</p>
<pre><code><span class="math-container">$ zcat gencode.gtf.gz | awk -v FS="\t" '$</span>3==&quot;UTR&quot;'
</code></pre>
<p>BTW: Why are you using such an old release of gencode? The current version is v29.</p>
<p>As @Wouter <a href="https://www.biostars.org/p/365086/#365131" rel="nofollow noreferrer">tells</a> you, the non coding region of a genome is the complement of the coding regions. Coding regions have its own feature in the gtf file. You can get them with <code>$ awk -v FS=&quot;\t&quot; '$3==&quot;CDS&quot;' gencode.gtf</code>. Reading the manual for <a href="https://bedtools.readthedocs.io/en/latest/content/tools/complement.html" rel="nofollow noreferrer">bedtools complement</a> is your task.</p>

CC BY-SA 4.0
2019-02-22T18:24:09.483Z
Sorry but your commands return nothing, I mean not working returning empty file
Zizogolu
CC BY-SA 4.0
2019-02-22T18:37:55.540Z
The gtf file the OP has linked to includes non-coding transcripts (LINCs, pseudogenes, tRNAs etc). I am guessing this is what they're after.
terdon
CC BY-SA 4.0
2019-02-22T18:43:51.320Z
@FereshTeh if you run the command on the file you link to, it most certainly produces output. If it doesn't, you are using another file or have somehow modified the file.
terdon
CC BY-SA 4.0
2019-02-22T12:50:18.610Z
2021-05-23T12:31:30.700Z
2021-05-23T12:31:30.700Z
finswimmer
<p>This isn't a problem that's easily solved with awk. It's not like you're extracting a feature that's annotated in the GTF file. Instead, you want the <em>empty space</em> between annotated features.</p>

<p>A few years ago I wrote a program called <a href="https://aegean.readthedocs.io/en/stable/locuspocus.html" rel="nofollow noreferrer">LocusPocus</a> for a similar task. It uses a gene annotation to break down a genome into gene loci and intergenic regions. It handles overlapping annotations and other weirdness pretty robustly. The output will include both coding regions and non-coding regions, but you can identify the intergenic spaces as those with <code>iLocus_type</code> equal to <code>iiLocus</code> or <code>fiLocus</code>.</p>

<p><strong>Note</strong>: the <code>--delta</code> parameter will extend each gene/transcript by 500bp by default.</p>

<p><strong>Caveat</strong>: the program only accepts GFF3 input by default. Hopefully it won't be too hard to convert your GTF to GFF3.</p>

<p><strong>Another caveat</strong>: eventual interpretation of these data will depend on what features are annotated in the genome and which annotations you include vs ignore. Do you want your non-coding regions to include non-coding genes, or should these be treated separately? Some non-coding regions will be full of transposable elements and other repetitive DNA, while others will have enhancers, promoters, or other regulatory elements. It's important to tread carefully before you jump to any conclusions.</p>

CC BY-SA 4.0
2019-02-22T19:32:57.617Z
Absolutely brilliant name! :)
terdon
CC BY-SA 4.0
2019-02-22T19:03:51.273Z
2019-02-22T19:14:00.553Z
2019-02-22T19:14:00.553Z
Daniel Standage
<p>If you want all transcripts from that gtf file whose type isn't "protein_coding", you can use almost the same command, just change the <code>==</code> ("is") to <code>!=</code> ("isn't"): </p>

<pre><code>awk '{if(<span class="math-container">$3=="transcript" &amp;&amp; $</span>20!="\"protein_coding\";"){print $0}}' gencode.gtf 
</code></pre>

<p>Or, a simpler version:</p>

<pre><code>awk '<span class="math-container">$3=="transcript" &amp;&amp; $</span>20!="\"protein_coding\";"' gencode.gtf 
</code></pre>

<p>Note that this will not include any of the havana transcripts in the file, but I am assuming that's what you want since that's what your original command did. </p>

<p>Specifically, the command will return the following types of transcript (the numbers on the left are the number of such transcripts in the file):</p>

<pre><code>awk '<span class="math-container">$3=="transcript" &amp;&amp; $</span>20!="\"protein_coding\";"{print $20}' gencode.gtf  | sort | uniq -c | sort -nk1
      1 "translated_processed_pseudogene";
      2 "Mt_rRNA";
      3 "IG_J_pseudogene";
      3 "TR_D_gene";
      4 "TR_J_pseudogene";
      5 "TR_C_gene";
     10 "IG_C_pseudogene";
     18 "IG_C_gene";
     18 "IG_J_gene";
     22 "Mt_tRNA";
     25 "3prime_overlapping_ncrna";
     27 "TR_V_pseudogene";
     37 "IG_D_gene";
     58 "non_stop_decay";
     59 "polymorphic_pseudogene";
     74 "TR_J_gene";
     97 "TR_V_gene";
    144 "IG_V_gene";
    182 "unitary_pseudogene";
    196 "IG_V_pseudogene";
    330 "sense_overlapping";
    387 "pseudogene";
    442 "transcribed_processed_pseudogene";
    531 "rRNA";
    802 "sense_intronic";
    860 "transcribed_unprocessed_pseudogene";
   1529 "snoRNA";
   1923 "snRNA";
   2050 "misc_RNA";
   2549 "unprocessed_pseudogene";
   3116 "miRNA";
   9710 "antisense";
  10623 "processed_pseudogene";
  11780 "lincRNA";
  13052 "nonsense_mediated_decay";
  25955 "retained_intron";
  28082 "processed_transcript";
</code></pre>

<p>You might also want to remove that "translated_processed_pseudogene" since that is actually translated into protein and is therefore technically coding:</p>

<pre><code>awk '<span class="math-container">$3=="transcript" &amp;&amp; 
     $</span>20!="\"protein_coding\";" &amp;&amp;
     $20!="\"translated_processed_pseudogene\";"' gencode.gtf  
</code></pre>

CC BY-SA 4.0
2019-02-22T20:29:07.750Z
Thanks a lot, really thank you for saving me I could not solve that myself.
Zizogolu
CC BY-SA 4.0
2019-02-22T18:34:06.030Z
2019-02-22T20:22:06.987Z
2019-02-22T20:22:06.987Z
terdon
<p>I have <a href="ftp://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_19/gencode.v19.annotation.gtf.gz" rel="nofollow noreferrer">this</a> GTF file and I use the command below on a Linux machine to extract the coding regions of the genome:</p>
<pre><code>awk '{if(<span class="math-container">$3=="transcript" &amp;&amp; $</span>20==&quot;\&quot;protein_coding\&quot;;&quot;){print $0}}' gencode.gtf
</code></pre>
<p>How I could do the inverse and keep only non coding regions?</p>
<p>I need non coding regions of human genome, but for asking my question here I referred to coding parts too.</p>
<p>After googling I see I actually need enhancers, promoters, or other regulatory elements of human genome to find cancer driver genes placed in these regions.</p>
<p>Likely non-coding regions of genome are here:</p>
<p><a href="https://elifesciences.org/download/aHR0cHM6Ly9jZG4uZWxpZmVzY2llbmNlcy5vcmcvYXJ0aWNsZXMvMjE3NzgvZWxpZmUtMjE3Nzgtc3VwcDQtdjMueGxzeA==/elife-21778-supp4-v3.xlsx?_hash=KQi5jfO3kT2c4Qw44j4Rg6YAyCBQilYuWHVYXcRDuuo%3D" rel="nofollow noreferrer">https://elifesciences.org/download/aHR0cHM6Ly9jZG4uZWxpZmVzY2llbmNlcy5vcmcvYXJ0aWNsZXMvMjE3NzgvZWxpZmUtMjE3Nzgtc3VwcDQtdjMueGxzeA==/elife-21778-supp4-v3.xlsx?_hash=KQi5jfO3kT2c4Qw44j4Rg6YAyCBQilYuWHVYXcRDuuo%3D</a></p>

<sequence-annotation><genome><gtf><text-processing><interval>
Identify non-coding regions from a genome annotation
# Identify non-coding regions from a genome annotation

(Asked by: username_0 on 2019-02-22)

I have this GTF file and I use the command below on a Linux machine to extract the coding regions of the genome:
awk '{if($3=="transcript" && $20=="\"protein_coding\";"){print $0}}' gencode.gtf

How I could do the inverse and keep only non coding regions?
I need non coding regions of human genome, but for asking my question here I referred to coding parts too.
After googling I see I actually need enhancers, promoters, or other regulatory elements of human genome to find cancer driver genes placed in these regions.
Likely non-coding regions of genome are here:
https://elifesciences.org/download/aHR0cHM6Ly9jZG4uZWxpZmVzY2llbmNlcy5vcmcvYXJ0aWNsZXMvMjE3NzgvZWxpZmUtMjE3Nzgtc3VwcDQtdjMueGxzeA==/elife-21778-supp4-v3.xlsx?_hash=KQi5jfO3kT2c4Qw44j4Rg6YAyCBQilYuWHVYXcRDuuo%3D

**Tags:** sequence-annotation, genome, gtf, text-processing, interval

---

## 3 answers

### Answer by username_1 on 2019-02-22. Score: 4

Getting the non coding regions of a protein coding transcript, sounds like you are looking for UTR.
UTR has its own feature in the gtf file. So you can do this:
$ awk -v FS="\t" '$3=="UTR"' gencode.gtf

If the gtf file is compressed use this instead:
$ zcat gencode.gtf.gz | awk -v FS="\t" '$3=="UTR"'

BTW: Why are you using such an old release of gencode? The current version is v29.
As @Wouter tells you, the non coding region of a genome is the complement of the coding regions. Coding regions have its own feature in the gtf file. You can get them with $ awk -v FS="\t" '$3=="CDS"' gencode.gtf. Reading the manual for bedtools complement is your task.

> **Comments:**
> **username_0**: Sorry but your commands return nothing, I mean not working returning empty file  
> **username_2**: The gtf file the OP has linked to includes non-coding transcripts (LINCs, pseudogenes, tRNAs etc). I am guessing this is what they're after.  
> **username_2**: @FereshTeh if you run the command on the file you link to, it most certainly produces output. If it doesn't, you are using another file or have somehow modified the file.  

---

### Answer by username_3 on 2019-02-22. Score: 3

This isn't a problem that's easily solved with awk. It's not like you're extracting a feature that's annotated in the GTF file. Instead, you want the *empty space* between annotated features.

A few years ago I wrote a program called [LocusPocus](https://aegean.readthedocs.io/en/stable/locuspocus.html) for a similar task. It uses a gene annotation to break down a genome into gene loci and intergenic regions. It handles overlapping annotations and other weirdness pretty robustly. The output will include both coding regions and non-coding regions, but you can identify the intergenic spaces as those with `iLocus_type` equal to `iiLocus` or `fiLocus`.

**Note**: the `--delta` parameter will extend each gene/transcript by 500bp by default.

**Caveat**: the program only accepts GFF3 input by default. Hopefully it won't be too hard to convert your GTF to GFF3.

**Another caveat**: eventual interpretation of these data will depend on what features are annotated in the genome and which annotations you include vs ignore. Do you want your non-coding regions to include non-coding genes, or should these be treated separately? Some non-coding regions will be full of transposable elements and other repetitive DNA, while others will have enhancers, promoters, or other regulatory elements. It's important to tread carefully before you jump to any conclusions.

> **Comments:**
> **username_2**: Absolutely brilliant name! :)  

---

### Answer by username_2 on 2019-02-22. Score: 2

If you want all transcripts from that gtf file whose type isn't "protein_coding", you can use almost the same command, just change the == ("is") to != ("isn't"): 
awk '{if($3=="transcript" && $20!="\"protein_coding\";"){print $0}}' gencode.gtf 

Or, a simpler version:
awk '$3=="transcript" && $20!="\"protein_coding\";"' gencode.gtf 

Note that this will not include any of the havana transcripts in the file, but I am assuming that's what you want since that's what your original command did. 
Specifically, the command will return the following types of transcript (the numbers on the left are the number of such transcripts in the file):
awk '$3=="transcript" && $20!="\"protein_coding\";"{print $20}' gencode.gtf  | sort | uniq -c | sort -nk1
      1 "translated_processed_pseudogene";
      2 "Mt_rRNA";
      3 "IG_J_pseudogene";
      3 "TR_D_gene";
      4 "TR_J_pseudogene";
      5 "TR_C_gene";
     10 "IG_C_pseudogene";
     18 "IG_C_gene";
     18 "IG_J_gene";
     22 "Mt_tRNA";
     25 "3prime_overlapping_ncrna";
     27 "TR_V_pseudogene";
     37 "IG_D_gene";
     58 "non_stop_decay";
     59 "polymorphic_pseudogene";
     74 "TR_J_gene";
     97 "TR_V_gene";
    144 "IG_V_gene";
    182 "unitary_pseudogene";
    196 "IG_V_pseudogene";
    330 "sense_overlapping";
    387 "pseudogene";
    442 "transcribed_processed_pseudogene";
    531 "rRNA";
    802 "sense_intronic";
    860 "transcribed_unprocessed_pseudogene";
   1529 "snoRNA";
   1923 "snRNA";
   2050 "misc_RNA";
   2549 "unprocessed_pseudogene";
   3116 "miRNA";
   9710 "antisense";
  10623 "processed_pseudogene";
  11780 "lincRNA";
  13052 "nonsense_mediated_decay";
  25955 "retained_intron";
  28082 "processed_transcript";

You might also want to remove that "translated_processed_pseudogene" since that is actually translated into protein and is therefore technically coding:
awk '$3=="transcript" && 
     $20!="\"protein_coding\";" &&
     $20!="\"translated_processed_pseudogene\";"' gencode.gtf

> **Comments:**
> **username_0**: Thanks a lot, really thank you for saving me I could not solve that myself.  

---

