phac-nml / staramr

Scans genome contigs against the ResFinder, PlasmidFinder, and PointFinder databases.
Apache License 2.0
113 stars 26 forks source link

pointfinder db results DataFrame is None; AttributeError: 'NoneType' object has no attribute 'to_csv' #13

Closed peterk87 closed 6 years ago

peterk87 commented 6 years ago

The following error when trying to run staramr development branch against a couple genomes:

$ staramr search -o out SRR19529*.fasta
2018-05-14 12:42:27,227 INFO: Scheduling blast for SRR1952908.fasta
2018-05-14 12:42:27,261 INFO: Scheduling blast for SRR1952926.fasta
2018-05-14 12:42:31,589 INFO: Finished. Took 0.07 minutes.
2018-05-14 12:42:31,591 ERROR: 'NoneType' object has no attribute 'to_csv'
Traceback (most recent call last):
  File "../staramr/bin/staramr", line 68, in <module>
    args.run_command(args)
  File "../staramr/staramr/subcommand/Search.py", line 197, in run
    self._print_dataframe_to_text_file_handle(amr_detection.get_pointfinder_results(), fh)
  File "../staramr/staramr/subcommand/Search.py", line 108, in _print_dataframe_to_text_file_handle
    dataframe.to_csv(file_handle, sep="\t", float_format="%0.2f", na_rep=self.BLANK)
AttributeError: 'NoneType' object has no attribute 'to_csv'

It doesn't seem like the pointfinder db is being searched (--verbose shows only resfinder results being parsed).

Here's the db info:

$ staramr --verbose db info
resfinder_db_dir              = ../staramr/staramr/databases/data/dist/resfinder
resfinder_db_url              = https://bitbucket.org/genomicepidemiology/resfinder_db.git
resfinder_db_commit           = dc33e2f9ec2c420f99f77c5c33ae3faa79c999f2
resfinder_db_date             = Tue, 20 Mar 2018 16:49
pointfinder_db_dir            = ../staramr/staramr/databases/data/dist/pointfinder
pointfinder_db_url            = https://bitbucket.org/genomicepidemiology/pointfinder_db.git
pointfinder_db_commit         = ba65c4d175decdc841a0bef9f9be1c1589c0070a
pointfinder_db_date           = Fri, 06 Apr 2018 09:02
pointfinder_gene_drug_version = 111317
resfinder_gene_drug_version   = 041318

Doing a fresh staramr db build after clearing out the existing db doesn't seem to help.

This affects #12 as well.

Let me know if you need any other info!

apetkau commented 6 years ago

Woops. Forgot to check existence of --pointfinder-organism. If you don't select an organism, it will default to only searching through ResFinder (since ResFinder works for all organisms).

I've added a check for this in 5300c8d50c9375bbfefa03c61c858d3c3b8195ac and also print out an extra log statement if you don't specify --pointfinder-organism:

staramr search -o out example/study/*.fasta 
2018-05-14 13:25:20,546 INFO: No --pointfinder-organism specified. Will not search the PointFinder databases
2018-05-14 13:25:20,629 INFO: Scheduling blast for example/study/SRR1952908.fasta
2018-05-14 13:25:20,643 INFO: Scheduling blast for example/study/SRR1952926.fasta
2018-05-14 13:25:25,209 INFO: Finished. Took 0.08 minutes.
2018-05-14 13:25:25,323 INFO: Output files in out
Imtiaz06 commented 3 years ago

The following error when trying to run staramr search --pointfinder-organism salmonella -o out *.fasta

Traceback (most recent call last): File "/home/imtiaz/miniconda2/envs/staramr/bin/staramr", line 68, in args.run_command(args) File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/staramr/subcommand/Search.py", line 447, in run results = self._generate_results(database_repos=database_repos, File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/staramr/subcommand/Search.py", line 283, in _generate_results amr_detection.run_amr_detection(files,pid_threshold, plength_threshold_resfinder, File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/staramr/detection/AMRDetection.py", line 197, in run_amr_detection self._summary_dataframe = self._create_amr_summary(files, self._resfinder_dataframe,self._quality_module_dataframe, File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/staramr/detection/AMRDetectionResistance.py", line 70, in _create_amr_summary return amr_detection_summary.create_summary(self._include_negative_results) File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/staramr/results/AMRDetectionSummary.py", line 134, in create_summary resistance_frame = self._compile_results(resistance_frame) File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/staramr/results/AMRDetectionSummaryResistance.py", line 40, in _compile_results df_summary = df_summary \ File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/pandas/core/groupby/generic.py", line 1010, in aggregate result = gba.agg() File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/pandas/core/apply.py", line 164, in agg return self.agg_list_like() File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/pandas/core/apply.py", line 355, in agg_list_like new_res = colg.aggregate(arg) File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/pandas/core/groupby/generic.py", line 249, in aggregate ret = self._aggregate_multiple_funcs(func) File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/pandas/core/groupby/generic.py", line 303, in _aggregate_multiple_funcs results[key] = self.aggregate(func) File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/pandas/core/groupby/generic.py", line 265, in aggregate return self._python_agg_general(func, *args, *kwargs) File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/pandas/core/groupby/groupby.py", line 1310, in _python_agg_general result = self.grouper.agg_series(obj, f) File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/pandas/core/groupby/ops.py", line 1028, in agg_series result = self._aggregate_series_fast(obj, func) File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/pandas/core/groupby/ops.py", line 1053, in _aggregate_seriesfast result, = sgrouper.get_result() File "pandas/_libs/reduction.pyx", line 281, in pandas._libs.reduction.SeriesGrouper.get_result File "pandas/_libs/reduction.pyx", line 88, in pandas._libs.reduction._BaseGrouper._apply_to_group File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/pandas/core/groupby/groupby.py", line 1296, in f = lambda x: func(x, args, **kwargs) File "/home/imtiaz/miniconda2/envs/staramr/lib/python3.9/site-packages/staramr/results/AMRDetectionSummaryResistance.py", line 25, in _aggregate_gene_phenotype flattened_phenotype_list = [y.strip() for x in dataframe.get('Predicted Phenotype').tolist() for y in AttributeError: 'NoneType' object has no attribute 'tolist'

apetkau commented 3 years ago

Thanks for reporting @Imtiaz06 . I'm wondering if you could post this as a new issue? And also provide the version of staramar staramr --version and of the databases staramr db info you are using?