<p>I found <a href="https://github.com/openvax/gtfparse/issues/19" rel="nofollow noreferrer">this</a> GTF parser for Python. However, it does not work with Scallop's GTF file:</p>
<pre><code>chr01_pilon_pilon       scallop transcript      168145  169166  1000    .       .       gene_id &quot;gene.1.0&quot;; transcript_id &quot;gene.1.0.0&quot;; RPKM &quot;9.8016&quot;; cov &quot;27.2554&quot;;
chr01_pilon_pilon       scallop exon    168145  169166  1000    .       .       gene_id &quot;gene.1.0&quot;; transcript_id &quot;gene.1.0.0&quot;; exon &quot;1&quot;;
chr01_pilon_pilon       scallop transcript      410672  444190  1000    +       .       gene_id &quot;gene.3.0&quot;; transcript_id &quot;gene.3.0.1&quot;; RPKM &quot;0.5936&quot;; cov &quot;1.6506&quot;;
chr01_pilon_pilon       scallop exon    410672  411205  1000    +       .       gene_id &quot;gene.3.0&quot;; transcript_id &quot;gene.3.0.1&quot;; exon &quot;1&quot;;
chr01_pilon_pilon       scallop exon    411326  411482  1000    +       .       gene_id &quot;gene.3.0&quot;; transcript_id &quot;gene.3.0.1&quot;; exon &quot;2&quot;;
chr01_pilon_pilon       scallop exon    444085  444190  1000    +       .       gene_id &quot;gene.3.0&quot;; transcript_id &quot;gene.3.0.1&quot;; exon &quot;3&quot;;
chr01_pilon_pilon       scallop transcript      678431  681781  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.1&quot;; RPKM &quot;0.4733&quot;; cov &quot;1.3162&quot;;
chr01_pilon_pilon       scallop exon    678431  678822  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.1&quot;; exon &quot;1&quot;;
chr01_pilon_pilon       scallop exon    678917  679068  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.1&quot;; exon &quot;2&quot;;
chr01_pilon_pilon       scallop exon    680616  681781  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.1&quot;; exon &quot;3&quot;;
chr01_pilon_pilon       scallop transcript      678431  685851  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.2&quot;; RPKM &quot;7.9200&quot;; cov &quot;22.0230&quot;;
chr01_pilon_pilon       scallop exon    678431  678822  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.2&quot;; exon &quot;1&quot;;
chr01_pilon_pilon       scallop exon    678917  679068  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.2&quot;; exon &quot;2&quot;;
chr01_pilon_pilon       scallop exon    680616  681627  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.2&quot;; exon &quot;3&quot;;
chr01_pilon_pilon       scallop exon    681874  681965  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.2&quot;; exon &quot;4&quot;;
chr01_pilon_pilon       scallop exon    683200  683274  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.2&quot;; exon &quot;5&quot;;
chr01_pilon_pilon       scallop exon    683744  683805  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.2&quot;; exon &quot;6&quot;;
chr01_pilon_pilon       scallop exon    684640  684709  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.2&quot;; exon &quot;7&quot;;
chr01_pilon_pilon       scallop exon    684842  685851  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.2&quot;; exon &quot;8&quot;;
chr01_pilon_pilon       scallop transcript      681834  685851  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.3&quot;; RPKM &quot;1.1177&quot;; cov &quot;3.1080&quot;;
chr01_pilon_pilon       scallop exon    681834  681965  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.3&quot;; exon &quot;1&quot;;
chr01_pilon_pilon       scallop exon    683200  683274  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.3&quot;; exon &quot;2&quot;;
chr01_pilon_pilon       scallop exon    683744  683805  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.3&quot;; exon &quot;3&quot;;
chr01_pilon_pilon       scallop exon    684640  684709  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.3&quot;; exon &quot;4&quot;;
chr01_pilon_pilon       scallop exon    684842  685851  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.3&quot;; exon &quot;5&quot;;
chr01_pilon_pilon       scallop transcript      683032  685851  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.0&quot;; RPKM &quot;0.6001&quot;; cov &quot;1.6686&quot;;
chr01_pilon_pilon       scallop exon    683032  683274  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.0&quot;; exon &quot;1&quot;;
chr01_pilon_pilon       scallop exon    683744  683805  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.0&quot;; exon &quot;2&quot;;
chr01_pilon_pilon       scallop exon    684640  684709  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.0&quot;; exon &quot;3&quot;;
chr01_pilon_pilon       scallop exon    684842  685851  1000    +       .       gene_id &quot;gene.6.0&quot;; transcript_id &quot;gene.6.0.0&quot;; exon &quot;4&quot;;
</code></pre>
<p>However, the below code caused the following errors:</p>
<pre><code>Traceback (most recent call last):
  File &quot;/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/gtfparse/read_gtf.py&quot;, line 103, in parse_gtf
    for df in chunk_iterator:
  File &quot;/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/pandas/io/parsers.py&quot;, line 1128, in __next__
    return self.get_chunk()
  File &quot;/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/pandas/io/parsers.py&quot;, line 1188, in get_chunk
    return self.read(nrows=size)
  File &quot;/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/pandas/io/parsers.py&quot;, line 1154, in read
    ret = self._engine.read(nrows)
  File &quot;/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/pandas/io/parsers.py&quot;, line 2059, in read
    data = self._reader.read(nrows)
  File &quot;pandas/_libs/parsers.pyx&quot;, line 881, in pandas._libs.parsers.TextReader.read
  File &quot;pandas/_libs/parsers.pyx&quot;, line 908, in pandas._libs.parsers.TextReader._read_low_memory
  File &quot;pandas/_libs/parsers.pyx&quot;, line 973, in pandas._libs.parsers.TextReader._read_rows
  File &quot;pandas/_libs/parsers.pyx&quot;, line 1105, in pandas._libs.parsers.TextReader._convert_column_data
  File &quot;pandas/_libs/parsers.pyx&quot;, line 1136, in pandas._libs.parsers.TextReader._convert_tokens
  File &quot;pandas/_libs/parsers.pyx&quot;, line 1232, in pandas._libs.parsers.TextReader._convert_with_dtype
