<p>@Jim Hat</p>
<p>I took a stab at this given the example files you included.</p>
<p>If the 'list.txt' file looks like this:</p>
<pre><code>Solyc00g019980
Solyc01g005020
</code></pre>
<p>And the data.gff file looks like this:</p>
<pre><code>SL4.0ch01   maker_ITAG  gene    46201   59605   .   -   .   ID=gene:Solyc01g005020.3;Alias=Solyc01g005020;Name=Solyc01g005020.3;length=13404
SL4.0ch01   maker_ITAG  mRNA    46201   59605   .   -   .   ID=mRNA:Solyc01g005020.3.1;Parent=gene:Solyc01g005020.3;Name=Solyc01g005020.3.1;Note=Salt Overly Sensitive 1;_AED=0.25;_QI=241|1|1|1|0|0|23|311|1151;_eAED=0.25;Ontology_term=GO:0006812,GO:0015299,GO:0016021,GO:0055085
SL4.0ch01   maker_ITAG  three_prime_UTR 46201   46511   .   -   .   ID=three_prime_UTR:Solyc01g005020.3.1.0;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    46201   46844   .   -   .   ID=exon:Solyc01g005020.3.1.1;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  CDS 46512   46844   .   -   0   ID=CDS:Solyc01g005020.3.1.1;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    47281   47585   .   -   .   ID=exon:Solyc01g005020.3.1.2;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  CDS 47281   47585   .   -   2   ID=CDS:Solyc01g005020.3.1.2;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    48276   48543   .   -   .   ID=exon:Solyc01g005020.3.1.3;Parent=mRNA:Solyc01g005020.3.1
</code></pre>
<p>(Note I removed the **s, which I assumed were added for emphasis)</p>
<p>You can do the following:</p>
<pre><code>aliasNames=<span class="math-container">$(grep -f list.txt data.gff | cut -d':' -f2 | cut -d';' -f1)
ontologyTerms=$</span>(grep -f list.txt data.gff | cut -d';' -f 8 | cut -d'=' -f2)
paste &lt;(echo &quot;<span class="math-container">$aliasNames") &lt;(echo "$</span>ontologyTerms&quot;)
</code></pre>
<p>The first line filters the file based on your list and then extracts the alias names from the filtered GFF file. The second line filters the GFF and extracts the ontology terms (after the equal sign). And the third line joins the two as columns.</p>
<p>The result that is printed to the screen is:</p>
<pre><code>Solyc01g005020.3
Solyc01g005020.3.1      GO:0006812,GO:0015299,GO:0016021,GO:0055085
Solyc01g005020.3.1.0
Solyc01g005020.3.1.1
Solyc01g005020.3.1.1
Solyc01g005020.3.1.2
Solyc01g005020.3.1.2
Solyc01g005020.3.1.3
</code></pre>
<p>Given the examples you included all of the lines of the GFF are included, but not all have gene ontology information.</p>

CC BY-SA 4.0
2021-03-15T15:39:16.107Z
2021-03-15T15:39:16.107Z
Helen Scott
<p>I have a text file with a list of name of genes (alias names) like this (<code>**</code> added for emphasis):</p>
<pre><code>Solyc00g019980
**Solyc01g005020**
.. 
.
</code></pre>
<p>And i have a gff file like this:</p>
<pre><code>SL4.0ch01   maker_ITAG  gene    46201   59605   .   -   .   ID=gene:Solyc01g005020.3;Alias=**Solyc01g005020**;Name=Solyc01g005020.3;length=13404
SL4.0ch01   maker_ITAG  mRNA    46201   59605   .   -   .   ID=mRNA:Solyc01g005020.3.1;Parent=gene:Solyc01g005020.3;Name=Solyc01g005020.3.1;Note=Salt Overly Sensitive 1;_AED=0.25;_QI=241|1|1|1|0|0|23|311|1151;_eAED=0.25;**Ontology_term=GO:0006812,GO:0015299,GO:0016021,GO:0055085**
SL4.0ch01   maker_ITAG  three_prime_UTR 46201   46511   .   -   .   ID=three_prime_UTR:Solyc01g005020.3.1.0;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    46201   46844   .   -   .   ID=exon:Solyc01g005020.3.1.1;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  CDS 46512   46844   .   -   0   ID=CDS:Solyc01g005020.3.1.1;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    47281   47585   .   -   .   ID=exon:Solyc01g005020.3.1.2;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  CDS 47281   47585   .   -   2   ID=CDS:Solyc01g005020.3.1.2;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    48276   48543   .   -   .   ID=exon:Solyc01g005020.3.1.3;Parent=mRNA:Solyc01g005020.3.1
</code></pre>
<p>I would like to grab only the ones i have in my list gene text file (Alias names) and the corresponding &quot;Ontology_term&quot; next to it.</p>
<p>Terminal is more convenient if there is a solution like grep or something.</p>
<p>Thanks in advance</p>
<p>edit:
i would like to get this output, as an example</p>
<pre><code>Solyc01g005070  Ontology_term=GO:0005543
Solyc01g005230  Ontology_term=GO:0008168
</code></pre>
<p>i dont mind if this is included &quot;Ontology_term=&quot;, i would prefer not to be included though</p>
<p>thanks again</p>
<p><code>grep -f list.txt data.gff</code> doesn't work for me, because it grabs all the other as well.</p>

