root/galaxy-central/eggs/twill-0.9-py2.6.egg/twill/extensions/csv_iterate.py

リビジョン 3, 0.9 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1"""
2An extension function to iterate over a list of comma-separated values.
3
4Function 'csv_iterate' reads a file containing one or more rows of
5comma-separated columns, assigns them to col1...colN, and, for each row,
6executes the given twill script.
7"""
8
9__all__ = ['csv_iterate']
10
11DEBUG=True
12
13import csv
14
15def csv_iterate(filename, scriptname):
16    """
17    >> csv_iterate <csv_file> <script>
18
19    For each line in <csv_file>, read in a list of comma-separated values,
20    put them in $col1...$colN, and execute <script>.
21    """
22    from twill import namespaces, execute_file, commands
23
24    global_dict, local_dict = namespaces.get_twill_glocals()
25
26    reader = csv.reader(open(filename, "rb"))
27    for i, row in enumerate(reader):
28        if DEBUG:
29            print>>commands.OUT,'csv_iterate: on row %d of %s' % (i, filename,)
30        for i, col in enumerate(row):
31            global_dict["col%d" % (i + 1,)] = col
32
33        execute_file(scriptname, no_reset=True)
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。