0
|
1 #!/usr/bin/env python
|
|
2
|
|
3 """
|
|
4 Script that imports locally stored data as a new dataset for the user
|
|
5 Usage: import id outputfile
|
|
6 """
|
|
7 import sys, os
|
|
8
|
|
9 assert sys.version_info[:2] >= ( 2, 4 )
|
|
10
|
|
11 BUFFER = 1048576
|
|
12
|
|
13 dataid = sys.argv[1]
|
|
14 out_name = sys.argv[2]
|
|
15
|
|
16
|
|
17 id2name = {
|
|
18 'eryth' : 'ErythPreCRMmm3_cusTrk.txt',
|
|
19 'cishg16' : 'ReglRegHBBhg16CusTrk.txt',
|
|
20 'cishg17' : 'ReglRegHBBhg17CusTrk.txt',
|
|
21 'exons' : 'ExonsKnownGenes_mm3.txt',
|
|
22 'krhg16' : 'known_regulatory_hg16.bed',
|
|
23 'krhg17' : 'known_regulatory_hg17.bed',
|
|
24 'tARhg16mmc' : 'hg16.mouse.t_AR.cold.bed',
|
|
25 'tARhg16mmm' : 'hg16.mouse.t_AR.medium.bed',
|
|
26 'tARhg16mmh' : 'hg16.mouse.t_AR.hot.bed',
|
|
27 'tARhg16rnc' : 'hg16.rat.t_AR.cold.bed',
|
|
28 'tARhg16rnm' : 'hg16.rat.t_AR.medium.bed',
|
|
29 'tARhg16rnh' : 'hg16.rat.t_AR.hot.bed',
|
|
30 'phastConsHg16' : 'phastConsMost_hg16.bed',
|
|
31 'omimhg16' : 'omimDisorders_hg16.tab',
|
|
32 'omimhg17' : 'omimDisorders_hg17.tab',
|
|
33
|
|
34 }
|
|
35
|
|
36 fname = id2name.get(dataid, '')
|
|
37 if not fname:
|
|
38 print 'Importing invalid data %s' % dataid
|
|
39 sys.exit()
|
|
40 else:
|
|
41 print 'Imported %s' % fname
|
|
42
|
|
43 # this path is hardcoded
|
|
44 inp_name = os.path.join('database', 'import', fname)
|
|
45
|
|
46 try:
|
|
47 inp = open(inp_name, 'rt')
|
|
48 except:
|
|
49 print 'Could not find file %s' % inp_name
|
|
50 sys.exit()
|
|
51
|
|
52 out = open(out_name, 'wt')
|
|
53
|
|
54 while 1:
|
|
55 data = inp.read(BUFFER)
|
|
56 if not data:
|
|
57 break
|
|
58 out.write(data)
|
|
59
|
|
60 inp.close()
|
|
61 out.close()
|