【问题标题】:Explanation of a code about lineIndex , to collect reads from a file [closed]关于 lineIndex 的代码说明,用于收集文件中的读取 [关闭]
【发布时间】:2023-01-04 14:32:56
【问题描述】:

这里的目的是从 FASTQ 文件中的一组字符串(读取)构建一个图形。但首先,我们实现以下获取读取的函数。我们从每行的末尾删除换行符(使用 str.strip()),并且为了约定,我们将读取中的所有字符转换为大写(使用 str.upper())。 代码:

def get_reads(filePath):
    reads = list() # The list of strings that will store the reads (the DNA strings) in the FASTQ file at filePath
    fastqFile = open(filePath, 'r') 
    fastqLines = fastqFile.readlines() 
    fastqFile.close()

    for lineIndex in range(1, len(fastqLines), 4): # I want this explained
        line = fastqLines[lineIndex]
        reads.append(line.strip().upper())
        
    return reads

我的问题是:请解释 lineIndex in range(1, len(fastqLines), 4) 这一行的用途是什么?

【问题讨论】:

    标签: python database string graph fastq


    【解决方案1】:

    fastqLines 是从文件中读取的每一行的 Python 列表。循环来自

    for lineIndex in range(1, len(fastqLines), 4):
    

    产生一个值 lineIndex 1, 5, 9 ... 到 List 的大小。然后使用此值将所选行存储在另一个列表 reads 中。因为 Python 列表是从 0 开始索引的,这意味着文件中的第 2、6、10 行存储在reads

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-26
      • 1970-01-01
      相关资源
      最近更新 更多