0

I have a GTF file (tab-delimited) and a list of gene name in another text file. I was wondering how I can obtain the information of the gene list from a GTF file with grep, awk? I tried some commands, but none of them was successful.

Here is an example of gtf file:

#!genome-build GRCh37.p13
#!genome-version GRCh37
#!genome-date 2009-02
#!genome-build-accession NCBI:GCA_000001405.14
#!genebuild-last-updated 2013-09
1   pseudogene  gene    11869   14412   .   +   .   gene_id "ENSG00000223972"; gene_name "DDX11L1"; gene_source "ensembl_havana"; gene_biotype "pseudogene";
1   processed_transcript    transcript  11869   14409   .   +   .   gene_id "ENSG00000223972"; transcript_id "ENST00000456328"; gene_name "DDX11L1"; gene_source "ensembl_havana"; gene_biotype "pseudogene"; transcript_name "DDX11L1-002"; transcript_source "havana";
1   processed_transcript    exon    11869   12227   .   +   .   gene_id "ENSG00000223972"; transcript_id "ENST00000456328"; exon_number "1"; gene_name "DDX11L1"; gene_source "ensembl_havana"; gene_biotype "pseudogene"; transcript_name "DDX11L1-002"; transcript_source "havana"; exon_id "ENSE00002234944";
1   processed_transcript    exon    12613   12721   .   +   .   gene_id "ENSG00000223972"; transcript_id "ENST00000456328"; exon_number "2"; gene_name "DDX11L1"; gene_source "ensembl_havana"; gene_biotype "pseudogene"; transcript_name "DDX11L1-002"; transcript_source "havana"; exon_id "ENSE00003582793";
1   processed_transcript    exon    13221   14409   .   +   .   gene_id "ENSG00000223972"; transcript_id "ENST00000456328"; exon_number "3"; gene_name "DDX11L1"; gene_source "ensembl_havana"; gene_biotype "pseudogene"; transcript_name "DDX11L1-002"; transcript_source "havana"; exon_id "ENSE00002312635";
10  protein_coding  exon    114710009   114710704   .   +   .   gene_id "ENSG00000148737"; transcript_id "ENST00000355995"; exon_number "1"; gene_name "TCF7L2"; gene_source "ensembl_havana"; gene_biotype "protein_coding"; transcript_name "TCF7L2-203"; transcript_source "ensembl"; exon_id "ENSE00002258101";
10  protein_coding  CDS 114710516   114710704   .   +   0   gene_id "ENSG00000148737"; transcript_id "ENST00000355995"; exon_number "1"; gene_name "TCF7L2"; gene_source "ensembl_havana"; gene_biotype "protein_coding"; transcript_name "TCF7L2-203"; transcript_source "ensembl"; protein_id "ENSP00000348274";

and here is an example of a list of gene name in the text file (which I want to extract all their related information from gtf file).

DDX11L1
TCF7L2

Thank you

4
  • 1
    Hello, and welcome to U&L! You are much more likely to get the help you are seeking if you provide three things: An example of the input you have, an example of the output you desire given that input, and a presentation of what you have already tried, and how it did not work as expected or intended.
    – DopeGhoti
    Oct 2, 2018 at 17:19
  • 1
    As most of the regulars here are not bioinformaticians, I would suggest giving an example of a small part of your GTF file along with a portion of the gene list (just enough that we may copy and paste it for testing purposes). As tabs and spaces are not distinguishable from each other in a question, also mention that a GTF file is tab-delimited by default.
    – Kusalananda
    Oct 2, 2018 at 17:30
  • Thanks for your comments, I edited the original question.
    – Mary
    Oct 2, 2018 at 17:57
  • Per your comment on my deleted answer, I once again ask: provide an example of the desired output as well as the two input streams you have provided.
    – DopeGhoti
    Oct 2, 2018 at 18:45

2 Answers 2

1

Still not clear. You want to list all lines for which the gene_name is found in the second text file? For this, try

awk 'NR == FNR {T[" gene_name \"" $0 "\""]; next} {for (t in T) if ($0 ~ t) print}' file2 file1
8
  • Thank you. Yes, I tested it on the short example file, it worked well, but it was very slow. Please kindly tell me if there is any possibility to increase the speed?
    – Mary
    Oct 2, 2018 at 19:56
  • What do you mean by "very slow"? Timed execution on my linux Ubuntu 18.04 with your samples yields 0.045 seconds.
    – RudiC
    Oct 2, 2018 at 21:08
  • Hi RudiC, really, 0.045s!, I tested the same example on our cluster (redhat) and it took about 5 minutes to finish, so strange, why?!
    – Mary
    Oct 3, 2018 at 20:13
  • Are you using the samples given above or "real" files of MB or GB size?
    – RudiC
    Oct 3, 2018 at 20:15
  • I just extract the information of two example genes (DDX11L1, TCF7L2) from the real GTF file with 900 MB in size. However, my real gene list contains about 4000 genes that I want to extract their related information from the real GTF file. Imagin how long it!
    – Mary
    Oct 3, 2018 at 21:30
0

If you have one file with the short list of data for which you want the details, you can do a simple grep. Say for example that your list of each datum is in a file called needles.list, and your collection of data are in a file called haystack.gtf. You can then:

$ grep -f needles.list haystack.gtf
1
  • I tried it before, it didn't work without returning any error.
    – Mary
    Oct 2, 2018 at 19:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .