fastq格式如下:
@HWI-ST1276:71:C1162ACXX:1:1101:1208:2458 1:N:0:CGATGT
NAAGAACACGTTCGGTCACCTCAGCACACTTGTGAATGTCATGGGATCCAT
'+'
@#55???BBBBB?BA@DEEFFCFFHHFFCFFHHHHHHHFAE0ECFFD/AEH
第一行是序列标识(read ID)以及相关的描述信息,以“@” 开头;
第二行即为碱基序列,长度由测序策略决定;如SE50
第三行以“+”开头,后面是序列标示符、描述信息,或者什么也不加;
第四行是测序质量值(phred),与第二行一一对应,phred值以ASCII码标记,对应的 ASCII 值减去33,即为第二行对应碱基的测序质量值。
Illumina测序标识详细信息如下:
HWI-ST1276
Instrument – unique identifier of the sequencer
测序仪识别号
71
run number – Run number on instrument
机器运行编号
C1162ACXX
FlowCell ID – ID of flowcell
flowcell编号
1
LaneNumber – positive integer
Lane编号;1个flowcell有8条lane
1101
TileNumber – positive integer
Tile编号;1条lane有两列,每列有32个tile
1208
X – x coordinate of the spot. Integer which can be negative
点的x坐标
2458
Y – y coordinate of the spot. Integer which can be negative
点的y坐标
1
ReadNumber - 1 for single reads; 1 or 2 for paired ends
单端或双端
N
whether it is filtered - NB:Y if the read is filtered out, not in the delivered fastq file, N otherwise
是否过滤,Y表示被过滤,否则为N
0
control number - 0 when none of the control bits are on, otherwise it is an even number
0表示十进制?否则是一个偶数
CGATGT
Illumina index sequences
一个flowcell中不同样品,需要index区分
一个样品的双末端测序结果中,同一条insert sequence 的两条reads的ID只有ReadNumber是不一样的,要么为1,要么为2;所有reads只有X – x coordinate of the spot是不断变化的。
fasta格式如下:
>XM_011525358.1 PREDICTED: Homo sapiens forkhead box N1 (FOXN1), transcript variant X2, mRNA
AGCTTCTTAGTCACCTTTCTCTTCTCCCCGTTTTGGCGCAGCCCCTCCGGGCAAGGGGAAGCTGATATCATAATTATTGGCTCACCTGGCAGCTGCCTCCCCTCACCTGATGTCAGCACAGACACAGGACGGCCGAGCTG
第一行是一个大于号
开头,后面紧接注释信息,比如序列的名字,编号等。
第二行开始就是纯序列部分。
代码如下:
import time
start = time.time()
import glob
import gzip
for i in glob.glob('*.fastq.gz'):
with gzip.open(i,'rt') as fp:
output_fasta = open("%s.fa"%i[:-9],'w')
i = 0
for line in fp:
i += 1
if i % 4 == 1:
line_new = line[1:]
output_fasta.write('>'+line_new)
elif i % 4 == 2:
output_fasta.write(line)
output_fasta.close()
end = time.time()
print("used %s s" % str(end - start))