def __init__(self, name='experimental', view_dir=''): self.name = name self.view_dir = view_dir self.length = [] self.gc = [] self.names = [] self.tax = {} self.covs = {} self.meta = {} BtIO.create_dir(self.view_dir)
def __init__(self, name='experimental', view_dir='', blobDb={}): self.name = name self.view_dir = re.sub(".blobDB", "", view_dir) self.length = [] self.gc = [] self.n_count = [] self.names = [] self.tax = {} self.covs = {} self.read_covs = defaultdict(list) self.tax_scores = {} self.blobDb = blobDb self.meta = {} BtIO.create_dir(self.view_dir)
def _write_output(self): primary = [ 'meta', 'blob_id', 'length', 'gc', 'n_count', 'agct_count', 'tax_id' ] secondary = ['cov_base', 'cov_read', 'tax', 'tax_hit'] directory = BtIO.create_dir(self.path) out_fs = [] if (directory): out_fs = [] strings = [] for key in self.files: if key in primary: out_f.append(self.files[key]) data.append(getattr(self, key)) elif key in secondary: for key2 in self.files[key]: out_f.append(self.files[key][key2]) data.append(getattr(self, key)[key2]) else: pass with tarfile.open(out_f, "a:gz") as tar: for out_f, string in zip(out_fs, strings): with open(out_f, 'w') as fh: json.dump(string, fh, indent=1, separators=(',', ' : ')) tar.add(out_f)
def output(self): # meta meta = self.get_meta() meta_f = join(self.view_dir, "meta.json") BtIO.writeJson(meta, meta_f, indent=2) # gc gc_f = join(self.view_dir, "gc.json") print BtLog.status_d['13'] % (gc_f) BtIO.writeJson(self.gc, gc_f, indent=1) # length length_f = join(self.view_dir, "length.json") print BtLog.status_d['13'] % (length_f) BtIO.writeJson(self.length, length_f, indent=1) # names names_f = join(self.view_dir, "names.json") print BtLog.status_d['13'] % (names_f) BtIO.writeJson(self.names, names_f, indent=1) # cov cov_d = join(self.view_dir, "covs") BtIO.create_dir(directory=cov_d) for cov_lib, cov in self.covs.items(): cov_f = join(cov_d, "%s.json" % cov_lib) print BtLog.status_d['13'] % (cov_f) BtIO.writeJson(cov, cov_f, indent=1) # tax taxrule_d = join(self.view_dir, "taxrule") BtIO.create_dir(directory=taxrule_d) for taxrule in self.tax: tax_d = join(taxrule_d, taxrule) BtIO.create_dir(directory=tax_d) for rank in self.tax[taxrule]: tax = self.tax[taxrule][rank] rank_f = join(tax_d, "%s.json" % rank) BtIO.writeJson(tax, rank_f, indent=1)