-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_dbgap_example_data.py
160 lines (149 loc) · 5.96 KB
/
add_dbgap_example_data.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
# Temporary script to create some test data.
# Run with: python manage.py shell < add_cdsa_example_data.py
from anvil_consortium_manager.tests.factories import (
AccountFactory,
GroupAccountMembershipFactory,
GroupGroupMembershipFactory,
)
from primed.dbgap import models
from primed.dbgap.tests import factories
from primed.primed_anvil.tests.factories import StudyFactory
from primed.users.tests.factories import UserFactory
# Studies
try:
fhs = models.Study.objects.get(short_name="FHS")
except models.Study.DoesNotExist:
fhs = StudyFactory.create(short_name="FHS", full_name="Framingham Heart Study")
try:
mesa = models.Study.objects.get(short_name="MESA")
except models.Study.DoesNotExist:
mesa = StudyFactory.create(short_name="MESA", full_name="Multi-Ethnic Study of Atherosclerosis")
try:
aric = models.Study.objects.get(short_name="ARIC")
except models.Study.DoesNotExist:
aric = StudyFactory.create(short_name="ARIC", full_name="Atherosclerosis Risk in Communities")
# dbGaP study accessions
dbgap_study_accession_fhs = factories.dbGaPStudyAccessionFactory.create(dbgap_phs=7, studies=[fhs])
dbgap_study_accession_mesa = factories.dbGaPStudyAccessionFactory.create(dbgap_phs=209, studies=[mesa])
dbgap_study_accession_aric = factories.dbGaPStudyAccessionFactory.create(dbgap_phs=280, studies=[aric])
# Create some dbGaP workspaces.
workspace_fhs_1 = factories.dbGaPWorkspaceFactory.create(
dbgap_study_accession=dbgap_study_accession_fhs,
dbgap_version=33,
dbgap_participant_set=12,
dbgap_consent_code=1,
dbgap_consent_abbreviation="HMB",
workspace__name="DBGAP_FHS_v33_p12_HMB",
)
workspace_fhs_2 = factories.dbGaPWorkspaceFactory.create(
dbgap_study_accession=dbgap_study_accession_fhs,
dbgap_version=33,
dbgap_participant_set=12,
dbgap_consent_code=2,
dbgap_consent_abbreviation="GRU",
workspace__name="DBGAP_FHS_v33_p12_GRU",
)
workspace_mesa_1 = factories.dbGaPWorkspaceFactory.create(
dbgap_study_accession=dbgap_study_accession_mesa,
dbgap_version=2,
dbgap_participant_set=1,
dbgap_consent_code=1,
dbgap_consent_abbreviation="HMB-NPU",
workspace__name="DBGAP_MESA_v2_p1_HMB-NPU",
)
workspace_mesa_2 = factories.dbGaPWorkspaceFactory.create(
dbgap_study_accession=dbgap_study_accession_mesa,
dbgap_version=2,
dbgap_participant_set=1,
dbgap_consent_code=2,
dbgap_consent_abbreviation="HMB-NPU-IRB",
workspace__name="DBGAP_MESA_v2_p1_HMB-NPU-IRB",
)
workspace_aric = factories.dbGaPWorkspaceFactory.create(
dbgap_study_accession=dbgap_study_accession_aric,
dbgap_version=3,
dbgap_participant_set=1,
dbgap_consent_code=1,
dbgap_consent_abbreviation="HMB",
workspace__name="DBGAP_ARIC_v3_p1_HMB",
)
# Create some dbGaP applications
dbgap_application_1 = factories.dbGaPApplicationFactory.create(
principal_investigator=UserFactory.create(name="Ken", username="Ken"),
dbgap_project_id=33119,
)
# Add a snapshot
dar_snapshot_1 = factories.dbGaPDataAccessSnapshotFactory.create(dbgap_application=dbgap_application_1)
# Add some data access requests.
dar_1_1 = factories.dbGaPDataAccessRequestForWorkspaceFactory.create(
dbgap_workspace=workspace_fhs_1,
dbgap_data_access_snapshot=dar_snapshot_1,
dbgap_dac="NHLBI",
dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED,
)
dar_1_2 = factories.dbGaPDataAccessRequestForWorkspaceFactory.create(
dbgap_workspace=workspace_fhs_2,
dbgap_data_access_snapshot=dar_snapshot_1,
dbgap_dac="NHLBI",
dbgap_current_status=models.dbGaPDataAccessRequest.REJECTED,
)
dar_1_3 = factories.dbGaPDataAccessRequestForWorkspaceFactory.create(
dbgap_workspace=workspace_mesa_1,
dbgap_data_access_snapshot=dar_snapshot_1,
dbgap_dac="NHLBI",
dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED,
)
dar_1_4 = factories.dbGaPDataAccessRequestForWorkspaceFactory.create(
dbgap_workspace=workspace_mesa_2,
dbgap_data_access_snapshot=dar_snapshot_1,
dbgap_dac="NHLBI",
dbgap_current_status=models.dbGaPDataAccessRequest.REJECTED,
)
dar_1_5 = factories.dbGaPDataAccessRequestFactory(
dbgap_data_access_snapshot=dar_snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED,
)
dbgap_application_2 = factories.dbGaPApplicationFactory.create(
principal_investigator=UserFactory.create(name="Alisa", username="Alisa"),
dbgap_project_id=33371,
)
# Add a snapshot
dar_snapshot_2 = factories.dbGaPDataAccessSnapshotFactory.create(dbgap_application=dbgap_application_2)
# Add some data access requests, only for FHS.
dar_1_1 = factories.dbGaPDataAccessRequestForWorkspaceFactory.create(
dbgap_workspace=workspace_fhs_1,
dbgap_data_access_snapshot=dar_snapshot_2,
dbgap_dac="NHLBI",
dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED,
)
dar_1_2 = factories.dbGaPDataAccessRequestForWorkspaceFactory.create(
dbgap_workspace=workspace_fhs_2,
dbgap_data_access_snapshot=dar_snapshot_2,
dbgap_dac="NHLBI",
dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED,
)
# Now add dbGaP access groups.
GroupGroupMembershipFactory.create(
parent_group=workspace_fhs_1.workspace.authorization_domains.first(),
child_group=dbgap_application_1.anvil_access_group,
)
# Add the PI to the access group for the first application.
GroupAccountMembershipFactory.create(
group=dbgap_application_1.anvil_access_group,
account__user=dbgap_application_1.principal_investigator,
)
# Add some collaborators for the first application.
users = UserFactory.create_batch(3)
dbgap_application_1.collaborators.add(users[0])
GroupAccountMembershipFactory.create(
group=dbgap_application_1.anvil_access_group,
account__user=users[0],
)
# # Do not add as an collaborator so we can check auditing.
# dbgap_application_1.collaborators.add(users[1])
GroupAccountMembershipFactory.create(
group=dbgap_application_1.anvil_access_group,
account__user=users[1],
)
dbgap_application_1.collaborators.add(users[2])
AccountFactory.create(user=users[2], verified=True)