Thank you for this. This is what I used for my command:
gunzip -c /Homo_sapiens.GRCh38.89.gtf.gz' |awk -F'\t' -v OFS='\t' '$3~/gene/{print $0, $5-$4}'|sort -t $'\t' -k10,10nr | head -n 1
AND THE OUTPUT 7 ensembl_havana gene 146116002 148420998 . + . gene_id "ENSG00000174469"; gene_version "19"; gene_name "CNTNAP2"; gene_source "ensembl_havana"; gene_biotype "protein_coding"; 2304996
I think I understand most of your code, below is my understanding:
zcat is basically same as gunzip --c
awk -F'\t' -v OFS ==> split files on tabs, OFS is for output field
$3~/gene/ ==> 3rd column number (i.e., feature type), we specify /gene/
{print $0, $5-$4} ==> $0 is for the entire input line, $5 is the end cord. position, $4 is the start cord. position
sort -t ==> sort considering a delimiter (in this case a pipe)
$'\t' -k10,10nr | ==> I'm really lost on this section. I believe the \t' is to split files on tabs? The nr is for number of rows?
head -n 1 ==> head outputting text?
How did I do?
Do you want the longest transcript in terms of DNA length or RNA length? There's likely a large difference between the two. Note that you should just use something like python to make your life easier.
Longest gene:
Output (gene symbol and length):
Gene with longest transcript and exons within transcript:
output (by gene symbol, transcripts and number of exons in each transcript)
datamash is gnu statistics library and available in all linux distro repos.
Many thanks, as you can see in my post below, I also came up with the 'CNTNAP2' as the longest gene.
Very respectfully,