-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfastqseqsource.cpp
116 lines (102 loc) · 2.33 KB
/
fastqseqsource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "myutils.h"
#include "fastqseqsource.h"
#include "seqinfo.h"
#include "alpha.h"
#include "omplock.h"
#define TRACE 0
bool FASTQSeqSource::GetNextLo(SeqInfo *SI)
{
// Label
bool Ok = ReadLine();
if (!Ok)
return false;
unsigned n = m_LineBuff.Size;
const char *Line = m_LineBuff.Data;
bool TruncLabels = opt(trunclabels);
#if TRACE
{
Log("m_LineBuff.Size=%u Line=\"", n);
for (unsigned i = 0; i < n; ++i)
Log("%c", Line[i]);
Log("\"\n");
}
#endif
// Allow empty lines at EOF
if (n == 0)
{
for (;;)
{
unsigned LineNr = m_LR.m_LineNr;
bool Ok = ReadLine();
if (!Ok)
return false;
if (m_LineBuff.Size != 0)
Die("Empty line nr %u in FASTQ file '%s'", LineNr, GetFileNameC());
}
}
if (Line[0] != '@')
{
Log("\n");
Log("Line %u: %s\n", m_LR.m_LineNr, Line);
Die("Bad line %u in FASTQ file '%s': expected '@'", m_LR.m_LineNr, GetFileNameC());
}
unsigned SeqIndex = m_SeqCount;
SI->Init(SeqIndex);
SI->AllocLabel(n);
for (unsigned i = 1; i < n; ++i)
{
char c = Line[i];
if (isspace(c) && TruncLabels)
{
SI->m_LabelBuffer[i-1] = 0;
break;
}
SI->m_LabelBuffer[i-1] = c;
}
SI->m_LabelBuffer[n-1] = 0;
// Seq
Ok = ReadLine();
if (!Ok)
Die("Unexpected end-of-file in FASTQ file %s", GetFileNameC());
Line = m_LineBuff.Data;
unsigned L = m_LineBuff.Size;
SI->AllocSeq(L);
SI->m_L = L;
byte *Seq = SI->m_SeqBuffer;
for (unsigned i = 0; i < L; ++i)
{
byte c = (byte) Line[i];
if (!isalpha(c))
{
if (isprint(c))
Die("Invalid sequence letter '%c' in FASTQ, line %u file %s",
c, m_LR.m_LineNr, GetFileNameC());
else
Die("Non-printing byte 0x%02x in FASTQ sequence line %u file %s label %s",
c, m_LR.m_LineNr, GetFileNameC(), SI->m_Label);
}
Seq[i] = c;
}
// +[Label]
// Ignore contents & possible eof
ReadLine();
// Qual
Ok = ReadLine();
if (!Ok)
Die("Unexpected end-of-file in FASTQ file %s", GetFileNameC());
Line = m_LineBuff.Data;
if (Line == 0)
Die("Unexpected end-of-file in FASTQ file %s", GetFileNameC());
unsigned LQ = m_LineBuff.Size;
if (LQ != L)
Die("Bad FASTQ record: %u bases, %u quals line %u file %s label %s",
L, LQ, m_LR.m_LineNr, GetFileNameC(), SI->m_Label);
SI->AllocQual(L);
char *Qual = SI->m_QualBuffer;
for (unsigned i = 0; i < L; ++i)
{
char c = (byte) Line[i];
Qual[i] = c;
}
return true;
}