annotate select_on_rank.py @ 2:44bfd7e34b39

added comment
author pieter.lukasse@wur.nl
date Thu, 19 Mar 2015 10:39:27 +0100
parents dffc38727496
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
1 import csv
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
2 import sys
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
3
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
4 __author__ = "Marcel Kempenaar"
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
5 __contact__ = "brs@nbic.nl"
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
6 __copyright__ = "Copyright, 2012, Netherlands Bioinformatics Centre"
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
7 __license__ = "MIT"
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
8
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
9 in_file = sys.argv[1]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
10 out_file = sys.argv[2]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
11 to_select_list = [str(select.strip()) for select in sys.argv[3].split(',') if (len(select) > 0)]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
12
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
13 data = list(csv.reader(open(in_file, 'rb'), delimiter='\t'))
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
14 header = data.pop(0)
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
15 header_clean = [i.lower().strip().replace(".", "").replace("%", "") for i in header]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
16 rank = header_clean.index("rank")
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
17
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
18 writer = csv.writer(open(out_file, 'wb'), delimiter='\t')
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
19 writer.writerow(header)
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
20 for select in to_select_list:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
21 writer.writerows([i for i in data if i[rank] == select])