我有我希望解析的 fastq 文件。下面显示了每个文件中 1 个“读取”数千个的示例:
@PSI179204_0037:4:1:2139:945#0/2
AGAGATCCTACGGGAGGCAGCAGTGAGGAATATTGGTCAATGGGCGCGAGCCTGAACCAGCCAAGTAGCGTGAGGGACGACTGCCCTACGGGTTGTAAACCTCTTTTGTTCGGGAATAAAGTGCGGCACGCGTGCCGGTTTGTATGTCCCGTTCGAATAG
+PSI179204_0037:4:1:2139:945#0/2
ghhhhhhhhhhhfhdhhhfhhhhhgeeghhhdghfgheh[hhfhfhhhhehghffcahhhhfgcfgeaegd_ah_aaOa[a[aW___W^`a`b`da`ZXO]N^``BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB^C
我的目标是让它们出现在字典中,如下所示,每一行都被缩短了:
{' @PSI179204_0037:4': 'AGAGATCCTACG' '+PSI179204_0' 'ghhhhhhhhh' }
我在这里看到,您可以将一行声明为键,然后使用 next(filename) 命令将下一行用作值,因此尝试使用它,但有 3 个 next(filename) 条目,如下面的代码所示:
file1 = open(inputfile1, 'r')
file2 = open(inputfile2, 'r')
File1dict = {}
File2dict = {}
for key in file1:
File1dict[key.strip()] = next(file1) = next(file1) = next(file1)
print (File1dict)
for key in file2:
File2dict[key.strip()] = next(file2) = next(file2) = next(file2)
print (File2dict)
目前我收到以下错误:
File "Dict_maybesworking.py", line 31
File1dict[key.strip()] = next(file1) = next(file1) = next(file1)
SyntaxError: can't assign to function call
有谁知道如何使此代码工作,如果不是替代方案?
整个脚本如下:
from __future__ import print_function
from collections import defaultdict
from itertools import groupby
import argparse
from itertools import izip
parser = argparse.ArgumentParser() #simplifys the wording of using argparse as stated in the python tutorial
parser.add_argument("-r1", type=str, action='store', dest='input1', help="input the forward read file") # allows input of the forward read
parser.add_argument("-r2", type=str, action='store', dest='input2', help="input the reverse read file") # allows input of the reverse read
parser.add_argument("-v", "--verbose", action="store_true", help=" Increases the output, only needs to be used to provide feedback for debugging")
parser.add_argument("-u", type=str, action='store', dest='unique', help="Unique insturment number for fastq file required") # allows input of the reverse read
parser.add_argument("-n", action="count", default=0, help="Allows for up to 5 mismatches, Default is 0")
parser.add_argument("-o", "--output", help="Directs the output to a name of your choice")
args = parser.parse_args()
Uni = str(args.unique)
inputfile1 = str(args.input1)
inputfile2 = str(args.input2)
output = str(args.output)
output_file= open(output, "w")
Unmatched_1 = open('Unmatched_1', "a")
Unmatched_2 = open('Unmatched_2', "a")
file1 = open(inputfile1, 'r')
file2 = open(inputfile2, 'r')
File1dict = {}
File2dict = {}
for key in file1:
File2dict[key.strip()] = [file2.next(), file2.next(), file2.next()]
print (File1dict)
for key in file2:
File2dict[key.strip()] = [file2.next(), file2.next(), file2.next()]
print (File2dict)
命令行使用:
python Dict_maybesworking.py -r1 Real_test_1 -r2 Real_test_2 -u PSI179204 -o file_result