def flat_directories(self): """The directories in this directory non-recursively, and sorted""" for root, dirs, files in os.walk(self.path): result = [DirectoryPath(os.path.join(root, d)) for d in dirs] break result.sort(key=lambda x: natural_sort(x.path)) return result
def load(self): """A delayed kind of __init__ that is not called right away to avoid crowding the RAM of the python interpreter when you just import gefes""" # Load # self.loaded = True # Automatic paths # self.p = AutoPaths(self.base_dir, self.all_paths) # Make an alias to the json # self.json_path.link_to(self.p.info_json, safe=True) # Make all the samples object that this project possesses # if self.info.get('auto_parse_samples'): search_dir = self.info['samples_base_dir'] search_dir = os.path.expanduser(search_dir) paths = glob.glob(search_dir + '*.fastq*') if not paths: paths = glob.glob(search_dir + '*.fasta*') if not paths: raise Exception("Found no FASTA or FASTQ path in %s" % search_dir) if all([re.search("_R[12]_", p) for p in paths]): pairs = join_paired_filepaths(paths) else: pairs = sort_string_by_pairs(paths) self.samples = [Sample(self, p[0], p[1], num=i) for i,p in enumerate(pairs)] self.samples.sort(key=lambda x: natural_sort(x.name)) else: self.samples = [Sample(self, info=info) for info in self.info['samples']] # The samples of a project are it's children in a way # self.children = self.samples # Call the mother function # return Aggregate.load(self)
def __init__(self, json_path, input_dir, output_dir): # Attributes # self.json_path = FilePath(json_path) self.input_dir = input_dir self.output_dir = output_dir # Name # self.name = self.json_path.prefix # Auto paths # self.base_dir = output_dir + 'experiment/' self.samples_dir = output_dir + 'samples/' self.p = AutoPaths(self.base_dir, self.all_paths) # Get sample json file # with open(json_path) as handle: self.info = json.load(handle) # Load all samples # self.samples = [] for name, desc in self.info.items(): if desc['type'] == 'humic': self.samples.append(Humic(name, desc, self)) if desc['type'] == 'fresh': self.samples.append(Fresh(name, desc, self)) self.samples.sort(key = lambda x: natural_sort(x.name)) self.children = self.samples # Samples # self.humic_samples = [s for s in self.samples if s.type == 'humic'] self.fresh_samples = [s for s in self.samples if s.type == 'fresh'] # Other # self.demultiplexer = Demultiplexer(self) #self.taxa_analysis = TaxonomyAnalysis(self) #self.meta_analysis = MetabolismAnalysis(self) # Runner # self.runner = ExperimentRunner(self)
def flat_directories(self): """The directories in this directory non-recursively, and sorted""" for root, dirs, files in os.walk(self.path): result = [DirectoryPath(os.path.join(root, d)) for d in dirs] break result.sort(key=lambda x: natural_sort(x.path)) return result
def flat_files(self): """The files in this directory non-recursively, and sorted. #TODO: check for permission denied in directory.""" result = [] for root, dirs, files in os.walk(self.path): result = [FilePath(os.path.join(root, f)) for f in files] break result.sort(key=lambda x: natural_sort(x.path)) return result
def __init__(self, samples): # Save samples # self.samples = [s for s in samples if s.sff_files_info] # Get all unique SFF files # self.sff_paths = set([f['path'] for s in self.samples for f in s.sff_files_info]) # Make objects of them # self.sff_files = [MultiplexedSFF(path) for path in self.sff_paths] self.sff_files.sort(key = lambda x: natural_sort(x.name)) # Two way linked graph # for sample in self.samples: sample.sff_links = OrderedDict() for sff in self.sff_files: sff.sample_links = OrderedDict() # Draw links # for sample in self.samples: for f in sample.sff_files_info: barcode, path = f['mid'], f['path'] sff_obj = [sff for sff in self.sff_files if sff.path==path][0] sample.sff_links[barcode] = sff_obj sff_obj.sample_links[barcode] = sample
def __init__(self, experiment): # Save parent # self.parent, self.experiment = experiment, experiment # Only for humic samples # self.samples = self.parent.humic_samples # Get all unique SFF files # self.sff_paths = set([f['path'] for s in self.samples for f in s.multiplexed_files]) # Make objects of them # self.sff_files = [Multiplexed(path) for path in self.sff_paths] self.sff_files.sort(key = lambda x: natural_sort(x.name)) # Two way linked graph # for sample in self.samples: sample.sff_links = {} for sff in self.sff_files: sff.sample_links = {} # Draw links # for sample in self.samples: for f in sample.multiplexed_files: barcode, path = f['mid'], f['path'] sff_obj = [sff for sff in self.sff_files if sff.path==path][0] sample.sff_links[barcode] = sff_obj sff_obj.sample_links[barcode] = sample