class CoreCreator: """Top level class for making bins""" def __init__(self, dbFileName): self._pm = ProfileManager(dbFileName) self._dbFileName = dbFileName def loadProfile(self, timer, minLength): return self._pm.loadData(timer, minLength=minLength, loadMarkers=True, loadBins=False) def run(self, timer, minLength, minSize, minPts, savedDistsPrefix="", keepDists=False, force=False): # check that the user is OK with nuking stuff... if not force and not self._pm.promptOnOverwrite(): return profile = self.loadProfile(timer, minLength=minLength ) if savedDistsPrefix=="": savedDistsPrefix = self._dbFileName+".dists" cacher = FileCacher(savedDistsPrefix) ce = ClassificationClusterEngine(profile, minPts=minPts, minSize=minSize, cacher=cacher, ) ce.makeBins(timer, out_bins=profile.binIds, out_reach_order=profile.reachOrder, out_reach_dists=profile.reachDists ) # Now save all the stuff to disk! print "Saving bins" self._pm.setReachabilityOrder(profile) self._pm.setBinAssignments(profile, nuke=True) print " %s" % timer.getTimeStamp() # Remove created files if not keepDists: try: cacher.cleanup() except: raise
class CoreCreator: """Top level class for making bins""" def __init__(self, dbFileName): self._pm = ProfileManager(dbFileName) self._dbFileName = dbFileName def loadProfile(self, timer, minLength): return self._pm.loadData(timer, minLength=minLength, loadMarkers=True, loadBins=False) def run(self, timer, minLength, minSize, minPts, savedDistsPrefix="", keepDists=False, force=False): # check that the user is OK with nuking stuff... if not force and not self._pm.promptOnOverwrite(): return profile = self.loadProfile(timer, minLength=minLength) if savedDistsPrefix == "": savedDistsPrefix = self._dbFileName + ".dists" cacher = FileCacher(savedDistsPrefix) ce = ClassificationClusterEngine( profile, minPts=minPts, minSize=minSize, cacher=cacher, ) ce.makeBins(timer, out_bins=profile.binIds, out_reach_order=profile.reachOrder, out_reach_dists=profile.reachDists) # Now save all the stuff to disk! print "Saving bins" self._pm.setReachabilityOrder(profile) self._pm.setBinAssignments(profile, nuke=True) print " %s" % timer.getTimeStamp() # Remove created files if not keepDists: try: cacher.cleanup() except: raise
class BinImporter: """Used for importing bin assignments""" def __init__(self, dbFileName): self._pm = ProfileManager(dbFileName) def loadProfile(self, timer): return self._pm.loadData(timer) def importBinAssignments(self, timer, infile, separator): """Parse assignment file for bin contigs""" profile = self.loadProfile(timer) br = BinReader() # looks like cid->bid contig_bins = {} try: with open(infile, "r") as f: try: (con_names, con_bins) = br.parse(f, separator) (_, con_bid) = np.unique(con_bins, return_inverse=True) con_bid += 1 # bid zero is unbinned contig_bins = dict(zip(con_names, con_bid)) except: print "Error parsing bin assignments" raise except: print "Could not parse bin assignment file:",infile,sys.exc_info()[0] raise # now get the internal indices for contigs for (i, cid) in enumerate(profile.contigNames): try: profile.binIds[i] = contig_bins[cid] except KeyError: pass # Now save all the stuff to disk! print "Saving bins" self._pm.setBinAssignments(profile, nuke=True) print " %s" % timer.getTimeStamp()
class BinImporter: """Used for importing bin assignments""" def __init__(self, dbFileName): self._pm = ProfileManager(dbFileName) def loadProfile(self, timer): return self._pm.loadData(timer) def importBinAssignments(self, timer, infile, separator): """Parse assignment file for bin contigs""" profile = self.loadProfile(timer) br = BinReader() # looks like cid->bid contig_bins = {} try: with open(infile, "r") as f: try: (con_names, con_bins) = br.parse(f, separator) (_, con_bid) = np.unique(con_bins, return_inverse=True) con_bid += 1 # bid zero is unbinned contig_bins = dict(zip(con_names, con_bid)) except: print "Error parsing bin assignments" raise except: print "Could not parse bin assignment file:", infile, sys.exc_info( )[0] raise # now get the internal indices for contigs for (i, cid) in enumerate(profile.contigNames): try: profile.binIds[i] = contig_bins[cid] except KeyError: pass # Now save all the stuff to disk! print "Saving bins" self._pm.setBinAssignments(profile, nuke=True) print " %s" % timer.getTimeStamp()