Skip to content

Commit 82ef09f

Browse files
committed
Merge branch 'develop' into main
2 parents a50e670 + 811a041 commit 82ef09f

File tree

7 files changed

+81
-71
lines changed

7 files changed

+81
-71
lines changed

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build: egg
2+
egg:
3+
python setup.py bdist_egg
4+
5+
clean:
6+
rm -rf dist/ build/ nacculator.egg-info/
7+
find . -name '*.pyc' | xargs rm

README

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NACCulator
1+
NACCulator
22

33
Converts a CSV data file exported from REDCap into the NACC's UDS3 fixed-width
44
format.
@@ -9,30 +9,30 @@ FILES
99
This is not exhaustive, but here is an explanation of some important files.
1010

1111
nacc/:
12-
Top-level Python package for all things NACC.
12+
Top-level Python package for all things NACC.
1313

1414
nacc/redcap2nacc.py:
15-
converts a CSV data file exported from REDCap into NACC's UDS3 fixed-width
16-
format
15+
converts a CSV data file exported from REDCap into NACC's UDS3 fixed-width
16+
format
1717

1818
nacc/uds3/blanks.py:
19-
specialized library for "Blanking Rules"
19+
specialized library for "Blanking Rules"
2020

2121
nacc/uds3/ivp/forms.py:
22-
UDS3 IVP forms represented as Python classes
22+
UDS3 IVP forms represented as Python classes
2323

2424
tools/generator.py:
25-
generates Python objects based on NACC Data Element Dictionaries in CSV
25+
generates Python objects based on NACC Data Element Dictionaries in CSV
2626

2727

2828
HOWTO Convert from REDCap to NACC
2929
---------------------------------
3030

31-
$ pip install nacculator
32-
$ redcap2nacc < data.csv > data.nacc
31+
$ pip install nacculator
32+
$ redcap2nacc < data.csv > data.nacc
3333

3434
Manually:
35-
$ PYTHONPATH=. ./nacc/redcap2nacc.py data.csv > data.nacc
35+
$ PYTHONPATH=. ./nacc/redcap2nacc.py data.csv > data.nacc
3636

3737
Note: output is written to STDOUT; errors are written to STDERR; input can be
3838
STDIN or the first argument passed to redcap2nacc.
@@ -41,11 +41,11 @@ HOWTO Generate New Forms
4141
------------------------
4242

4343
Note: executing generator.py from within tools is an important step as the
44-
script assumes any corrected DEDs are stored under a folder in the
45-
current working directory called 'corrected'.
44+
script assumes any corrected DEDs are stored under a folder in the
45+
current working directory called 'corrected'.
4646

4747
Warning: read the warnings in the current ../nacc/uds3/ivp/forms.py first.
4848

49-
$ cd tools
50-
$ PYTHONPATH=.. ./generator.py uds3/ded/csv/ > ../nacc/uds3/ivp/forms.py
51-
$ edit ../nacc/uds3/ivp/forms
49+
$ cd tools
50+
$ PYTHONPATH=.. ./generator.py uds3/ded/csv/ > ../nacc/uds3/ivp/forms.py
51+
$ edit ../nacc/uds3/ivp/forms

nacc/redcap2nacc.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
import re
1111
import sys
1212

13-
from nacc.uds3 import ivp
14-
from nacc.uds3.ivp import forms as ivp_forms
1513
from nacc.uds3 import blanks
14+
from nacc.uds3.ivp import forms as ivp_forms
15+
from nacc.uds3.ivp import packet as ivp_packet
1616

1717

1818
def udsv3_ivp_from_redcap_csv(record):
1919
""" Converts REDCap CSV data into a packet (list of IVP Form objects) """
20-
packet = ivp.Packet()
20+
packet = ivp_packet.Packet()
2121

2222
# Set up us the forms
2323
a1 = ivp_forms.FormA1()

nacc/uds3/ivp/__init__.py

