-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2009 from antgonza/fix-doi
WIP: Fix DOI issues
- Loading branch information
Showing
18 changed files
with
1,488 additions
and
1,124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- Dec 3, 2016 | ||
-- Modify qiita.study_publication so studies can have string | ||
-- dois and pubmed ids | ||
|
||
|
||
-- dropping PRIMARY KEY ( study_id, publication_doi ) | ||
ALTER TABLE qiita.study_publication DROP CONSTRAINT idx_study_publication_0; | ||
|
||
-- dropping FOREIGN KEY ( study_id ) REFERENCES qiita.study( study_id ) | ||
ALTER TABLE qiita.study_publication DROP CONSTRAINT fk_study_publication_study; | ||
|
||
-- dropping FOREIGN KEY ( publication_doi ) REFERENCES qiita.publication( doi ) | ||
ALTER TABLE qiita.study_publication DROP CONSTRAINT fk_study_publication; | ||
|
||
-- renaming publication_doi to publication | ||
ALTER TABLE qiita.study_publication RENAME publication_doi TO publication; | ||
|
||
-- adding a new column so we know if the publication is doi or pubmedid | ||
ALTER TABLE qiita.study_publication ADD COLUMN is_doi boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import qiita_db as qdb | ||
|
||
|
||
# selecting all doi/pubmedids | ||
with qdb.sql_connection.TRN: | ||
sql = """SELECT p.doi, pubmed_id, study_id | ||
FROM qiita.study_publication AS sp | ||
LEFT JOIN qiita.publication AS p ON (sp.publication = p.doi) | ||
WHERE p.doi NOT IN ( | ||
SELECT publication_doi FROM qiita.software_publication)""" | ||
qdb.sql_connection.TRN.add(sql) | ||
|
||
pubs = qdb.sql_connection.TRN.execute_fetchindex() | ||
|
||
# deleting all references to start from scratch | ||
sql = """DELETE FROM qiita.study_publication""" | ||
qdb.sql_connection.TRN.add(sql) | ||
qdb.sql_connection.TRN.execute() | ||
|
||
# reinserting following the new structure | ||
for doi, pid, sid in pubs: | ||
to_insert = [] | ||
if doi is not None: | ||
to_insert.append([doi, True, sid]) | ||
if pid not in to_insert: | ||
to_insert.append([pid, False, sid]) | ||
|
||
sql = """INSERT INTO qiita.study_publication | ||
(publication, is_doi, study_id) | ||
VALUES (%s, %s, %s)""" | ||
qdb.sql_connection.TRN.add(sql, to_insert, many=True) | ||
qdb.sql_connection.TRN.execute() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.