def openFile(self, dataFile): # We need to check to see if the path exists here as pysam does # not throw an error if the index is missing. if not os.path.exists(self._indexFile): raise exceptions.FileOpenFailedException(self._indexFile) try: return pysam.AlignmentFile(self._dataUrl, filepath_index=self._indexFile) except IOError as exception: # IOError thrown when the index file passed in is not actually # an index file... may also happen in other cases? raise exceptions.DataException(exception.message)
def _readFile(self): if not os.path.exists(self._dataUrl): raise exceptions.FileOpenFailedException(self._dataUrl) reader = OboReader(obo_file=self._dataUrl) ids = set() for record in reader: if record.id in ids: raise exceptions.OntologyFileFormatException( self._dataUrl, "Duplicate ID {}".format(record.id)) ids.add(record.id) self._nameIdMap[record.name].append(record.id) self._sourceVersion = reader.format_version if len(ids) == 0: raise exceptions.OntologyFileFormatException( self._dataUrl, "No valid records found.") # To get prefix, pull out an ID and parse it. self._ontologyPrefix = record.id.split(":")[0] self._sourceVersion = reader.data_version
def getFileHandle(self, dataFile, openMethod): """ Returns handle associated to the filename. If the file is already opened, update its priority in the cache and return its handle. Otherwise, open the file using openMethod, store it in the cache and return the corresponding handle. """ if dataFile in self._memoTable: handle = self._memoTable[dataFile] self._update(dataFile, handle) return handle else: try: handle = openMethod(dataFile) except ValueError: raise exceptions.FileOpenFailedException(dataFile) self._memoTable[dataFile] = handle self._add(dataFile, handle) if len(self._memoTable) > self._maxCacheSize: dataFile = self._removeLru() del self._memoTable[dataFile] return handle