RTXteam / RTX

Software repo for Team Expander Agent (Oregon State U., Institute for Systems Biology, and Penn State U.)
https://arax.ncats.io/
MIT License
33 stars 21 forks source link

Odd bug in RTXFeedback.py #1057

Closed dkoslicki closed 4 months ago

dkoslicki commented 4 years ago

@edeutsch I discovered this issue when merging master into ranker-refine (one conflict, a single comment, easily fixed) and when running the DSL:

add_qnode(name=DOID:1227, id=n00)
add_qnode(type=phenotypic_feature, id=n01)
add_qedge(source_id=n00, target_id=n01, type=has_phenotype, id=e00)
expand(edge_id=e00)
overlay(action=overlay_clinical_info, paired_concept_frequency=true)
resultify()

And trying to run the DSL in a local UI, I get the error pasted below (which I didn't observe on master). Note that pretty much anything that uses return(message=true, store=true) throws this error...

127.0.0.1 - - [09/Sep/2020 09:25:14] "POST /devED/api/rtx/v1/query HTTP/1.1" 200 -
INFO: Connecting to database
INFO: Disconnecting from database
Exception in thread Thread-10:
Traceback (most recent call last):
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/dkoslicki/Desktop/RTX/code/UI/OpenAPI/python-flask-server/swagger_server/../../../../ARAX/ARAXQuery/ARAX_query.py", line 104, in asynchronous_query
    result = self.query(query)
  File "/home/dkoslicki/Desktop/RTX/code/UI/OpenAPI/python-flask-server/swagger_server/../../../../ARAX/ARAXQuery/ARAX_query.py", line 178, in query
    result = self.executeProcessingPlan(query)
  File "/home/dkoslicki/Desktop/RTX/code/UI/OpenAPI/python-flask-server/swagger_server/../../../../ARAX/ARAXQuery/ARAX_query.py", line 574, in executeProcessingPlan
    message_id = rtxFeedback.addNewMessage(message,query)
  File "/home/dkoslicki/Desktop/RTX/code/ARAX/ARAXQuery/../../UI/Feedback/RTXFeedback.py", line 287, in addNewMessage
    self.addNewResults(storedMessage.message_id,message)
  File "/home/dkoslicki/Desktop/RTX/code/ARAX/ARAXQuery/../../UI/Feedback/RTXFeedback.py", line 338, in addNewResults
    session.flush()
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/orm/session.py", line 2523, in flush
    self._flush(objects)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/orm/session.py", line 2664, in _flush
    transaction.rollback(_capture_exception=True)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
    exc_value, with_traceback=exc_tb,
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/orm/session.py", line 2624, in _flush
    flush_context.execute()
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/orm/unitofwork.py", line 422, in execute
    rec.execute(self)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/orm/unitofwork.py", line 589, in execute
    uow,
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj
    insert,
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/orm/persistence.py", line 1136, in _emit_insert_statements
    statement, params
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1020, in execute
    return meth(self, multiparams, params)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_clauseelement
    distilled_params,
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1324, in _execute_context
    e, statement, parameters, cursor, context
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1521, in _handle_dbapi_exception
    util.raise_(exc_info[1], with_traceback=exc_info[2])
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1284, in _execute_context
    cursor, statement, parameters, context
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
    cursor.execute(statement, parameters)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/pymysql/cursors.py", line 168, in execute
    query = self.mogrify(query, args)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/pymysql/cursors.py", line 147, in mogrify
    query = query % self._escape_args(args, conn)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/pymysql/cursors.py", line 127, in _escape_args
    return {key: conn.literal(val) for (key, val) in args.items()}
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/pymysql/cursors.py", line 127, in <dictcomp>
    return {key: conn.literal(val) for (key, val) in args.items()}
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/pymysql/connections.py", line 467, in literal
    return self.escape(obj, self.encoders)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/pymysql/connections.py", line 460, in escape
    return converters.escape_item(obj, self.charset, mapping=mapping)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/pymysql/converters.py", line 27, in escape_item
    val = encoder(val, mapping)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/pymysql/converters.py", line 118, in escape_unicode
    return u"'%s'" % _escape_unicode(value)
  File "/home/dkoslicki/anaconda3/envs/RTX37/lib/python3.7/site-packages/pymysql/converters.py", line 73, in _escape_unicode
    return value.translate(_escape_table)
AttributeError: 'numpy.float64' object has no attribute 'translate'

I find this especially odd since RTXFeedback.py wasn't touched in the merge:

Removing code/kg2/prompt_for_password_and_save_to_temp_file.py
Removing code/kg2/owl-load-inventory.yaml
Removing code/kg2/owl-load-inventory-test.yaml
Auto-merging code/kg2/multi_ont_to_json_kg.py
Auto-merging code/kg2/install-docker-ubuntu18.sh
Removing code/kg2/curies-to-urls-lookaside-list.yaml
Auto-merging code/kg2/build-multi-ont-kg.sh
Auto-merging code/ARAX/ARAXQuery/Overlay/predictor/predictor.py
CONFLICT (content): Merge conflict in code/ARAX/ARAXQuery/Overlay/predictor/predictor.py
Auto-merging code/ARAX/ARAXQuery/Overlay/predict_drug_treats_disease.py
Removing code/ARAX/ARAXQuery/Overlay/pmid_mapper.py
Auto-merging code/ARAX/ARAXQuery/Overlay/overlay_clinical_info.py
Automatic merge failed; fix conflicts and then commit the result.

This issue blocks #941

edeutsch commented 4 years ago

okay, I confirm, that I'm not seeing this in master. I can repro in ranker-refine?

edeutsch commented 4 years ago

I switched my branch to ranker-refine and am seeing a bazillion of these errors:

2020-09-09 16:53:17.522553 DEBUG:  Querying Columbia Open Health data for info about neutropenia and Hypoplastic fingernail
2020-09-09 16:53:17.522729 ERROR:  Traceback (most recent call last): File "/mnt/data/orangeboard/devED/RTX/code/UI/OpenAPI/python-flask-server/swagger_server/../../../../ARAX/ARAXQuery/Overlay/overlay_clinical_info.py", line 119, in make_edge_attribute_from_curies res = self.cohdIndex.get_concept_ids(source_curie) File "/mnt/data/orangeboard/devED/RTX/code/ARAX/ARAXQuery/Overlay/../../KnowledgeSources/COHD_local/scripts/COHDIndex.py", line 225, in get_concept_ids cursor.execute(f"select distinct t1.curie, t1.concept_id from CURIE_TO_OMOP_MAPPING t1 inner join CONCEPTS t2 on t1.concept_id = t2.concept_id where curie='{curie}';") sqlite3.OperationalError: no such table: CURIE_TO_OMOP_MAPPING
2020-09-09 16:53:17.522744 ERROR:  Something went wrong when adding the edge attribute from COHD.

Any ideas on how to address that?

edeutsch commented 4 years ago

@dkoslicki I am not able to test further because of previous post's problem.

BUT, I am going to guess that the error arises because you have a confidence value that cannot be converted to a float. I would check all the confidence values in your resulting message, and I'll wager that one of them is not convertible to float. If you fix that, it will likely work?

I can make the code more robust to not fail so poorly when that happens, but it shouldn't happen I suppose.

dkoslicki commented 4 years ago

@edeutsch Right: the errors you see with COHD are due to updates in the COHD local database, so that gets fixed if you merge and then run the code. MWE:

git checkout ranker-refine
git pull origin ranker-refine
git merge --no-ff origin/master
<fix the merge conflict>
git add code/ARAX/ARAXQuery/Overlay/predictor/predictor.py
python ARAX_query.py 16

Let me know if that works in reproducing the error for you

edeutsch commented 4 years ago

@dkoslicki I ran aground trying the above git commands. I could not get it to work. BUT, I checked in a fix to master than now checks to see if confidence scores can be converted to floats in a robust way. If any confidence score cannot be converted to a float, instead of erroring out (like it was), it prints this message to STDERR: eprint(f"WARNING: Confidence value '{result.confidence}' cannot be converted to float") and then result.confidence is set to -999.0 So be on the lookout for confidence scores of -999.0 and consider that something that needs to be fixed in the ranker. All output confidences should be floats.

edeutsch commented 4 months ago

closing ancient history.