cmap / cmapPy

Assorted tools for interacting with .gct, .gctx files and other Connectivity Map (Broad Institute) data/tools
https://clue.io/cmapPy/index.html
BSD 3-Clause "New" or "Revised" License
126 stars 76 forks source link

error in 'test_genes_queries.py' #10

Closed FADHLyemen closed 7 years ago

FADHLyemen commented 7 years ago

I try to run 'test_genes_queries.py' but I got the below error:

NoSectionError Traceback (most recent call last) /home/fadl2/cmapPy/cmapPy/clue_api_client/tests/test_genes_queries.py in () 40 setup_logger.setup(verbose=True) 41 ---> 42 cao = test_clue_api_client.build_clue_api_client_from_default_test_config() 43 44 unittest.main()

/home/fadl2/cmapPy/cmapPy/clue_api_client/tests/test_clue_api_client.py in build_clue_api_client_from_default_test_config() 125 #cao = clue_api_client.ClueApiClient(base_url=cfg.get(config_section, "clue_api_url"), 126 # user_key=cfg.get(config_section, "clue_api_user_key")) --> 127 cao = clue_api_client.ClueApiClient(base_url=cfg.get(config_section, " https://api.clue.io/api/genes"), 128 user_key=cfg.get(config_section, "87474c084256d13f140eaa3227ab48b2")) 129 return cao

/home/fadl2/anaconda3/envs/my_cmapPy_env2/lib/python2.7/ConfigParser.pyc in get(self, section, option) 328 if section not in self._sections: 329 if section != DEFAULTSECT: --> 330 raise NoSectionError(section) 331 if opt in self._defaults: 332 return self._defaults[opt]

NoSectionError: No section: 'test'

in file "clue_api_client.py" I use the two lines:

 self.base_url = https://api.clue.io/api/genes
 self.headers = {"user_key":my_key_ID}
dllahr commented 7 years ago

Thank you for submitting this! It actually pointed out some missing documentation. The problem is your config file, which is close. Here's some steps that I think will get the tests working for you:

  1. Please update your repository to the latest (I made a fix) version of master
  2. copy the file "example_cmapPy_config_file.cfg" to be in your home directory renamed as ~/.cmapPy.cfg.
  3. Edit that file to use your CLUE API key instead of "CHANGEME". You need an account at https://clue.io once you have that and you've logged in, click on your name in the upper right, then click account settings to get your API key
FADHLyemen commented 7 years ago

Thank you, for your updating, the last error is resolved but I have another error that I appreciate your kind reply.

ClueApiClient request failed response.status_code: 401 response.reason: Unauthorized

DEBUG 2017-09-25 12:21:58,283 connectionpool _new_conn Starting new HTTPS connection (1): dev-api.clue.io
DEBUG 2017-09-25 12:21:58,877 connectionpool _make_request https://dev-api.clue.io:443 "GET /api/genes?filter=%7B%22fields%22%3A+%7B%22pr_gene_symbol%22%3A+true%7D%2C+%22where%22%3A+%7B%22pr_gene_symbol%22%3A+%7B%22inq%22%3A+%5B%22AKT1%22%2C+%22BRAF%22%2C+%22Dave+Lahr%27s+fake+cell+line+that+never+existed%22%5D%7D%7D%7D HTTP/1.1" 401 33
DEBUG 2017-09-25 12:21:58,881 clue_api_client run_filter_query requests.get result r.status_code:  401
FWARNING 2017-09-25 12:21:58,884 gene_queries are_genes_in_api provided gene_symbols was empty, cannot run query
DEBUG 2017-09-25 12:21:58,886 test_genes_queries test_are_genes_in_api_no_genes_provided r:  set([])
.
======================================================================
FAIL: test_are_genes_in_api (__main__.TestGenesQueries)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/fadl2/cmapPy/cmapPy/clue_api_client/tests/test_genes_queries.py", line 19, in test_are_genes_in_api
    r = gq.are_genes_in_api(cao, ["AKT1", "BRAF", "Dave Lahr's fake cell line that never existed"])
  File "/home/fadl2/anaconda3/envs/my_cmapPy_env2/lib/python2.7/site-packages/cmapPy/clue_api_client/gene_queries.py", line 27, in are_genes_in_api
    {"where":{"pr_gene_symbol":{"inq":query_gene_symbols}}, "fields":{"pr_gene_symbol":True}})
  File "/home/fadl2/anaconda3/envs/my_cmapPy_env2/lib/python2.7/site-packages/cmapPy/clue_api_client/clue_api_client.py", line 44, in run_filter_query
    ClueApiClient._check_request_response(r)
  File "/home/fadl2/anaconda3/envs/my_cmapPy_env2/lib/python2.7/site-packages/cmapPy/clue_api_client/clue_api_client.py", line 100, in _check_request_response
    response.status_code, response.reason)
