Add my script to convert Caltech's made_for field to htsworkflow 0.2's affiliation...
[htsworkflow.git] / docs / conv_caltech_v0.1_made_for.py
1 """
2 Read the made-for field and split them up into different affiliations
3 while fixing the different spellings for some of our users
4 """
5 import os
6
7 script_dir = os.path.split(__file__)[0]
8 settings_path = os.path.join(script_dir, 'htsworkflow','frontend')
9 os.environ['DJANGO_SETTINGS_MODULE'] = 'htsworkflow.frontend.settings'
10
11 from htsworkflow.frontend.samples import models as samples
12
13 def main():
14     # names  ( {'target name': ('current name', 'current name') )
15     names = [
16       'Unknown',
17       'Adam Rosenthal',
18       'Adler Dillman',
19       'Ali',
20       'Ali/EHD',
21       'Ali/PWS',
22       'Andrew Medina-Marino',
23       'Brian Williams',
24       'Davidson',
25       'Elowitz',
26       'Erich Schwarz',
27       'Georgi Warinov',
28       'Gilberto Desalvo',
29       'Gigio',
30       'Gordon Kwan',
31       'Hudson-Alpha',
32       'James Puckett',
33       'Jingli Zhang',
34       'Ellen Rothenberg',
35       'Jose Luis',
36       'Katherine Fisher',
37       'Meyerowitz',
38       'Ryan',
39       'Demo',
40       'Angela Stathopoulos',
41       'Steven Kuntz',
42       'Tony',
43       'Tristan',
44       'Yuling Jiao',
45     ]
46
47     name_map = {
48       '': ('Unknown',) ,
49       'Adam Rosenthal': ('Adam Rosenthal',),
50       'Adler Dillman': ('Adler Dillman',),
51       'Ali': ('Ali',),
52       'Ali/EHD': ('Ali/EHD',),
53       'Ali/PWS': ('Ali/PWS',),
54       'Andrew Medina-Marina': ('Andrew Medina-Marino',),
55       'Andrew Medina-Marino': ('Andrew Medina-Marino',),
56       'Brian': ('Brian Williams',),
57       'Brian Williams': ('Brian Williams',),
58       'Davidson': ('Davidson',),
59       'Elowitz': ('Elowitz',),
60       'Erich Schwarz': ('Erich Schwarz',),
61       'Erich Schwartz': ('Erich Schwarz',),
62       'Georgi Warinov': ('Georgi Warinov',),
63       'Gilberto Desalvo': ('Gilberto Desalvo',),
64       'Gordon Kwan': ('Gordon Kwan',),
65       'Gordon': ('Gordon Kwan',),
66       'Alpha-Hudson': ('Hudson-Alpha',),
67       'Hudson-Alpha': ('Hudson-Alpha',),
68       'James Puckett': ('James Puckett',),
69       'Jingli Zhang, Rothenberg': ('Jingli Zhang', 'Ellen Rothenberg',),
70       'Jingli Zhang': ('Jingli Zhang',),
71       'Jose Luis': ('Jose Luis',),
72       'Katherine Fisher': ('Katherine Fisher',),
73       'Katherine, Gigio': ('Katherine Fisher', 'Gigio',),
74       'Meyerowitz': ('Meyerowitz',),
75       'Ryan, Demo': ('Ryan', 'Demo',),
76       'Stathopoulos': ('Angela Stathopoulos',),
77       'Steve Kuntz': ('Steven Kuntz',),
78       'Steven Kuntz': ('Steven Kuntz',),
79       'Tony': ('Tony',),
80       'Tristan': ('Tristan',),
81       'Yuling Jiao': ('Yuling Jiao',),
82     }
83
84     affiliations = {}
85     for name in names:
86       aff = samples.Affiliation(name=name)
87       affiliations[name] = aff
88       aff.save()
89
90     for lib in samples.Library.objects.all():
91       made_list = name_map[lib.made_for]
92       assert type(made_list) == type((None,))
93       affiliation_list = []
94       for n in made_list:
95         lib.affiliations.add(affiliations[n])
96       lib.save()
97
98 if __name__ == "__main__":
99   print "don't run this unless you know what its for"
100   print "it converts the caltech 'made_for' field into a set of"
101   print "affiliations."
102   print ""
103   print "The user lists are hard coded and exist mostly for my"
104   print "convienence."
105   #main()