Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code changes to reflect data curation and cleanup results #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions scripts/all_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
>>> len(data_files)
11
'''
'''
# ls note: deposit date ideally would have been 2005 for all datasets; when not indicated by repository,
date of publication used (as per http://researchremix.wordpress.com/2011/02/16/choosing-repositories-for-the-tracking-data-reuse-project/:
"In some repositories it is very difficult to determine the date of deposit.
I use date of article publication as an imperfect proxy.") cf. Jonathan's notes (https://notebooks.dataone.org/data-reuse/links-to-our-data/)

'''
import csv
import os
import fnmatch
Expand All @@ -15,14 +21,18 @@

year_regex = re.compile('[(\[ ]([1-2][0-9]{3})[)\].]')

data_files = fnmatch.filter(os.listdir('data/repo_datasets/'),
'*_datasets.csv')
# ls data_files = fnmatch.filter(os.listdir('data/repo_datasets/'),
# ls '*_datasets.csv')

data_files = fnmatch.filter(os.listdir('data/cleaner_old_all_datasets/'),
'*.tsv')

if __name__ == '__main__':
print 'repo\tid\twos\tgs\tyear'

for data_file in data_files:
path = os.path.join('data/repo_datasets', data_file)
# ls path = os.path.join('data/repo_datasets', data_file)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lsheble would you mind deleting these # ls lines. Git tracks and highlights the exact change already, and so not keeping a commented-out version of the changed line actually makes the diff much clearer for seeing quickly what changed.

path = os.path.join('data/cleaner_old_all_datasets', data_file)
repo = clean_repo_name(data_file[:-len('_datasets.csv')])
with open(path) as input_file:
r = csv.reader(input_file)
Expand All @@ -43,9 +53,10 @@
gs_col = gs_cols[0]
except IndexError:
gs_col = None

date_cols = [n for n, x in enumerate(header)
if 'date' in x.lower() or 'year' in x.lower()]
# ls if 'date' in x.lower() or 'year' in x.lower()]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lsheble same as for other comment - would you mind deleting these # ls lines.

if 'date made public' in x.lower()]

try:
assert len(date_cols) == 1
date_col = date_cols[0]
Expand All @@ -57,6 +68,8 @@
# if there's not a date column, try to parse it out of each
# line with regular expressions
date_col = None



for line in r:
if len(line) <= 1: continue
Expand All @@ -69,6 +82,8 @@
vals.append(wos)

if gs_col is None: gs = 0
# ls: do we want to account for NA's like this?
elif: gs_col == 'NA': gs = 0
else:
gs = line[gs_col].split()[0]
if not gs.strip(): gs = 0
Expand Down
8 changes: 5 additions & 3 deletions scripts/get_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ def main(file_path):
vals = line.split('\t')
repo = vals[1]
accession = vals[2]
longest = sorted(vals, key=lambda k: len(k), reverse=True)[0].replace('\n', '').replace('\r', '')
if longest.startswith('http'): continue
if len(longest) < 100: continue
# ls longest = sorted(vals, key=lambda k: len(k), reverse=True)[0].replace('\n', '').replace('\r', '')
# ls if longest.startswith('http'): continue
# ls if len(longest) < 100: continue
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lsheble same as for other comment - would you mind deleting these # ls lines.

# article reference is in column 8 in the data table/spreadsheet that combines repos
longest = vals[8]
print '\t'.join((repo, accession, longest))

if __name__ == '__main__':
Expand Down