root/galaxy-central/tools/data_source/import.py

リビジョン 2, 1.4 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#!/usr/bin/env python
2
3"""
4Script that imports locally stored data as a new dataset for the user
5Usage: import id outputfile
6"""
7import sys, os
8
9assert sys.version_info[:2] >= ( 2, 4 )
10
11BUFFER = 1048576
12
13dataid   = sys.argv[1]
14out_name = sys.argv[2]
15
16
17id2name = {
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
36fname = id2name.get(dataid, '')
37if not fname:
38    print 'Importing invalid data %s' % dataid
39    sys.exit()
40else:
41    print 'Imported %s' % fname
42
43# this path is hardcoded
44inp_name = os.path.join('database', 'import', fname)
45
46try:
47    inp = open(inp_name, 'rt')
48except:
49    print 'Could not find file %s' % inp_name
50    sys.exit()
51
52out = open(out_name, 'wt')
53
54while 1:
55    data = inp.read(BUFFER)
56    if not data:
57        break
58    out.write(data)
59
60inp.close()
61out.close()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。