Beispiel #1
0
        gtm_fname = arg
    elif os.path.splitext(arg)[1] in ['png', 'pdf', 'ps', 'dot']:
        out_fnames.append(arg)
    else:
        color_fnames.append(arg)
if len(color_fnames) == 0:
    parser.error("Specify a color file")

guess = gtm_fname is None
for input_index, color_fname in enumerate(color_fnames):
    if input_index < len(out_fnames):
        out_fname = out_fnames[input_index]
    else:
        out_fname = strip_ext(color_fname) + "." + options.out_type
    if guess: gtm_fname = guess_gtmfile2(color_fname, False)
    gtm = GtmFile(gtm_fname)
    try:
        gtm.map = GtmMap(gtm_fname)
    except IOError:
        gtm.map = None
    if gtm.map is None or gtm.map.fname is None:
        if show_ind_label == "map" or show_ind_label == "index":
            ind_label = lambda i, t: "%d" % (i)
            time_label = lambda t: "%d" % (t)
        elif show_ind_label == "both":
            # both index
            ind_label = lambda i, t: "%d" % (i)
            time_label = lambda t: "T%d" % (t)
        else:
            raise Exception("ERROR")
    else:
Beispiel #2
0
    def __init__(self, color2_fname, gtmdata=None, typesep=None):

        if gtmdata is None:
            gtmdata = GtmFile(color2_fname)
            assert gtmdata is not None

        self.gtm = gtmdata
        if color2_fname == '-':
            f = sys.stdin
        else:
            f = open(color2_fname, 'r')

        num = len(gtmdata.group) + len(gtmdata.inds) * len(gtmdata.times)

        line = f.readline()
        assert line != "", "First line in %s is empty" % color2_fname
        tmp = line.split()

        if typesep is None:
            try:
                x = int(tmp[0])
                typesep = (x == 1)
            except ValueError:
                typesep = False

        #print "typesep", typesep
        if not typesep:  # convert 1char to sep
            tmp2 = []
            for field in tmp:
                for c in field:
                    try:
                        x = int(c)
                    except ValueError:
                        raise Exception("Invalid color '%s'" % c)
                        x = ord(c) - ord('A')
                        if (x < 0):
                            x = ord(c) - ord('a')
                        assert x >= 0
                        x += 10
                    tmp2.append(x)
            tmp = tmp2

        if len(tmp) == 0:
            self.group_color = None
            self.ind_color = None
            #self.max_exist_color = None
        else:
            if len(tmp) < num:
                raise Exception, "coloring %s is shorter than gtm file. " \
                    "%d colors while %d objects" %(color2_fname, len(tmp), num)

            tmp = map(int, tmp)
            self.max_exist_color = max(tmp)

            assert len(tmp) == gtmdata.group_count + \
                gtmdata.ind_count*gtmdata.time_count, \
                "len in color file %d != len in gtm file %d" %\
                    (len(tmp), gtmdata.group_count + \
                    gtmdata.ind_count*gtmdata.time_count)

            offset = len(gtmdata.group)
            time_count = len(gtmdata.times)
            self.group_color = tmp[0:offset]
            self.ind_color = {}
            for i in gtmdata.inds:
                self.ind_color[i - 1] = tmp[offset:offset + time_count]
                offset += time_count

            if offset != len(tmp):
                raise Exception, "coloring is longer than gtm file. " \
                    "len(tmp)==%d while offset==%d" %(len(tmp), offset)