コード例 #1
0
def list_or_files(*args):
    """
    
    Return the contents of *args as dict[name] = list pairs regardless of whether the user provided a filename or dict
    If a list is provided, it will be appended to the dict with key ''

    Returns a dict of name->list pairs

    WARNING: This function uses base names, not the full path!  If the base names are the same, one will be ignored!

    """

    ndict = {}

    for lst in args:
        if isinstance(lst, list):
            ndict.setdefault('', []).extend(lst)
            print("WARNING: List received! Multiple lists are concatenated!")

        elif isinstance(lst, dict):
            ndict.update(lst)
        
        else:
            name = os.path.basename(lst)
            ndict[name] = parsers.get_list_from_file(lst)

    return ndict
コード例 #2
0
def km(timeconv, eventconv, *clusts):
    """
    Draw the kaplan-meier curves for a number of clusters
    
    timeconv - file of tab-delim table of sample id -> survival time conversions
    eventconv - file of tab-delim table of sample id -> event conversions (ie, 1 for yes, 0 for no, anything else for NA)
    clusts - cluster filenames
    
    """
    tc = parsers.read_table(timeconv)
    ec = parsers.read_table(eventconv)

    labels = []
    times = []
    events = []

    for clust in clusts:

        cl = parsers.get_list_from_file(clust)
       
        ts = []
        ev = []

        for sam in cl:
            try:
                time = float(tc[sam])
                event = int(ec[sam])

                ts.append(time)
                ev.append(event)
            except:
                pass

        labels.append(clust)
        times.append(ts)
        events.append(ev)

    display.km(times, events, labels)