Hi,
I am trying to convert a Canine gene annotation (GTF) file downloaded from Ensembl to BED file using the gtf2bed tool within the BEDOPS application.  Using this command gives an error:

$ gtf2bed < Canis_familiaris.CanFam3.1.85_noheader.gtf > Canis_familiaris.CanFam3.1.85_noheader.bed

Error: Potentially missing gene or transcript ID from GTF attributes (malformed GTF at line [1]?)

I checked the first few lines of the GTF file and it seems to match up with the required format:

 $ head Canis_familiaris.CanFam3.1.85_noheader.gtf

X       ensembl gene    1575    5716    .       +       .       gene_id "ENSCAFG00000010935"; gene_version "3"; gene_source "ensembl"; gene_biotype "protein_coding";

X       ensembl transcript      1575    5716    .       +       .       gene_id "ENSCAFG00000010935"; gene_version "3"; transcript_id "ENSCAFT00000017396"; transcript_version "3"; gene_source "ensembl"; gene_biotype "protein_coding"; transcript_source "ensembl"; transcript_biotype "protein_coding";

...

I looked at the source code on github for this tool and can see that is check for gene or transcript id and if not present gives this error.  But the gene_id is present here in the first line, so not sure how it is reaching the error condition.

I would appreciate any help with troubleshooting this error.

Thank you,
- Pankaj
**Note: This should no longer be an error with *gtf2bed* v2.4.40 and on.**

----------

I added more stringent GTF format validation to BEDOPS v2.4.20. 

The error suggests that the first line is missing the `transcript_id` field. It has a `gene_id` field, as you note, but no `transcript_id` field. The GTF 2.2 specification indicates that this field is mandatory, though its value can be an empty string. 

There are a couple solutions:

1. Use an older version of `gtf2bed` that doesn't apply this validation check (e.g., 2.4.19 or earlier)
2. Or, modify the GTF and add a placeholder field where none exists

I suggest the second solution. You could do the following:

    $ awk '{ if ($0 ~ "transcript_id") print $0; else print $0" transcript_id \"\";"; }' input.gtf | gtf2bed - > output.bed

This adds `transcript_id "";` to lines in the GTF that do not contain that field, and leaves other lines unchanged. 

The GTF that comes out of this `awk` statement is more valid, enough to get through the conversion step, and so it can be piped to `gtf2bed` to get BED as output.