Ejemplo n.º 1
0
def info(args):
    input_dirs = args.input_dirs
    if input_dirs is None:
        logging.error('Please specify SSEA directories using "-d" or "--dir"')
        return 1
    for path in find_paths(input_dirs):
        sample_set_json_file = os.path.join(path, Config.SAMPLE_SET_JSON_FILE)
        sample_set = SampleSet.parse_json(sample_set_json_file)[0]
        compname = computerize_name(sample_set.name)
        print '\t'.join([compname, path])
Ejemplo n.º 2
0
def info(args):
    input_dirs = args.input_dirs
    if input_dirs is None:
        logging.error('Please specify SSEA directories using "-d" or "--dir"')
        return 1
    for path in find_paths(input_dirs):
        sample_set_json_file = os.path.join(path, Config.SAMPLE_SET_JSON_FILE)
        sample_set = SampleSet.parse_json(sample_set_json_file)[0]
        compname = computerize_name(sample_set.name)
        print '\t'.join([compname, path])        
Ejemplo n.º 3
0
def to_smx(args):
    filename = args.sample_set_file
    sep = args.sep
    prefix = args.prefix
    if not os.path.exists(filename):
        logging.error("Sample set file '%s' not found" % (filename))
        return 1
    for ss in _parse_sample_sets(filename, sep):
        lines = []
        lines.append('\t'.join(['name', ss.name]))
        lines.append('\t'.join(['desc', ss.desc]))
        for sample in sorted(ss.value_dict):
            lines.append('\t'.join([sample, str(ss.value_dict[sample])]))
        suffix = computerize_name(ss.name)
        path = prefix + '.' + suffix + '.smx'
        with open(path, 'w') as f:
            for line in lines:
                print >>f, line
Ejemplo n.º 4
0
def merge(args):
    # get args
    input_paths_file = args.input_paths_file
    input_dirs = args.input_dirs
    output_dir = args.output_dir
    # check args
    input_paths = set()
    if input_paths_file is not None:
        if not os.path.exists(input_paths_file):
            logging.error('Input paths file "%s" not found' %
                          (input_paths_file))
        else:
            with open(input_paths_file) as fileh:
                for line in fileh:
                    path = line.strip()
                    if check_path(path):
                        input_paths.add(path)
    if input_dirs is not None:
        input_paths.update(find_paths(input_dirs))
    if len(input_paths) == 0:
        logging.error('No valid SSEA results directories found.. Exiting.')
        return 1
    if not os.path.exists(output_dir):
        logging.debug('Creating output directory "%s"' % (output_dir))
        os.makedirs(output_dir)
    # read paths already in output directory
    existing_paths = set()
    for path in glob.iglob(os.path.join(output_dir, "*")):
        if os.path.exists(path) and os.path.isdir(path):
            existing_paths.add(path)
    # merge input paths
    for src in input_paths:
        sample_set_json_file = os.path.join(src, Config.SAMPLE_SET_JSON_FILE)
        sample_set = SampleSet.parse_json(sample_set_json_file)[0]
        dirname = computerize_name(sample_set.name)
        dst = os.path.join(output_dir, dirname)
        if os.path.exists(dst):
            logging.error(
                'Conflict when merging sample set name "%s" from path "%s"' %
                (sample_set.name, src))
        else:
            logging.debug('Moving sample set "%s" from "%s" to "%s"' %
                          (sample_set.name, src, dst))
            shutil.move(src, dst)
Ejemplo n.º 5
0
def merge(args):
    # get args
    input_paths_file = args.input_paths_file
    input_dirs = args.input_dirs
    output_dir = args.output_dir
    # check args
    input_paths = set()
    if input_paths_file is not None:
        if not os.path.exists(input_paths_file):
            logging.error('Input paths file "%s" not found' % (input_paths_file))
        else:
            with open(input_paths_file) as fileh:
                for line in fileh:
                    path = line.strip()
                    if check_path(path):
                        input_paths.add(path)
    if input_dirs is not None:
        input_paths.update(find_paths(input_dirs))
    if len(input_paths) == 0:
        logging.error('No valid SSEA results directories found.. Exiting.')
        return 1
    if not os.path.exists(output_dir):
        logging.debug('Creating output directory "%s"' % (output_dir))
        os.makedirs(output_dir)
    # read paths already in output directory
    existing_paths = set()
    for path in glob.iglob(os.path.join(output_dir, "*")):
        if os.path.exists(path) and os.path.isdir(path):
            existing_paths.add(path)
    # merge input paths
    for src in input_paths:
        sample_set_json_file = os.path.join(src, Config.SAMPLE_SET_JSON_FILE)
        sample_set = SampleSet.parse_json(sample_set_json_file)[0]
        dirname = computerize_name(sample_set.name)
        dst = os.path.join(output_dir, dirname)
        if os.path.exists(dst):
            logging.error('Conflict when merging sample set name "%s" from path "%s"' % (sample_set.name, src))
        else:
            logging.debug('Moving sample set "%s" from "%s" to "%s"' % (sample_set.name, src, dst))
            shutil.move(src, dst)
Ejemplo n.º 6
0
def info(args):
    filename = args.sample_set_file
    sep = args.sep
    if not os.path.exists(filename):
        logging.error("Sample set file '%s' not found" % (filename))
        return 1
    print '\t'.join(['compname', 'name', 'desc', 'total', 'hits', 
                     'misses', 'nas'])
    for ss in _parse_sample_sets(filename, sep):
        hits = 0
        misses = 0
        nas = 0
        tot = 0
        for v in ss.value_dict.itervalues():
            if v == 1:
                hits += 1
            elif v == 0:
                misses += 1
            else:
                nas += 1
            tot += 1
        print '\t'.join(map(str, [computerize_name(ss.name), ss.name, ss.desc, tot, hits, misses, nas]))
Ejemplo n.º 7
0
def extract(args):
    list_file = args.sample_set_list_file
    sample_set_file = args.sample_set_file
    sep = args.sep
    if not os.path.exists(sample_set_file):
        logging.error("Sample set file '%s' not found" % (sample_set_file))
        return 1
    compname_dict = {}
    name_dict = {}
    for ss in _parse_sample_sets(sample_set_file, sep):
        compname_dict[computerize_name(ss.name)] = ss
        name_dict[ss.name] = ss
    with open(list_file) as fileh:
        for line in fileh:
            name = line.strip()
            found = False
            if name in compname_dict:
                print compname_dict[name].to_json()
                found = True
            elif name in name_dict:
                print name_dict[name].to_json()
                found = True
            if not found:
                logging.error('Sample set "%s" not found' % (name))