當前位置: 首頁>>代碼示例>>Python>>正文


Python GenericTsvReader.getInputContentFP方法代碼示例

本文整理匯總了Python中oncotator.utils.GenericTsvReader.GenericTsvReader.getInputContentFP方法的典型用法代碼示例。如果您正苦於以下問題:Python GenericTsvReader.getInputContentFP方法的具體用法?Python GenericTsvReader.getInputContentFP怎麽用?Python GenericTsvReader.getInputContentFP使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oncotator.utils.GenericTsvReader.GenericTsvReader的用法示例。


在下文中一共展示了GenericTsvReader.getInputContentFP方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sortFile

# 需要導入模塊: from oncotator.utils.GenericTsvReader import GenericTsvReader [as 別名]
# 或者: from oncotator.utils.GenericTsvReader.GenericTsvReader import getInputContentFP [as 別名]
    def sortFile(self, filename, func, length=50000):
        """
        This method sorts the input file and writes out the sorted file to filename.

        :param filename: sorted filename
        :param func: function that converts each row of the input file to an unique, sortable key
        :param length: maximum number of lines in a partition
        """
        reader = GenericTsvReader(filename=self.readfilename, commentPrepend=self.commentPrepend,
                                  delimiter=self.delimiter)
        comments = reader.getComments()

        fieldnames = reader.getFieldNames()
        if fieldnames is None:
            fieldnames = []

        fieldnameIndexes = collections.OrderedDict()
        if fieldnames is not None:
            fieldnameIndexes = collections.OrderedDict([(x, i) for (i, x) in enumerate(fieldnames)])

        iterable = iter(reader.getInputContentFP())
        partitions = self._yieldPartitions(iterable, func, fieldnameIndexes, length)

        with open(name=filename, mode='wb', buffering=64 * 1024) as writer:
            writer.write(comments)
            writer.write(string.join(fieldnames, self.delimiter) + "\n")
            writer.writelines(self._merge(partitions))  # generators are allowed as inputs to writelines function
開發者ID:Tmacme,項目名稱:oncotator,代碼行數:29,代碼來源:TsvFileSorter.py


注:本文中的oncotator.utils.GenericTsvReader.GenericTsvReader.getInputContentFP方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。