AssertionError: ClueApiClient request failed response.status_code:  401  response.reason:  Unauthorized

----------------------------------------------------------------------
Ran 2 tests in 0.607s

FAILED (failures=1)
dllahr commented 7 years ago

Glad to hear you're making progress. From the error message "401 Unauthorized" it looks like it is not using a valid API key. Did you change the API key entry in the config file, did you use the one you got from your account on clue.io?

in4matx commented 7 years ago

Also, why are you using "dev-api" ? Thats obviously development (internal). Was there a doc or code that had dev-api harcoded in?

Please let us know.

Thanks

On Mon, Sep 25, 2017 at 10:13 PM, Dave Lahr notifications@github.com wrote:

Glad to hear you're making progress. From the error message "401 Unauthorized" it looks like it is not using a valid API key. Did you change the API key entry in the config file, did you use the one you got from your account on clue.io?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cmap/cmapPy/issues/10#issuecomment-332065839, or mute the thread https://github.com/notifications/unsubscribe-auth/AA381mz7C14XpY3j51XVH3PQQT0QteqRks5smF3TgaJpZM4PjRu- .

FADHLyemen commented 7 years ago

Yes dllahr, I used the same API user key. Yes in4matx, the config file "cmapPy.cfg" has dev-api,

[prod]
clue_api_url = https://api.clue.io/api
clue_api_user_key ="my user key"

[test]
clue_api_url = https://dev-api.clue.io/api
clue_api_user_key ="my user key"

when I change https://dev-api.clue.io/api to https://api.clue.io/api as you suggest I got the below error:

FAIL: test_are_genes_in_api (__main__.TestGenesQueries)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/fadl2/cmapPy/cmapPy/clue_api_client/tests/test_genes_queries.py", line 22, in test_are_genes_in_api
    self.assertEqual(2, len(r))
AssertionError: 2 != 0

----------------------------------------------------------------------
Ran 3 tests in 1.890s

FAILED (failures=1)
dllahr commented 7 years ago

@in4matx He should be using the dev API, that is the correct thing to use when running the integration tests, we don't want them running against the production system.
Can you please change back to the dev api?

@FADHLyemen just a sanity check, you're not using "my user key" as your API key in the config file, and if you're not, you don't have it in quotes? (It should not be in quotes).

dllahr commented 7 years ago

@FADHLyemen I made a mistake, the problem is that your user key will not work against our dev system. Can you please point the tests at the production system? Then, to resolve the error messages you saw above when you tried that, can you check that you have the latest code - in particular, can you check that on line 27 of gene_queries.py it says: {"where":{"gene_symbol":{"inq":query_gene_symbols}}, "fields":{"gene_symbol":True}})

FADHLyemen commented 7 years ago

Yes, dllahr, Thank you. When I change the gene_queries.py inside the environment it works for only one time, then it gives the below error:

AssertionError: ClueApiClient request failed response.status_code: 500 response.reason: Internal Server Error

FADHLyemen commented 7 years ago

Thank you dllahr and int4max for your help, It works when I reset it, but my question is that why you delete the creating environment instructions from the readme file. Second, How could I use the API playground https://clue.io/api#playground with the API python package.

The only file that gives the below error is 'test_macchiato_queries.py' AssertionError: ClueApiClient request failed response.status_code: 500 response.reason: Internal Server Error

dllahr commented 7 years ago

Those instructions were redundant with the main instructions, and I don't want us to try to maintain the same documentation / instructions in multiple locations - that will lead to errors. You can find the documentation here: http://cmappy.readthedocs.io/en/latest/clue_api_client.html

If you go to the README for all of cmapPy the first link is to the overall documentation.

You will not be able to use the macchiato api tests, since they test writing to the API, which is reserved for our internal systems.