def __init__(self, prefixDict=None, separator='.', filename=None, dbClass=BlastDB, trypath=None): '''can either be created using prefixDict, or a header file for a previously created PrefixUnionDict''' if filename is not None: # READ UNION HEADER FILE if trypath is None: # DEFAULT: LOOK IN SAME DIRECTORY AS UNION HEADER trypath = [os.path.dirname(filename)] ifile = file(filename) it = iter(ifile) separator = it.next().strip('\r\n') # DROP TRAILING CR prefixDict = {} for line in it: prefix, filepath = line.strip().split('\t')[:2] try: prefixDict[prefix] = \ dbClass(classutil.search_dirs_for_file(filepath, trypath)) except IOError: raise IOError( '''unable to open database %s: check path or privileges. Set trypath to give a list of directories to search.''' % filepath) ifile.close() self.separator = separator if prefixDict is not None: self.prefixDict = prefixDict else: self.prefixDict = {} d = {} for k, v in self.prefixDict.items(): d[v] = k # CREATE A REVERSE MAPPING self.dicts = d self.seqInfoDict = PUDSeqInfoDict(self) # standard interface
def __init__(self,prefixDict=None,separator='.',filename=None, dbClass=BlastDB,trypath=None): '''can either be created using prefixDict, or a header file for a previously created PrefixUnionDict''' if filename is not None: # READ UNION HEADER FILE if trypath is None: # DEFAULT: LOOK IN SAME DIRECTORY AS UNION HEADER trypath=[os.path.dirname(filename)] ifile=file(filename) it=iter(ifile) separator=it.next().strip('\r\n') # DROP TRAILING CR prefixDict={} for line in it: prefix,filepath=line.strip().split('\t')[:2] try: prefixDict[prefix] = \ dbClass(classutil.search_dirs_for_file(filepath, trypath)) except IOError: raise IOError('''unable to open database %s: check path or privileges. Set trypath to give a list of directories to search.''' % filepath) ifile.close() self.separator=separator if prefixDict is not None: self.prefixDict=prefixDict else: self.prefixDict={} d={} for k,v in self.prefixDict.items(): d[v]=k # CREATE A REVERSE MAPPING self.dicts=d self.seqInfoDict = PUDSeqInfoDict(self) # standard interface
def __init__(self, prefixDict=None, separator='.', filename=None, dbClass=SequenceFileDB, trypath=None): # read union header file if filename is not None: if prefixDict: raise TypeError(''' cannot create with prefixDict and filename both!''') if trypath is None: trypath = [os.path.dirname(filename)] ifile = file(filename, 'rU') try: it = iter(ifile) # Remove leading/trailing CR+LF. separator = it.next().strip('\r\n') prefixDict = {} for line in it: prefix, filepath = line.strip().split('\t')[:2] try: dbfile = classutil.search_dirs_for_file( filepath, trypath) db = dbClass(dbfile) except IOError: for db in prefixDict.values(): db.close() # close databases before exiting raise IOError('''\ unable to open database %s: check path or privileges. Set 'trypath' to give a list of directories to search.''' % filepath) else: prefixDict[prefix] = db finally: ifile.close() self.separator = separator if prefixDict is not None: self.prefixDict = prefixDict else: self.prefixDict = {} # also create a reverse mapping d = {} for k, v in self.prefixDict.items(): d[v] = k self.dicts = d self.seqInfoDict = _PUDSeqInfoDict(self) # supply standard interface
def __init__(self, prefixDict=None, separator=".", filename=None, dbClass=SequenceFileDB, trypath=None): # read union header file if filename is not None: if prefixDict: raise TypeError( """ cannot create with prefixDict and filename both!""" ) if trypath is None: trypath = [os.path.dirname(filename)] ifile = file(filename, "rU") try: it = iter(ifile) separator = it.next().strip("\r\n") # remove leading/trailing CR prefixDict = {} for line in it: prefix, filepath = line.strip().split("\t")[:2] try: dbfile = classutil.search_dirs_for_file(filepath, trypath) db = dbClass(dbfile) except IOError: for db in prefixDict.values(): db.close() # close databases before exiting raise IOError( """\ unable to open database %s: check path or privileges. Set 'trypath' to give a list of directories to search.""" % filepath ) else: prefixDict[prefix] = db finally: ifile.close() self.separator = separator if prefixDict is not None: self.prefixDict = prefixDict else: self.prefixDict = {} # also create a reverse mapping d = {} for k, v in self.prefixDict.items(): d[v] = k self.dicts = d self.seqInfoDict = _PUDSeqInfoDict(self) # supply standard interface