Beispiel #1
0
    def _open(self, path_or_file):
        """
        Open a file like object resp. a wrapper for a file like object.

        Arguments:
            path (str): path to the mzml file

        Returns:
            file_handler: instance of
            :py:class:`~pymzml.file_classes.standardGzip.StandardGzip`,
            :py:class:`~pymzml.file_classes.indexedGzip.IndexedGzip` or
            :py:class:`~pymzml.file_classes.standardMzml.StandardMzml`,
            based on the file ending of 'path'
        """
        if isinstance(path_or_file, BytesIO):
            return bytesMzml.BytesMzml(path_or_file, self.encoding,
                                       self.build_index_from_scratch)

        try:
            from django.core.files.uploadedfile import UploadedFile
            if isinstance(path_or_file, UploadedFile):
                return standardMzml.StandardMzml(path_or_file, self.encoding,
                                                 self.build_index_from_scratch)
        except ImportError:
            pass

        if path_or_file.endswith(".gz"):
            if self._indexed_gzip(path_or_file):
                return indexedGzip.IndexedGzip(path_or_file, self.encoding)
            else:
                return standardGzip.StandardGzip(path_or_file, self.encoding)
        return standardMzml.StandardMzml(path_or_file, self.encoding,
                                         self.build_index_from_scratch)
Beispiel #2
0
    def _open(self, path):
        """
        Open a file like object resp. a wrapper for a file like object.

        Arguments:
            path (str): path to the mzml file

        Returns:
            file_handler: instance of
            :py:class:`~pymzml.file_classes.standardGzip.StandardGzip`,
            :py:class:`~pymzml.file_classes.indexedGzip.IndexedGzip` or
            :py:class:`~pymzml.file_classes.standardMzml.StandardMzml`,
            based on the file ending of 'path'
        """
        if path.endswith('.gz'):
            if self._indexed_gzip(path):
                file_handler = indexedGzip.IndexedGzip(path, self.encoding)
            else:
                file_handler = standardGzip.StandardGzip(path, self.encoding)
        else:
            file_handler = standardMzml.StandardMzml(
                path,
                self.encoding,
                self.build_index_from_scratch,
            )
        return file_handler