agshumate/Liftoff

UnboundLocalError: local variable 'feature_db' referenced before assignment

Closed this issue · 5 comments

Hello,

I have the same error as this issue #75, however there is no _db file created that I can delete as mentioned in that issue.
This is my command. Thank you in advance for your help.

liftoff -g /apps/opt/rnaseq-pipeline/ref/hg38/hg38.ensGene.gtf -o /home/Data/A673_bionano/output/hybridscaffold_hifiasm_hic_hap1/hybrid_sc$
/gpfs0/home/opt/miniconda3/envs/local_liftoff_env/lib/python3.6/site-packages/gffutils/create.py:725: UserWarning: It appears you have a tra$
  "It appears you have a transcript feature in your GTF "
0 of 2 (0%)^M1 of 2 (50%)^M0 of 2 (0%)^M1 of 2 (50%)^M0 of 2 (0%)^M1 of 2 (50%)^M0 of 2 (0%)^M1 of 2 (50%)^M0 of 2 (0%)^M1 of 2 (50%)^M0 of 2 (0%)^M1 of 2 (50%)^$
Traceback (most recent call last):
  File "/gpfs0/home/opt/miniconda3/envs/local_liftoff_env/bin/liftoff", line 10, in <module>
    sys.exit(main())
  File "/gpfs0/home/opt/miniconda3/envs/local_liftoff_env/lib/python3.6/site-packages/liftoff/run_liftoff.py", line 10, in main
    run_all_liftoff_steps(args)
  File "/gpfs0/home/opt/miniconda3/envs/local_liftoff_env/lib/python3.6/site-packages/liftoff/run_liftoff.py", line 25, in run_all_liftoff_s$
    parent_features_to_lift)
  File "/gpfs0/home/opt/miniconda3/envs/local_liftoff_env/lib/python3.6/site-packages/liftoff/liftover_types.py", line 13, in lift_original_$
    parents_to_lift, args)
  File "/gpfs0/home/opt/miniconda3/envs/local_liftoff_env/lib/python3.6/site-packages/liftoff/extract_features.py", line 17, in extract_feat$
    feature_db = create_feature_db_connections(args)
  File "/gpfs0/home/opt/miniconda3/envs/local_liftoff_env/lib/python3.6/site-packages/liftoff/extract_features.py", line 32, in create_featu$
    feature_db = build_database(args.db, args.g, disable_transcripts, disable_genes)
  File "/gpfs0/home/opt/miniconda3/envs/local_liftoff_env/lib/python3.6/site-packages/liftoff/extract_features.py", line 47, in build_databa$
    return feature_db
UnboundLocalError: local variable 'feature_db' referenced before assignment

My liftoff version is v1.6.1

I am having a similar issue. Also a miniconda3 install, version 1.6.1, no _db file.

@maximilianpress, fyi I was able to run liftoff without error simply by using a gff3 file instead of a gtf file.
You may want to try it.

@olechnwin Thanks, figured it out, it was a different issue. My issue was in this function:

def build_database(db, gff_file, disable_transcripts, disable_genes,):
    if db is None:
        try:
            feature_db = gffutils.create_db(gff_file, gff_file + "_db", merge_strategy="create_unique", force=True,
                                            disable_infer_transcripts=disable_transcripts,
                                            disable_infer_genes=disable_genes, verbose=True)
        except:
            find_problem_line(gff_file)
    else:
        feature_db = gffutils.FeatureDB(db)
    return feature_db 

Writing GFF to gff_file + "_db" did not work for me because the gff_file was in a write-protected location. The try-except clause then caught and squelched the informative error that gffutils couldn't write there, but which does show up if you run it directly via gffutils interactively:

# writing to a dummy location in wd
>>> featuredb = gffutils.create_db("/write/protected/location.gff", "fake_db", merge_strategy="create_unique", force=True, disable_infer_transcripts=True, disable_infer_genes=True, verbose=True)
2021-08-17 15:11:38,690 - INFO - Populating features
2021-08-17 15:20:20,652 - INFO - Populating features table and first-order relations: 3545011 features
2021-08-17 15:20:20,653 - INFO - Updating relations
2021-08-17 15:22:44,618 - INFO - Creating relations(parent) index
2021-08-17 15:23:20,359 - INFO - Creating relations(child) index
2021-08-17 15:24:12,303 - INFO - Creating features(featuretype) index
2021-08-17 15:24:28,376 - INFO - Creating features (seqid, start, end) index
2021-08-17 15:24:34,566 - INFO - Creating features (seqid, start, end, strand) index
2021-08-17 15:24:39,542 - INFO - Running ANALYZE features
# writing to write-protected location throws a poorly captured error!
>>> featuredb = gffutils.create_db("/write/protected/location.gff", "/write/protected/location.gff_gb", merge_strategy="create_unique", force=True, disable_infer_transcripts=True, disable_infer_genes=True, verbose=True)
...
sqlite3.OperationalError: unable to open database file

find_problem_line() will not help here as the issue is not in the GFF file but in the mechanics of permissions. It would be nice if the error could be unsquelched, e.g. with find_problem_line() only being run when gffutils sees a specific error type.

Additionally, it would be helpful to have the db written e.g. to the intermediate_files/ directory, which is guaranteed to have write access (or it should fail vocally before this step). Or some other way of controlling where it goes.

I was able to solve this by simply copying my gff to a write-allowed location, but it was pretty unclear what was going on.

Hi,
Apologies for my slow response. Thanks for bringing this to my attention. The error handling here certainly needs to be improved. In case others run into this in the meantime, I will comment and say that this error is indicative of some problem with your gff3 input whether it be the formatting or the permission. If its a format problem, i suggest running AGAT (https://github.com/NBISweden/AGAT) which will clean up anything problematic in the file

Hi, just an additional comment. I ran into the same problem, turns out it was because I ran it on a mounted network drive. After moving all the files to a local drive it worked fine.