@@ -0,0 +1,2478 @@
+import logging%0Aimport multiprocessing%0Aimport os%0Aimport tempfile%0Aimport yaml%0Afrom collections import OrderedDict%0A%0A# Adapted from: https://github.com/pnnl/atlas/blob/master/atlas/conf.py%0A%0A%0Adef get_sample_files(path):%0A    samples = OrderedDict()%0A    seen = set()%0A    for dir_name, sub_dirs, files in os.walk(path):%0A        for fname in files:%0A%0A            if %22.fastq%22 in fname or %22.fq%22 in fname:%0A%0A                sample_id = fname.partition(%22.fastq%22)%5B0%5D%0A                if %22.fq%22 in sample_id:%0A                    sample_id = fname.partition(%22.fq%22)%5B0%5D%0A%0A                sample_id = sample_id.replace(%22_R1%22, %22%22).replace(%22_r1%22, %22%22).replace(%22_R2%22, %22%22).replace(%22_r2%22, %22%22)%0A                sample_id = sample_id.replace(%22_%22, %22-%22).replace(%22 %22, %22-%22)%0A%0A                fq_path = os.path.join(dir_name, fname)%0A                fastq_paths = %5Bfq_path%5D%0A%0A                if fq_path in seen: continue%0A%0A                if %22_R1%22 in fname or %22_r1%22 in fname:%0A                    r2_path = os.path.join(dir_name, fname.replace(%22_R1%22, %22_R2%22).replace(%22_r1%22, %22_r2%22))%0A                    if not r2_path == fq_path:%0A                        seen.add(r2_path)%0A                        fastq_paths.append(r2_path)%0A%0A                if %22_R2%22 in fname or %22_r2%22 in fname:%0A                    r1_path = os.path.join(dir_name, fname.replace(%22_R2%22, %22_R1%22).replace(%22_r2%22, %22_r1%22))%0A                    if not r1_path == fq_path:%0A                        seen.add(r1_path)%0A                        fastq_paths.insert(0, r1_path)%0A%0A                if sample_id in samples:%0A                    logging.warn(%22Duplicate sample %25s was found after renaming; skipping...%22 %25 sample_id)%0A                    continue%0A                samples%5Bsample_id%5D = %7B'path': fastq_paths %7D%0A    return samples%0A%0A%0Adef make_config(config, path):%0A    %22%22%22Write the file %60config%60 and complete the sample names and paths for all files in %60path%60.%22%22%22%0A    represent_dict_order = lambda self, data:  self.represent_mapping('tag:yaml.org,2002:map', data.items())%0A    yaml.add_representer(OrderedDict, represent_dict_order)%0A    path = os.path.realpath(path)%0A%0A    conf = OrderedDict()%0A    samples = get_sample_files(path)%0A%0A    logging.info(%22Found %25d samples under %25s%22 %25 (len(samples), path))%0A    conf%5B%22samples%22%5D = samples%0A%0A    with open(config, %22w%22) as f:%0A        print(yaml.dump(conf, default_flow_style=False), file=f)%0A    logging.info(%22Configuration file written to %25s%22 %25 config)%0A%0Aif __name__ == %22__main__%22:%0A    make_config(config=%22config.yaml%22, path=%22data%22)%0A  %0A

Add initial config generation script