ValueError: Integer column has NA values in column 3

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;/Users/lorencm/projects/bioinf-scripts/reduceIsoforms.py&quot;, line 24, in &lt;module&gt;
    df = read_gtf(&quot;data/hybrid.gtf&quot;)
  File &quot;/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/gtfparse/read_gtf.py&quot;, line 211, in read_gtf
    restrict_attribute_columns=usecols)
  File &quot;/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/gtfparse/read_gtf.py&quot;, line 154, in parse_gtf_and_expand_attributes
    features=features)
  File &quot;/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/gtfparse/read_gtf.py&quot;, line 122, in parse_gtf
    raise ParsingError(str(e))
gtfparse.parsing_error.ParsingError: Integer column has NA values in column 3
</code></pre>
<p>This is the code:</p>
<pre><code>df = read_gtf(&quot;data/hybrid.gtf&quot;)
df_genes = df[df[&quot;feature&quot;] == &quot;gene&quot;]
print(df_genes)
</code></pre>
<p>Thank you in advance,</p>

CC BY-SA 4.0
2020-09-09T08:24:30.847Z
Your GTF file contains NA values in the 3rd column. You can use a subset of the GTF file, for example what you have copy pasted above (seems like there are no NAs) and re-run your script to see if it is the GTF file or the script that is causing the error. I can't think of a reason for NAs in the coordinate columns though!
haci
CC BY-SA 4.0
2020-09-10T03:24:09.447Z
Thank you, I tried a different GTF file and this error disappeared. However, I got a new [one](https://bioinformatics.stackexchange.com/questions/14333/gtf-parser-returned-empty-dataframe)
user977828
CC BY-SA 4.0
2021-02-28T19:52:11.817Z
Do you have a link to the gtf-file? `import pyranges as pr; pr.read_gtf("file.gtf")` might work.
The Unfun Cat
<python><gtf><parsing>
GTF parser for Python
# GTF parser for Python

(Asked by: username_0 on 2020-09-08)

I found this GTF parser for Python. However, it does not work with Scallop's GTF file:
chr01_pilon_pilon       scallop transcript      168145  169166  1000    .       .       gene_id "gene.1.0"; transcript_id "gene.1.0.0"; RPKM "9.8016"; cov "27.2554";
chr01_pilon_pilon       scallop exon    168145  169166  1000    .       .       gene_id "gene.1.0"; transcript_id "gene.1.0.0"; exon "1";
chr01_pilon_pilon       scallop transcript      410672  444190  1000    +       .       gene_id "gene.3.0"; transcript_id "gene.3.0.1"; RPKM "0.5936"; cov "1.6506";
chr01_pilon_pilon       scallop exon    410672  411205  1000    +       .       gene_id "gene.3.0"; transcript_id "gene.3.0.1"; exon "1";
chr01_pilon_pilon       scallop exon    411326  411482  1000    +       .       gene_id "gene.3.0"; transcript_id "gene.3.0.1"; exon "2";
chr01_pilon_pilon       scallop exon    444085  444190  1000    +       .       gene_id "gene.3.0"; transcript_id "gene.3.0.1"; exon "3";
chr01_pilon_pilon       scallop transcript      678431  681781  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.1"; RPKM "0.4733"; cov "1.3162";
chr01_pilon_pilon       scallop exon    678431  678822  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.1"; exon "1";
chr01_pilon_pilon       scallop exon    678917  679068  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.1"; exon "2";
chr01_pilon_pilon       scallop exon    680616  681781  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.1"; exon "3";
chr01_pilon_pilon       scallop transcript      678431  685851  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.2"; RPKM "7.9200"; cov "22.0230";
chr01_pilon_pilon       scallop exon    678431  678822  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.2"; exon "1";
chr01_pilon_pilon       scallop exon    678917  679068  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.2"; exon "2";
chr01_pilon_pilon       scallop exon    680616  681627  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.2"; exon "3";
chr01_pilon_pilon       scallop exon    681874  681965  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.2"; exon "4";
chr01_pilon_pilon       scallop exon    683200  683274  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.2"; exon "5";
chr01_pilon_pilon       scallop exon    683744  683805  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.2"; exon "6";
chr01_pilon_pilon       scallop exon    684640  684709  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.2"; exon "7";
chr01_pilon_pilon       scallop exon    684842  685851  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.2"; exon "8";
chr01_pilon_pilon       scallop transcript      681834  685851  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.3"; RPKM "1.1177"; cov "3.1080";
chr01_pilon_pilon       scallop exon    681834  681965  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.3"; exon "1";
chr01_pilon_pilon       scallop exon    683200  683274  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.3"; exon "2";
chr01_pilon_pilon       scallop exon    683744  683805  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.3"; exon "3";
chr01_pilon_pilon       scallop exon    684640  684709  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.3"; exon "4";
chr01_pilon_pilon       scallop exon    684842  685851  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.3"; exon "5";
chr01_pilon_pilon       scallop transcript      683032  685851  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.0"; RPKM "0.6001"; cov "1.6686";
chr01_pilon_pilon       scallop exon    683032  683274  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.0"; exon "1";
chr01_pilon_pilon       scallop exon    683744  683805  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.0"; exon "2";
chr01_pilon_pilon       scallop exon    684640  684709  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.0"; exon "3";
chr01_pilon_pilon       scallop exon    684842  685851  1000    +       .       gene_id "gene.6.0"; transcript_id "gene.6.0.0"; exon "4";

However, the below code caused the following errors:
Traceback (most recent call last):
  File "/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/gtfparse/read_gtf.py", line 103, in parse_gtf
    for df in chunk_iterator:
  File "/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/pandas/io/parsers.py", line 1128, in __next__
    return self.get_chunk()
  File "/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/pandas/io/parsers.py", line 1188, in get_chunk
    return self.read(nrows=size)
  File "/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/pandas/io/parsers.py", line 1154, in read
    ret = self._engine.read(nrows)
  File "/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/pandas/io/parsers.py", line 2059, in read
    data = self._reader.read(nrows)
  File "pandas/_libs/parsers.pyx", line 881, in pandas._libs.parsers.TextReader.read
  File "pandas/_libs/parsers.pyx", line 908, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas/_libs/parsers.pyx", line 973, in pandas._libs.parsers.TextReader._read_rows
  File "pandas/_libs/parsers.pyx", line 1105, in pandas._libs.parsers.TextReader._convert_column_data
  File "pandas/_libs/parsers.pyx", line 1136, in pandas._libs.parsers.TextReader._convert_tokens
  File "pandas/_libs/parsers.pyx", line 1232, in pandas._libs.parsers.TextReader._convert_with_dtype
ValueError: Integer column has NA values in column 3

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/lorencm/projects/bioinf-scripts/reduceIsoforms.py", line 24, in 
    df = read_gtf("data/hybrid.gtf")
  File "/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/gtfparse/read_gtf.py", line 211, in read_gtf
    restrict_attribute_columns=usecols)
  File "/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/gtfparse/read_gtf.py", line 154, in parse_gtf_and_expand_attributes
    features=features)
  File "/anaconda/envs/bioinf-scripts/lib/python3.7/site-packages/gtfparse/read_gtf.py", line 122, in parse_gtf
    raise ParsingError(str(e))
gtfparse.parsing_error.ParsingError: Integer column has NA values in column 3

This is the code:
df = read_gtf("data/hybrid.gtf")
df_genes = df[df["feature"] == "gene"]
print(df_genes)

Thank you in advance,

**Tags:** python, gtf, parsing
> **Comments:**
> **username_1**: Your GTF file contains NA values in the 3rd column. You can use a subset of the GTF file, for example what you have copy pasted above (seems like there are no NAs) and re-run your script to see if it is the GTF file or the script that is causing the error. I can't think of a reason for NAs in the coordinate columns though!  
> **username_0**: Thank you, I tried a different GTF file and this error disappeared. However, I got a new [one](https://bioinformatics.stackexchange.com/questions/14333/gtf-parser-returned-empty-dataframe)  
> **username_2**: Do you have a link to the gtf-file? `import pyranges as pr; pr.read_gtf("file.gtf")` might work.  

---

## 0 answers