CC BY-SA 4.0
2021-03-09T19:43:39.200Z
Are you trying to grep the Ontology term from the next line in your example? If so, that makes things a little more complicated.
Ram RS
CC BY-SA 4.0
2021-03-10T12:31:22.227Z
@JimHat your output example does not correspond to your input examples. `Solyc01g005070` and `Solyc01g005230` are not referred anywhere in your `gff` example. Thus, it's hard to relate exactly what you want exactly
user324810
<grep>
How to grep with a list of genes from a gff the GO terms
# How to grep with a list of genes from a gff the GO terms

(Asked by: username_0 on 2021-03-09)

I have a text file with a list of name of genes (alias names) like this (** added for emphasis):
Solyc00g019980
**Solyc01g005020**
.. 
.

And i have a gff file like this:
SL4.0ch01   maker_ITAG  gene    46201   59605   .   -   .   ID=gene:Solyc01g005020.3;Alias=**Solyc01g005020**;Name=Solyc01g005020.3;length=13404
SL4.0ch01   maker_ITAG  mRNA    46201   59605   .   -   .   ID=mRNA:Solyc01g005020.3.1;Parent=gene:Solyc01g005020.3;Name=Solyc01g005020.3.1;Note=Salt Overly Sensitive 1;_AED=0.25;_QI=241|1|1|1|0|0|23|311|1151;_eAED=0.25;**Ontology_term=GO:0006812,GO:0015299,GO:0016021,GO:0055085**
SL4.0ch01   maker_ITAG  three_prime_UTR 46201   46511   .   -   .   ID=three_prime_UTR:Solyc01g005020.3.1.0;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    46201   46844   .   -   .   ID=exon:Solyc01g005020.3.1.1;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  CDS 46512   46844   .   -   0   ID=CDS:Solyc01g005020.3.1.1;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    47281   47585   .   -   .   ID=exon:Solyc01g005020.3.1.2;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  CDS 47281   47585   .   -   2   ID=CDS:Solyc01g005020.3.1.2;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    48276   48543   .   -   .   ID=exon:Solyc01g005020.3.1.3;Parent=mRNA:Solyc01g005020.3.1

I would like to grab only the ones i have in my list gene text file (Alias names) and the corresponding "Ontology_term" next to it.
Terminal is more convenient if there is a solution like grep or something.
Thanks in advance
edit:
i would like to get this output, as an example
Solyc01g005070  Ontology_term=GO:0005543
Solyc01g005230  Ontology_term=GO:0008168

i dont mind if this is included "Ontology_term=", i would prefer not to be included though
thanks again
grep -f list.txt data.gff doesn't work for me, because it grabs all the other as well.

**Tags:** grep
> **Comments:**
> **username_1**: Are you trying to grep the Ontology term from the next line in your example? If so, that makes things a little more complicated.  
> **username_2**: @JimHat your output example does not correspond to your input examples. `Solyc01g005070` and `Solyc01g005230` are not referred anywhere in your `gff` example. Thus, it's hard to relate exactly what you want exactly  

---

## 1 answers

### Answer by username_3 on 2021-03-15. Score: 2

@Jim Hat
I took a stab at this given the example files you included.
If the 'list.txt' file looks like this:
Solyc00g019980
Solyc01g005020

And the data.gff file looks like this:
SL4.0ch01   maker_ITAG  gene    46201   59605   .   -   .   ID=gene:Solyc01g005020.3;Alias=Solyc01g005020;Name=Solyc01g005020.3;length=13404
SL4.0ch01   maker_ITAG  mRNA    46201   59605   .   -   .   ID=mRNA:Solyc01g005020.3.1;Parent=gene:Solyc01g005020.3;Name=Solyc01g005020.3.1;Note=Salt Overly Sensitive 1;_AED=0.25;_QI=241|1|1|1|0|0|23|311|1151;_eAED=0.25;Ontology_term=GO:0006812,GO:0015299,GO:0016021,GO:0055085
SL4.0ch01   maker_ITAG  three_prime_UTR 46201   46511   .   -   .   ID=three_prime_UTR:Solyc01g005020.3.1.0;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    46201   46844   .   -   .   ID=exon:Solyc01g005020.3.1.1;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  CDS 46512   46844   .   -   0   ID=CDS:Solyc01g005020.3.1.1;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    47281   47585   .   -   .   ID=exon:Solyc01g005020.3.1.2;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  CDS 47281   47585   .   -   2   ID=CDS:Solyc01g005020.3.1.2;Parent=mRNA:Solyc01g005020.3.1
SL4.0ch01   maker_ITAG  exon    48276   48543   .   -   .   ID=exon:Solyc01g005020.3.1.3;Parent=mRNA:Solyc01g005020.3.1

(Note I removed the **s, which I assumed were added for emphasis)
You can do the following:
aliasNames=$(grep -f list.txt data.gff | cut -d':' -f2 | cut -d';' -f1)
ontologyTerms=$(grep -f list.txt data.gff | cut -d';' -f 8 | cut -d'=' -f2)
paste <(echo "$aliasNames") <(echo "$ontologyTerms")

The first line filters the file based on your list and then extracts the alias names from the filtered GFF file. The second line filters the GFF and extracts the ontology terms (after the equal sign). And the third line joins the two as columns.
The result that is printed to the screen is:
Solyc01g005020.3
Solyc01g005020.3.1      GO:0006812,GO:0015299,GO:0016021,GO:0055085
Solyc01g005020.3.1.0
Solyc01g005020.3.1.1
Solyc01g005020.3.1.1
Solyc01g005020.3.1.2
Solyc01g005020.3.1.2
Solyc01g005020.3.1.3

Given the examples you included all of the lines of the GFF are included, but not all have gene ontology information.


---

