aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
AgeCommit message (Collapse)Author
2022-04-07Use case attribute id inside brackets if present during updatesBonfaceKilz
* gn3/db/sample_data.py: Import "parse_csv_column". (update_sample_data): If an id is present in the column header, use it. * tests/unit/db/test_sample_data.py (test_update_sample_data): Update tests to capture the above.
2022-04-07Add method for fetching the case_attributesBonfaceKilz
* gn3/db/sample_data.py (get_case_attributes): New function. * tests/unit/db/test_sample_data.py (test_get_case_attributes): Test case for the above.
2022-04-07Run python black on fileBonfaceKilz
* gn3/db/sample_data.py: Run "python black -l 79 ..."
2022-03-14Dummy White Space commit to fix laminarBonfaceKilz
2022-03-12Remove unused importsBonfaceKilz
2022-03-12Fix mypy issuesBonfaceKilz
2022-03-12Fix pylint issuesBonfaceKilz
2022-03-12Store the first element as strain_idBonfaceKilz
2022-03-12Append the strain name when extracting "actions"BonfaceKilz
* gn3/db/sample_data.py (__extract_actions): During updates, make sure that the strain name is part of the returned string when extracting "actions". * tests/unit/db/test_sample_data.py: Add test cases for the above.
2022-03-12Apply auto-pep8 to sample_data.py and it's test fileBonfaceKilz
2022-03-12Add missing return type-annotationsBonfaceKilz
* tests/unit/db/test_sample_data.py (delete_sample_data): Add missing return type for type annotations. (insert_sample_data): Ditto.
2022-03-12Update how data is updated by re-using existing functionsBonfaceKilz
* gn3/db/sample_data.py (get_sample_data_ids): Re-use "delete_sample_data" and "insert_sample_data" when updating data; and also add logic for updating modified data. * tests/unit/db/test_sample_data.py: Add tests for the above.
2022-03-12Create action dict that's created when updating dataBonfaceKilz
* gn3/db/sample_data.py (__extract_actions): An update on a vector of data can contain: inserts, deletes and updates. This functions extracts these actions during an update. * tests/unit/db/test_sample_data.py (test_extract_actions): Add test-case for the above.
2022-03-12Remove check for inserted data when inserting individual dataBonfaceKilz
* gn3/db/sample_data.py (insert_sample_data)[__insert_data]: Move check to the main body. With this check here, you have 3 redundant checks. For a successful insert, it will insert the first value to the `PublishData` table and ignore the rest of the inserts.
2022-03-12Make `_map` a constantBonfaceKilz
* gn3/db/sample_data.py: Now constant, `_MAP`. (delete_sample_data)[__delete_data]: Replace `_map` with `_MAP`. (insert_sample_data)[__insert_data]: Ditto.
2022-03-12Fix faulty SQL query string when deleting case-attributesBonfaceKilz
2022-03-12Explicitly get CaseAttributeId and fix broken sql queryBonfaceKilz
* gn3/db/sample_data.py (insert_sample_data): Use correct query string. Also, use CaseAttributeId to determine whether case-attributes were inserted. If so, do not attempt an insert.
2022-03-12Remove duplicate paramsBonfaceKilz
* gn3/db/sample_data.py (insert_sample_data)[__insert_case_attribute]: Remove extra parameters.
2022-03-12Remove dead codeBonfaceKilz
2022-03-12Check whether publish data already exists before insertingBonfaceKilz
* gn3/db/sample_data.py (insert_sample_data): If data already exists in the table, do not attempt an insert; otherwise, an error will be generated.
2022-03-12Fetch id's separately for the insertion edge-caseBonfaceKilz
* gn3/db/sample_data (get_sample_data_ids): Add an extra condition that caters for inserts: during inserts, joins won't work when fetching the strain_id, publishdata_id, and strain_name. In this case, just create 2 separate queries to do that work.
2022-03-12Extract a strain name given a csv string and it's headerBonfaceKilz
* gn3/csvcmp.py (extract_strain_name): New function. * gn3/db/sample_data (delete_sample_data): Use the aforementioned function. (insert_sample_data): Ditto. * tests/unit/test_csvcmp: Test cases for above.
2022-03-12Allow deleting case-attribute data during deletionBonfaceKilz
* gn3/db/sample_data.py (delete_sample_data): Modify this function to allow deleting case-attribute values.
2022-03-12Allow inserting case-attribute data during insertsBonfaceKilz
* gn3/db/sample_data.py (insert_sample_data): Modify this function to allow inserting case-attribute values.
2022-03-12Fetch InbredSetIdBonfaceKilz
* gn3/db/sample_data.py (get_sample_data_ids): Extend to also fetch InbredSetId. (update_sample_data): Discard the returned value of InbredSetId. (delete_sample_data): Ditto.
2022-03-12Create a new function for retrieving strain_id and publishdata_idBonfaceKilz
* gn3/db/sample_data.py: Import Any, Tuple. (get_sample_data_ids): New function that fetches the strain_id and publishdata_id of a given data point. (update_sample_data): Use `get_sample_data_ids`. (delete_sample_data): Ditto. (insert_sample_data): Ditto.
2022-03-12Move operations on sample_data to it's own moduleBonfaceKilz
2022-03-12db: Fix error in SQL queryBonfaceKilz
* gn3/db/traits.py (get_trait_csv_sample_data): Update SQL to fix runtime errors.
2022-03-12Fix pylint errorBonfaceKilz
2022-03-12Append case attributes to csv data if they existBonfaceKilz
2022-03-12db: Extend csv query to fetch case attributesBonfaceKilz
* gn3/db/traits.py (get_trait_csv_sample_data): Fetch case attribute data if it exists.
2022-03-12Revert "db: Fetch correct sample data"BonfaceKilz
This reverts commit 710769e84b3bc6a2bdd66effdbac0659272ed511.
2022-03-11Fix typing errorsFrederick Muriuki Muriithi
2022-02-21Fix minor issues introduced while fixing linting errorsFrederick Muriuki Muriithi
2022-02-21Fix a myriad of linter issuesFrederick Muriuki Muriithi
* Use `with` in place of plain `open` * Use f-strings in place of `str.format()` * Remove string interpolation from queries - provide data as query parameters * other minor fixes
2022-02-21Test partial corrs API with mix of existing and non-existing control traitsFrederick Muriuki Muriithi
Test that the partial correlations endpoint handles a mix of existing and non-existing control traits gracefully and issues a warning to the user. Summary of changes: * gn3/computations/partial_correlations.py: Issue a warning for all non-existing control traits * gn3/db/partial_correlations.py: update queries - use `INNER JOIN` for tables instead of comma-separated list of tables * tests/integration/conftest.py: Add `db_conn` fixture to provide a database connection to the tests. This will probably be changed in the future to connect to a temporary database for tests. * tests/integration/test_partial_correlations.py: Add test to check for correct behaviour with a mix of existing and non-existing control traits
2022-02-19Test partial corrs endpoint with non-existing control traitsFrederick Muriuki Muriithi
Test that if the endpoint is queried and not a single one of the control traits exists in the database, then the endpoint will respond with a 404 (not-found) status code. Summary of changes: * gn3/computations/partial_correlations.py: Check whether any control trait is found. If none is found, return "not-found" message. * gn3/db/partial_correlations.py: Fix bug in Geno query. * tests/integration/test_partial_correlations.py: Add test for non-existing control traits. Rename function to make it clearer what it is testing for. Remove obsoleted comments.
2022-02-18Remove code trying to query non-existent `TempFreeze` tableFrederick Muriuki Muriithi
The code was migrated from GN1 with a faulty assumption that all trait types have a corresponding `*Freeze` table in the database. This assumption is not true for the `Temp` traits. This commit removes the buggy code.
2022-02-18Test partial correlations endpoint with non-existent primary traitsFrederick Muriuki Muriithi
Test that the partial correlations endpoint responds with an appropriate "not-found" message and the corresponding 404 status code in the case where a request is made and the primary trait requested for does not exist in the database. Summary of the changes in each file: * gn3/api/correlation.py: generalise the building of the response * gn3/computations/partial_correlations.py: return with a "not-found" if the primary trait does not exist in the database * gn3/db/partial_correlations.py: Fix a number of bugs that led to exceptions in the case that the primary trait did not exist * pytest.ini: register a `slow` pytest marker * tests/integration/test_partial_correlations.py: Add a new test to check for an appropriate 404 response in case of a primary trait that does not exist in the database.
2022-02-08db: traits: Enable deletion of individual sample valuesBonfaceKilz
If a user replaces an individual value with an "x", delete that date entry from the respective table. Deletion here is the only option since by default the Nstrain, PublishData and PublishSE don't accept null values. Note that deleting all 3 values is equivalent to removing the sample from the CSV file. * gn3/db/traits.py (update_sample_data): If a value is "x", delete it from the respective table.
2022-02-08db: traits: Allow insertions of "0" in resp. sample values tablesBonfaceKilz
When editing values from "x" to "0"(or any other value) when editing data, an "update" statement was being run; thereby no new value was being inserted. To the end user, modifying an "x" value to something else meant that no value was being inserted. This commit fixes that by doing an insert whenever a change from "x" to "0" is performed. * gn3/db/traits.py (update_sample_data): Add insert statements whenever an "update" statement returns a 0 row-count.
2022-02-08db: traits: Insert "count" instead of "error" in "NStrain" tableBonfaceKilz
2022-02-03db: Fetch correct sample dataBonfaceKilz
2022-02-02Remove PublishFreeze from retrieve_publish_trait_info queryzsloan
The PublishFreeze table isn't necessary in phenotype queries, since PublishFreeze.Id = InbredSet.Id (for the purposes of identifying traits, at least)
2022-02-02Fix bug where sample values of 0 were being treated as Falsezsloan
In line 91 of gn3/db/traits.py, there was an if statement "if record[key] else 'x'" that was treating values of 0 as False, so I changed it to explicitly check that values aren't None
2022-02-02Fix retrieve_publish_trait_data queryzsloan
The PublishFreeeze table is actually unnecessary for this query, since the group ID (inbred_set_id) should be passed in and that ID is in the PublishXRef table (so no neeed to join with PublishFreeze)
2022-01-12Indent code correctlyFrederick Muriuki Muriithi
Indent the code correctly.
2022-01-12Deduplicate query to fetch data for 'Publish' traitsFrederick Muriuki Muriithi
The queries run in the `get_trait_csv_sample_data` and `retrieve_publish_trait_data` functions in the `gn3.db.traits` module were mostly similar. This commit changes that, by making the `get_trait_csv_sample_data` function make use of the results from calling the `retrieve_publish_trait_data` function.
2022-01-10Check for path existenceFrederick Muriuki Muriithi
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi
2022-01-10Fix dataset retrieval query for `Geno` traitsFrederick Muriuki Muriithi
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi