9 from commoncode import getConfigParser, getConfigOption, getConfigBoolOption
11 print "makesitetrack: version 2.2"
18 usage = "usage: python %prog sitefile outbedfile [--noheader] [--stype fieldID] [--color xx,yy,zz] [--append] [--exploded]"
20 parser = makeParser(usage)
21 (options, args) = parser.parse_args(argv[1:])
30 makesitetrack(infile, outfileName, options.stypeID, options.color, options.append, options.compact, options.noHeader)
33 def makeParser(usage=""):
34 parser = optparse.OptionParser(usage=usage)
35 parser.add_option("--noheader", action="store_true", dest="noHeader")
36 parser.add_option("--stype", type="int", dest="stypeID")
37 parser.add_option("--color", dest="color")
38 parser.add_option("--append", action="store_true", dest="append")
39 parser.add_option("--exploded", action="store_false", dest="compact")
41 configParser = getConfigParser()
42 section = "makesitetrack"
43 stypeID = getConfigOption(configParser, section, "stypeID", None)
44 color = getConfigOption(configParser, section, "color", "0,0,0")
45 append = getConfigBoolOption(configParser, section, "append", False)
46 compact = getConfigBoolOption(configParser, section, "compact", True)
47 noHeader = getConfigBoolOption(configParser, section, "noHeader", False)
49 parser.set_defaults(stypeID=stypeID, color=color, append=append, compact=compact, noHeader=noHeader)
54 def makesitetrack(infileName, outFileName, stypeID=None, color="0,0,0", append=False, compact=True, noHeader=False):
55 if stypeID is not None:
61 infile = open(infileName)
64 outfile = open(outFileName, "a")
66 outfile = open(outFileName, "w")
69 (name, extension) = outFileName.split(".")
71 name = outFileName.split(".")[:-1]
72 name = string.join(name, "_")
75 outfile.write('track name="%s" visibility=4 itemRgb="On"\n' % name)
84 (chrom, loc) = fields[0].split(":")
85 (start, stop) = loc.split("-")
93 stype = "%s-%s" % (name, str(count))
96 stype = fields[stypeID]
106 sense = fields[-2].strip()
107 if sense not in ["+", "-"]:
110 outfile.write("%s\t%s\t%d\t%s\t%s\t%s\t-\t-\t%s\n" % (chrom, start, int(stop) + 1, stype, score, sense, color))
116 if __name__ == "__main__":