Created
June 5, 2014 12:16
-
-
Save terrycojones/2cdf9358aa1f91aa7f53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
from collections import defaultdict | |
def parseColors(colors): | |
""" | |
Parse read id color specification. | |
@param colors: A C{list}, each of whose elements is a C{str} such as | |
'green id1 id2', where each of id1, id2 etc. is either a read | |
identifier or the name of a file containing read identifiers one | |
per line. | |
@return: A C{dict} whose keys are colors and whose values are sets of | |
read identifiers. | |
""" | |
result = defaultdict(set) | |
for colorInfo in colors: | |
readIds = colorInfo.split() | |
color = readIds.pop(0) | |
for readId in readIds: | |
if os.path.isfile(readId): | |
with open(readId, 'r') as fp: | |
for line in fp: | |
result[color].add(line.rstrip()) | |
else: | |
result[color].add(readId) | |
return result | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--color', action='append') | |
args = parser.parse_args() | |
for color, ids in parseColors(args.color).iteritems(): | |
print '%s: %s' % (color, ids) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment