This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to mach gene names and source (lincRNA, antisense, protein_coding,....) with specific list of genes id?

I have a list of gene id's and I want to match those with gene names and source (lincRNA, antisense, protein_coding, ...) from Ensembl gtf file. For example this is a small part of the list as shown:

Gene id             strand
ENSG00000242959     1
ENSG00000160396     -1
ENSG00000229494     1
ENSG00000230262     -1
ENSG00000229240     -1
ENSG00000223569     1

I got help before by using awk command to match gene id with gene name, so how can we include the source with them

next-gen rna-seq r

2 answers

Take only the column 1.

awk '{ print $1 }' input_list | sort | uniq > gene_names

Now take the gene names and grep against GTF file.

while read line; do grep $line genes.gtf; done < gene_names > gene_names.gtf

This will be a bit slower but does the job. If you want a super fast program, you may need to wait for a perl/Python script.

Hi Geek,

Komal helped me by using the following awk command

awk '{                                
    for (i = 1; I <= NF; i++) {
        if ($i ~ /gene_id|gene_name/) {
            printf "%s ", $(i+1)
        }
    }
    print ""
}' Homo_sapiens.GRCh37.70.gtf | sed -e 's/"//g' -e 's/;//g' -e 's/ /\t/' | sort -k1,1 | uniq > Homo_sapiens.GRCh37.70.txt

and it works very well and I merged the result file with my file using R, So I wounder if we can add the source column in this command.

M K I have replied to you on the previous question. Also, do not duplicate your posts.

If looking for something more readable you may alternatively use gtftk the CLI of pygtftk. The gene_list.txt contains one column with any identifiers of interest related to the target key ("transcript_id" in your case)

 gtftk select_by_key -k transcript_id -f gene_list.txt -i genes.gtf -V 1   > gene_list.gtf

Best

Disclaimer: I'm the pygtftk developper.

Log in to answer this question.