-40
Original file line numberDiff line numberDiff line change
@@ -1,40 +0,0 @@
1-
###############################################################################
2-
# Copyright 2015-2016 University of Florida. All rights reserved.
3-
# This file is part of UF CTS-IT's NACCulator project.
4-
# Use of this source code is governed by the license found in the LICENSE file.
5-
###############################################################################
6-
7-
class Packet(list):
8-
"""
9-
A collection of UDS Forms
10-
11-
This class is makes it convenient to access a field, which are all uniquely
12-
named, regardless of which form they are in with the exception of A4D.
13-
"""
14-
15-
def __init__(self):
16-
self._cache = dict()
17-
18-
def __getitem__(self, key):
19-
"""
20-
Searches through each form in the packet for the field, `key`
21-
22-
Note: you cannot access fields in A4D in this manner since there is no
23-
guarantee there will only be one; a KeyError will be raised.
24-
25-
Example:
26-
packet['RESTTRL'] is equivalent to:
27-
packet.__getitem__('RESTTRL')
28-
"""
29-
if key in self._cache:
30-
return self._cache[key]
31-
32-
for form in self:
33-
if key in form.fields:
34-
if "A4D" in str(form.__class__):
35-
raise KeyError("Form A4D is unsupported")
36-
self._cache[key] = form.fields[key]
37-
return self._cache[key]
38-
39-
raise KeyError(key)
40-

nacc/uds3/ivp/packet.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
###############################################################################
2+
# Copyright 2015-2016 University of Florida. All rights reserved.
3+
# This file is part of UF CTS-IT's NACCulator project.
4+
# Use of this source code is governed by the license found in the LICENSE file.
5+
###############################################################################
6+
7+
class Packet(list):
8+
"""
9+
A collection of UDS Forms
10+
11+
This class is makes it convenient to access a field, which are all uniquely
12+
named, regardless of which form they are in with the exception of A4D.
13+
"""
14+
15+
def __init__(self):
16+
self._cache = dict()
17+
18+
def __getitem__(self, key):
19+
"""
20+
Searches through each form in the packet for the field, `key`
21+
22+
Note: you cannot access fields in A4D in this manner since there is no
23+
guarantee there will only be one; a KeyError will be raised.
24+
25+
Example:
26+
packet['RESTTRL'] is equivalent to:
27+
packet.__getitem__('RESTTRL')
28+
"""
29+
if key in self._cache:
30+
return self._cache[key]
31+
32+
for form in self:
33+
if key in form.fields:
34+
if "A4D" in str(form.__class__):
35+
raise KeyError("Form A4D is unsupported")
36+
self._cache[key] = form.fields[key]
37+
return self._cache[key]
38+
39+
raise KeyError(key)
40+

setup.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66

77
from setuptools import setup
88

9+
VERSION="0.1.1"
10+
911
setup(
10-
name="NACCulator",
11-
version="0.1.0",
12+
name="nacculator",
13+
version=VERSION,
14+
author="Taeber Rapczak",
15+
author_email="taeber@ufl.edu",
16+
maintainer="UF CTS-IT",
17+
maintainer_email="ctsit@ctsi.ufl.edu",
18+
url="https://github.com/ctsit/nacculator",
19+
license=open('LICENSE').read(),
20+
description="CSV to NACC's UDS3 format converter",
21+
keywords=["REDCap", "NACC", "UDS", "Clinical data"],
22+
download_url="https://github.com/ctsit/nacculator/releases/tag/" + VERSION,
23+
1224
packages=["nacc"],
1325
entry_points={
1426
"console_scripts": [
1527
"redcap2nacc = nacc.redcap2nacc:main"
1628
]
17-
},
18-
author="Taeber Rapczak",
19-
author_email="taeber@ufl.edu",
20-
description="CSV to NACC's UDS3 format converter",
21-
license="BSD 2-Clause",
22-
23-
url='https://github.com/ctsit/nacculator',
24-
download_url='https://github.com/ctsit/nacculator/releases/tag/0.1.0',
25-
keywords=['REDCap', 'NACC', 'UDS', 'Clinical data'],
29+
}
2630
)

tools/generator.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/usr/bin/env python
2+
# coding=ascii
23
###############################################################################
34
# Copyright 2015-2016 University of Florida. All rights reserved.
45
# This file is part of UF CTS-IT's NACCulator project.
56
# Use of this source code is governed by the license found in the LICENSE file.
67
###############################################################################
78

8-
# coding=ascii
9-
109
import csv
1110
import os
1211
import re

0 commit comments

Comments
 (0)