-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_oa_calculations.py
599 lines (364 loc) · 17.2 KB
/
6_oa_calculations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
#!/usr/bin/env python
# coding: utf-8
# # Open Access status for WoS DOIs
#
# Notebook used for the study presented at the EAHIL 2022 conference
#
# * Title: Computational assistance in the analysis of cited references in biomedical literature: a case study from two institutions.
#
# * Authors:
# * Teresa Lee, Knowledge Manager, International Agency for Research on Cancer (IARC/WHO) leet@iarc.fr
# * Pablo Iriarte, IT Coordinator, Library of the University of Geneva Pablo.Iriarte@unige.ch
# * Floriane Muller, Librarian (Medical Library), Library of the University of Geneva Floriane.Muller@unige.ch
# * Ramon Cierco Jimenez, Doctoral Student, International Agency for Research on Cancer (IARC/WHO) CiercoR@students.iarc.fr
#
#
# ### Prerequisites
# * DOIs from publications and citations
# * unpaywall data downloaded using the notebook "doi_unpaywall.ipynb" or queries made directly on unpaywall website
#
# ## unpaywall data extraction
#
# https://unpaywall.org/data-format
#
# Fields to extract:
#
# - is_oa : Boolean (Is there an OA copy of this resource
# - oa_status : Strin (The OA status, or color, of this resource: gold, hybrid, bronze, green or closed)
# - has_repository_copy : Boolean (Whether there is a copy of this resource in a repository. True if this resource has at least one OA Location with host_type = "repository". False otherwise.)
#
#
#
# In[1]:
import re
import os
import pandas as pd
import time
import datetime
import json
import numpy as np
# ## DOIs
#
# In[2]:
# open DOIs data
dois = pd.read_csv('export_dois_all_dedup.tsv', encoding='utf-8', sep='\t', header=0)
dois
# In[3]:
# del and rename cols
del dois['Accession Number']
dois = dois.rename(columns={'DOI' : 'doi', 'ID': 'id'})
dois
# In[4]:
# open the second series of DOIs (obtained after fixing the bug on the parsing code)
dois_2 = pd.read_csv('export_dois_without_unpaywall.tsv', encoding='utf-8', sep='\t', header=0)
dois_2
# In[5]:
# append
dois = dois.append(dois_2, ignore_index=True)
dois
# In[6]:
# dedup by DOI and keep only the last
dois = dois.drop_duplicates(subset='doi', keep='last')
dois
# In[7]:
# export to csv and excel
dois.to_csv('export_dois_1_and_2_dedup.tsv', sep='\t', encoding='utf-8', index=False)
dois.to_excel('export_dois_1_and_2_dedup.xlsx', index=False)
# ## Publications from UNIGE
#
# In[8]:
# open UNIGE data
unige_citations = pd.read_csv('WoS UNIGE results 2001_2020/UNIGE_WoS.csv', encoding='utf-8', header=0, usecols=['ID', 'Accession Number', 'DOI', 'DOI of cited article'])
unige_citations
# In[9]:
unige_citations.loc[unige_citations['Accession Number'].isna()]
# In[10]:
unige_citations.loc[unige_citations['Accession Number']=='']
# In[11]:
# unige publications by ID
unige_publications_rows = unige_citations[['ID', 'Accession Number', 'DOI']].drop_duplicates(subset='ID').shape[0]
unige_publications_rows
# In[12]:
# unige publications
unige_publications = unige_citations[['Accession Number', 'DOI']].drop_duplicates(subset='Accession Number')
del unige_publications['Accession Number']
unige_publications = unige_publications.rename(columns={'DOI' : 'doi'})
unige_publications_dois = unige_publications.loc[unige_publications['doi'].notna()]
unige_publications_dois
# In[13]:
unige_publications
# In[14]:
# unige citations with DOIs
del unige_citations['Accession Number']
del unige_citations['ID']
del unige_citations['DOI']
unige_citations = unige_citations.rename(columns={'DOI of cited article' : 'doi'})
unige_citations_dois = unige_citations.loc[unige_citations['doi'].notna()]
unige_citations_dois
# In[15]:
# open IARC data
iarc_citations = pd.read_csv('WoS IARC results 2001_2020/IARC_WoS.csv', encoding='utf-8', header=0, usecols=['Accession Number', 'DOI', 'DOI of cited article'])
iarc_citations
# In[16]:
# iarc publications with DOIs
iarc_publications = iarc_citations[['Accession Number', 'DOI']].drop_duplicates(subset='Accession Number')
del iarc_publications['Accession Number']
iarc_publications = iarc_publications.rename(columns={'DOI' : 'doi'})
iarc_publications_dois = iarc_publications.loc[iarc_publications['doi'].notna()]
iarc_publications_dois
# In[17]:
# iarc citations with DOIs
del iarc_citations['Accession Number']
del iarc_citations['DOI']
iarc_citations = iarc_citations.rename(columns={'DOI of cited article' : 'doi'})
iarc_citations_dois = iarc_citations.loc[iarc_citations['doi'].notna()]
iarc_citations_dois
# In[18]:
# add columns
unige_publications_dois['doi'] = unige_publications_dois['doi'].str.strip()
unige_citations_dois['doi'] = unige_citations_dois['doi'].str.strip()
iarc_publications_dois['doi'] = iarc_publications_dois['doi'].str.strip()
iarc_citations_dois['doi'] = iarc_citations_dois['doi'].str.strip()
unige_publications_dois['publication_unige'] = 1
unige_citations_dois['citation_unige'] = 1
iarc_publications_dois['publication_iarc'] = 1
iarc_citations_dois['citation_iarc'] = 1
# In[19]:
# merge the publication and citation information
dois = pd.merge(dois, unige_publications_dois, on='doi', how='left')
dois = pd.merge(dois, unige_citations_dois, on='doi', how='left')
dois = pd.merge(dois, iarc_publications_dois, on='doi', how='left')
dois = pd.merge(dois, iarc_citations_dois, on='doi', how='left')
dois
# In[20]:
# drop duplicates
dois = dois.drop_duplicates(subset='id')
dois
# In[21]:
# reset index
dois.reset_index(drop=True, inplace=True)
dois
# In[22]:
# test empty rows
dois.loc[dois['publication_unige'].isna() & dois['citation_unige'].isna() & dois['publication_iarc'].isna() & dois['citation_iarc'].isna()]
# In[23]:
# export
dois.to_csv('export_dois_all_dedup_publications_citations.tsv', sep='\t', index=False)
# ## unpaywall OA status
# In[22]:
# extract informtation on downloaded data from unpaywall
for index, row in dois.iterrows():
mydoi = row['doi']
myid = str(row['id']).zfill(10)
myfolder = str(int(row['id']/100000)+1)
# print(myid)
if (((index/1000) - int(index/1000)) == 0) :
print(index)
# open the json file
if os.path.exists('E:/data_sources/unpaywall/eahil_2022/eahil_2022_' + myfolder + '/' + myid + '.json'):
# initialising variables
doi_unpaywall = ''
oa_status = ''
has_repository_copy = ''
with open('E:/data_sources/unpaywall/eahil_2022/eahil_2022_' + myfolder + '/' + myid + '.json', 'r', encoding='utf-8') as f:
data = json.load(f)
if ('doi' in data):
doi_unpaywall = data['doi']
if ('oa_status' in data):
oa_status = data['oa_status']
if ('has_repository_copy' in data):
has_repository_copy = data['has_repository_copy']
dois.at[index,'doi_unpaywall'] = doi_unpaywall
dois.at[index,'oa_status'] = oa_status
dois.at[index,'has_repository_copy'] = has_repository_copy
else :
# print(str(row['id']) + ' - not found')
with open('unpaywall_extract_errors.txt', 'a', encoding='utf-8') as g:
g.write(str(row['id']) + ' file not found\n')
# In[23]:
dois
# In[24]:
dois['oa_status'].value_counts()
# In[25]:
dois['has_repository_copy'].value_counts()
# In[26]:
# dois found
dois.loc[dois['doi_unpaywall'].notna()].shape[0]
# In[27]:
# dois found
dois.loc[dois['doi_unpaywall'].notna()].shape[0] / dois.shape[0]
# In[28]:
# dois not found
dois.loc[dois['doi_unpaywall'].isna()].shape[0]
# In[29]:
# dois not found
dois.loc[dois['doi_unpaywall'].isna()].shape[0] / dois.shape[0]
# In[30]:
# dois not equal
dois.loc[(dois['doi'] != dois['doi_unpaywall']) & dois['doi_unpaywall'].notna()]
# In[31]:
# normalize DOIs
dois.loc[dois['doi'].notna(), 'doi_normalized'] = dois['doi'].str.upper()
dois.loc[dois['doi_unpaywall'].notna(), 'doi_unpaywall_normalized'] = dois['doi_unpaywall'].str.upper()
dois
# In[32]:
# dois not equal
dois.loc[(dois['doi_normalized'] != dois['doi_unpaywall_normalized']) & dois['doi_unpaywall_normalized'].notna()]
# In[33]:
# dois not equal
dois.loc[(dois['doi_normalized'] != dois['doi_unpaywall_normalized']) & dois['doi_unpaywall_normalized'].notna()].shape[0]
# In[34]:
# export dois not equal
dois.loc[(dois['doi_normalized'] != dois['doi_unpaywall_normalized']) & dois['doi_unpaywall_normalized'].notna()].to_excel('export_dois_wos_unpaywall_not_equal.xlsx', index=False)
# In[35]:
# export to csv and excel
dois.to_csv('export_dois_oa_status.tsv', sep='\t', encoding='utf-8', index=False)
dois.to_excel('export_dois_oa_status.xlsx', index=False)
# # Add OA status to publications and citations
# In[36]:
# open UNIGE data
unige_all = pd.read_csv('WoS UNIGE results 2001_2020/UNIGE_WoS.csv', encoding='utf-8', header=0, usecols=['Accession Number', 'Document Type', 'Year Published', '29 Character Source Abbreviation', 'Open Access Indicator', 'PubMed ID', 'DOI', 'Year of cited article', 'Journal of cited article', 'DOI of cited article'])
unige_all
# In[37]:
# open IARC data
iarc_all = pd.read_csv('WoS IARC results 2001_2020/IARC_WoS.csv', encoding='utf-8', header=0, usecols=['Accession Number', 'Document Type', 'Year Published', '29 Character Source Abbreviation', 'Open Access Indicator', 'PubMed ID', 'DOI', 'Year of cited article', 'Journal of cited article', 'DOI of cited article'])
iarc_all
# In[38]:
# rename columns
unige_all = unige_all.rename(columns={'Accession Number' : 'publication_wos_id',
'Year Published' : 'publication_year',
'Document Type' : 'publication_type',
'29 Character Source Abbreviation' : 'publication_journal',
'DOI' : 'publication_doi',
'PubMed ID' : 'publication_pmid',
'Open Access Indicator' : 'publication_wos_oa',
'Year of cited article' : 'citation_year',
'Journal of cited article' : 'citation_journal',
'DOI of cited article' : 'citation_doi'})
unige_all
# In[39]:
# rename columns
iarc_all = iarc_all.rename(columns={'Accession Number' : 'publication_wos_id',
'Year Published' : 'publication_year',
'Document Type' : 'publication_type',
'29 Character Source Abbreviation' : 'publication_journal',
'DOI' : 'publication_doi',
'PubMed ID' : 'publication_pmid',
'Open Access Indicator' : 'publication_wos_oa',
'Year of cited article' : 'citation_year',
'Journal of cited article' : 'citation_journal',
'DOI of cited article' : 'citation_doi'})
iarc_all
# In[40]:
# strip DOIs
unige_all['publication_doi'] = unige_all['publication_doi'].str.strip()
unige_all['citation_doi'] = unige_all['citation_doi'].str.strip()
iarc_all['publication_doi'] = iarc_all['publication_doi'].str.strip()
iarc_all['citation_doi'] = iarc_all['citation_doi'].str.strip()
# In[41]:
# merge in UNIGE file for publications
unige_all = pd.merge(unige_all, dois, left_on='publication_doi', right_on='doi', how='left')
unige_all
# In[42]:
# merge in UNIGE file for citations
unige_all = pd.merge(unige_all, dois, left_on='citation_doi', right_on='doi', how='left')
unige_all
# In[43]:
unige_all.columns
# In[44]:
# merge in IARC file
iarc_all = pd.merge(iarc_all, dois, left_on='publication_doi', right_on='doi', how='left')
iarc_all
# In[45]:
# merge in IARC file for citations
iarc_all = pd.merge(iarc_all, dois, left_on='citation_doi', right_on='doi', how='left')
iarc_all
# In[46]:
iarc_all.columns
# In[47]:
# del columns not used and rename
del unige_all['doi_normalized_x']
del unige_all['doi_unpaywall_normalized_x']
del unige_all['doi_unpaywall_x']
del unige_all['id_x']
del unige_all['doi_x']
del unige_all['doi_normalized_y']
del unige_all['doi_unpaywall_normalized_y']
del unige_all['doi_unpaywall_y']
del unige_all['id_y']
del unige_all['doi_y']
# rename columns
unige_all = unige_all.rename(columns={'publication_unige_x' : 'publication_doi_is_unige_publication',
'publication_unige_y' : 'citation_doi_is_unige_publication',
'citation_unige_x' : 'publication_doi_is_unige_citation',
'citation_unige_y' : 'citation_doi_is_unige_citation',
'publication_iarc_x' : 'publication_doi_is_iarc_publication',
'publication_iarc_y' : 'citation_doi_is_iarc_publication',
'citation_iarc_x' : 'publication_doi_is_iarc_citation',
'citation_iarc_y' : 'citation_doi_is_iarc_citation',
'oa_status_x' : 'publication_doi_oa_status',
'oa_status_y' : 'citation_doi_oa_status',
'has_repository_copy_x' : 'publication_doi_has_repository_copy',
'has_repository_copy_y' : 'citation_doi_has_repository_copy'})
unige_all
# In[48]:
unige_all.columns
# In[49]:
del iarc_all['doi_normalized_x']
del iarc_all['doi_unpaywall_normalized_x']
del iarc_all['doi_unpaywall_x']
del iarc_all['id_x']
del iarc_all['doi_x']
del iarc_all['doi_normalized_y']
del iarc_all['doi_unpaywall_normalized_y']
del iarc_all['doi_unpaywall_y']
del iarc_all['id_y']
del iarc_all['doi_y']
# rename columns
iarc_all = iarc_all.rename(columns={'publication_unige_x' : 'publication_doi_is_unige_publication',
'publication_unige_y' : 'citation_doi_is_unige_publication',
'citation_unige_x' : 'publication_doi_is_unige_citation',
'citation_unige_y' : 'citation_doi_is_unige_citation',
'publication_iarc_x' : 'publication_doi_is_iarc_publication',
'publication_iarc_y' : 'citation_doi_is_iarc_publication',
'citation_iarc_x' : 'publication_doi_is_iarc_citation',
'citation_iarc_y' : 'citation_doi_is_iarc_citation',
'oa_status_x' : 'publication_doi_oa_status',
'oa_status_y' : 'citation_doi_oa_status',
'has_repository_copy_x' : 'publication_doi_has_repository_copy',
'has_repository_copy_y' : 'citation_doi_has_repository_copy'})
iarc_all
# In[50]:
iarc_all.columns
# In[51]:
# export of dois without unpaywall information to test a new download
unige_publications_with_dois_without_unpaywall = unige_all.loc[unige_all['publication_doi'].notna() & unige_all['publication_doi_oa_status'].isna()][['publication_wos_id', 'publication_doi']]
unige_citations_with_dois_without_unpaywall = unige_all.loc[unige_all['citation_doi'].notna() & unige_all['citation_doi_oa_status'].isna()][['publication_wos_id', 'citation_doi']]
iarc_publications_with_dois_without_unpaywall = iarc_all.loc[iarc_all['publication_doi'].notna() & iarc_all['publication_doi_oa_status'].isna()][['publication_wos_id', 'publication_doi']]
iarc_citations_with_dois_without_unpaywall = iarc_all.loc[iarc_all['citation_doi'].notna() & iarc_all['citation_doi_oa_status'].isna()][['publication_wos_id', 'citation_doi']]
# rename columns
unige_publications_with_dois_without_unpaywall = unige_publications_with_dois_without_unpaywall.rename(columns={'publication_doi' : 'doi'})
unige_citations_with_dois_without_unpaywall = unige_citations_with_dois_without_unpaywall.rename(columns={'citation_doi' : 'doi'})
iarc_publications_with_dois_without_unpaywall = iarc_publications_with_dois_without_unpaywall.rename(columns={'publication_doi' : 'doi'})
iarc_citations_with_dois_without_unpaywall = iarc_citations_with_dois_without_unpaywall.rename(columns={'citation_doi' : 'doi'})
# In[52]:
# append dfs and reindex
dois_without_unpaywall = unige_publications_with_dois_without_unpaywall.append(unige_citations_with_dois_without_unpaywall, ignore_index=True)
dois_without_unpaywall = dois_without_unpaywall.append(iarc_publications_with_dois_without_unpaywall, ignore_index=True)
dois_without_unpaywall = dois_without_unpaywall.append(iarc_citations_with_dois_without_unpaywall, ignore_index=True)
# dedup
dois_without_unpaywall = dois_without_unpaywall.drop_duplicates(subset='doi')
# reset index
dois_without_unpaywall.reset_index(drop=True, inplace=True)
# add new id
dois_without_unpaywall['id'] = dois_without_unpaywall.index + 800001
dois_without_unpaywall
# In[53]:
dois_without_unpaywall[['id', 'doi']].to_csv('export_dois_without_unpaywall.tsv', sep='\t', index=False)
# In[54]:
# export files
unige_all.to_csv('unige_all_oa_status_citations.csv', sep='\t', index=False, encoding='utf-8')
# unige_all.to_excel('unige_all_oa_status_citations.xlsx', index=False)
iarc_all.to_csv('iarc_all_oa_status_citations.csv', sep='\t', index=False, encoding='utf-8')
iarc_all.to_excel('iarc_all_oa_status_citations.xlsx', index=False)
# In[ ]: