File: guide.tex

package info (click to toggle)
seqan 1.4.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 34,156 kB
  • ctags: 30,130
  • sloc: cpp: 226,267; python: 7,737; xml: 189; sh: 153; awk: 129; makefile: 48
file content (269 lines) | stat: -rw-r--r-- 8,613 bytes parent folder | download | duplicates (4)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}              % Farben
\usepackage{xspace}                     % platzhalter


\usepackage{tabularx}
\usepackage{array} % für Tabellenerstellung
\usepackage{booktabs} % für Tabellenerstellu

\usepackage{listings}

\newenvironment{packed_enum}{
\begin{enumerate}
  \setlength{\itemsep}{1pt}
  \setlength{\parskip}{0pt}
  \setlength{\parsep}{0pt}
}{\end{enumerate}}

% Title Page
\title{Developer / User-Guide on new SeqAn IO}
\author{Hannes Hauswedell}

\usepackage{setspace} 
\parindent0pt
\parskip1.5ex
 \setstretch{1.1}


\newcommand{\todo}[1]{{\color{red}TODO:#1}\xspace}

\begin{document}

\section{General User and Developer Info}

\subsection{Some notes}

\begin{itemize}
\item \verb#https://trac.mi.fu-berlin.de/seqan/wiki/IoRevision# is partly 
outdated, do not rely on it!
\item Currently all new IO-Code lives in SeqAn \emph{beside} the old code, you 
do not need any \verb|#define|s to switch to the new code
\item Currently only FastA and FastQ are supported in the new code base
\item If you use only FastA and/or FastQ, you should definitely switch now, 
since the new code is faster and more reliable
\item switching is fairly easy, you only need to construct a \verb#RecordReader#
object for reading and work on that (see below and dddoc for more details)
\item the new calls are \verb#readRecord()#, \verb#read2()# (read entire document),
\verb#writeRecord()# and \verb#write2()# (write entire document).
\end{itemize}


\subsection{Some examples}
 \lstset
{
    language=C++,
    basicstyle=\color{black}\footnotesize\tt,
    backgroundcolor=\color{white},
%     numbers=left,
%     numberstyle=\tiny,
%     numbersep=5pt,
    captionpos=b,
     stringstyle=\ttfamily,
    frame=single,
    showspaces=false,
    breaklines=true,        % sets automatic line breaking
    breakatwhitespace=true
    % sets if automatic breaks should only happen at whitespace
}

Example code for reading a single record from a gzipped file (you will probably
want to loop over \verb#readRecord()#):
\begin{lstlisting}
char filename[] = "/path/to/file.fasta.gz";
gzFile file = gzopen(filename, "rb");
if (gzdirect(file)) 
{
	// error handling
}
Stream<GZFile> stream(file);

RecordReader<Stream<GZFile>, SinglePass<> > reader(stream);

CharString meta;
DnaString seq;

res = readRecord(meta, seq, reader, Fasta());
if (res != 0)
{
	// error handling
}

gzclose(file);
\end{lstlisting}


Example code for reading an entire file efficiently (using 
memory-mapped strings as files and ConcatDirect-Strings as storage):
\begin{lstlisting}
typedef String<char, MMap<> > TMMapString;
TMMapString stream;
char filename[] = "/path/to/file.fasta";

int res = open(stream, filename, OPEN_RDONLY));
if (res != 0)
{
	// error handling
}

RecordReader<TMMapString, DoublePass<Mapped> > reader(stream);

StringSet<CharString, Owner<ConcatDirect<> > > sequenceIds;
StringSet<DnaString, Owner<ConcatDirect<> > > sequences;

res = read2(sequenceIds, sequences, reader, Fasta());
if (res != 0)
{
	// error handling
}

close(stream);
\end{lstlisting}
% 
% // read one record
% CharString meta;
% DnaString seq;
% readRecord(meta, seq, reader);
% 
% // read the entire file into optimized StringSets
% 
% \end{lstlisting}


\section{Overview of new Stream Module}

There is a new Stream module, which currently resides in extras. The module 
is composed of these main components:
\begin{itemize}
\item Stream related (basic abstraction for IO)
\begin{itemize}
\item the stream concept [\verb#concept_stream.h#]
\item Stream adaptations [\verb#adapt_fstream.h#, \verb#adapt_cstdio.h# ..]
\item Stream class and specializations [\verb#stream_*.h#]
\end{itemize}
\item reading related
\begin{itemize}
\item core RecordReader classes (generic Buffer around Stream) [\verb#record_reader*.h#]
\item tokenizing code (low level readUntil* , readWhile* calls etc) 
[\verb#tokenizing.h# \verb#is.h#]
\item Format related reading based on tokenizing and RecordReader [\verb#read*.h#]
\item File format detection based on above code [\verb#guess_stream_format.h#]
\end{itemize}
\item Format related writing code [\verb#write*.h#]
\item code for casting from string to numerical types [\verb#lexical_cast.h#]
\end{itemize}



\section{Notes on completing the IO-Revision}

\subsection{General Information}

\begin{itemize}
\item different Stream backends are not yet implemented (e.g. char array, iostream)
\item \verb#tokenizing.h# contains copies of all old parsing/tokenizing functions, please
have a look there when switching to new IO (especially since in the old IO everyone
confused 'blank' and 'whitespace', as well as other terms!). Please also add any 
tokenizing functions to \verb#tokenizing.h# and not into your file format code. Do
also check if you can use the helper-functions in \verb#tokenizing.h# for your task!
\item once all code is ported read2() and write2() shall be renamed to read() and 
write()
\end{itemize}

Throughout SeqAn, IO-related code is marked with \verb#//IOREV# and zero or more
of the following tags:

\begin{tabular}{ll}\toprule
\textsc{Tag}	& \textsc{Description}		\\\midrule
\verb#_nottested_#     &This code may not work at all \\
\verb#_docnottested_#  &This code is documented but may behave different from doc\\
\verb#_nodoc_#         &This code should be documented but isn't\\
\verb#_duplicate_#     &This code reimplements functionality found elsewhere\\
\verb#_delcandidate_#  &This code should probably just be deleted\\
\verb#_notIO_#         &This code is falsely tagged as IO\\
\verb#_noop_#          &This call doesnt do anything\\
\verb#_stub_#          &This looks like its not done yet\\\bottomrule
\end{tabular}

I would recommend first following the advice in this document and \textbf{after}
having
implemented/ported the relevant code portions, to grep through seqan for IOREV
and deal with the leftover code on an individual basis. Since tagging happened
in the beginning of my work, some code comments might not by applicable anymore.


\subsection{Open Issues in existing files}

\begin{tabular}{ll}\toprule
\textsc{File}	& \textsc{TODOs}		\\\midrule
\verb#tokenizing.h#    &specialized comparison code for other alphabets beside Dna and Dna5\\
\verb#read_fasta_fastq.h#     &Questions what kind of format behaviour is legal \\
&(empty sequences? empty headers?) \\\bottomrule
\end{tabular}





\subsection{Sequence IO}

The following previously supported file formats are still missing: embl, genbank, QSeq, raw, CGViz (write-only)

Once they are implemented and all applications have changed to new IO, the following 
files will be obsolete:
\begin{packed_enum}
\item \verb#seqan/file/cstream.h#
\item \verb#seqan/file/stream.h#
\item \verb#seqan/file/file_base.h#
\item \verb#seqan/file/file_cstyle.h#
\item \verb#seqan/file/file_filereaderiterator.h#
\item \verb#seqan/file/file_filereader.h#
\item \verb#seqan/file/file_format.h#
\item \verb#seqan/file/stream_algorithms.h#
\item \verb#seqan/file/file_format_raw.h#
\item \verb#seqan/file/file_format_fasta.h#
\item \verb#seqan/file/file_format_embl.h#
\item \verb#seqan/file/file_format_genbank.h#
\item \verb#seqan/file/file_format_cgviz.h#
\item \verb#seqan/file/file_format_mmap.h#
\item \verb#seqan/sequence/sequence_stream.h#
\item \verb#seqan/misc/misc_parsing.h#
\end{packed_enum}

The following files shall not be removed, it needs to be decided where to put them in the future:

\begin{packed_enum}
\item \verb#seqan/file/chunk_collector.h#
\item \verb#seqan/file/file_page.h#
\item \verb#seqan/file/file_page_raid0.h#
\item \verb#seqan/file/string_external.h#
\item \verb#seqan/file/string_mmap.h#
\item \verb#seqan/file/file_array.h#
\item \verb#seqan/system/file_directory.h#
\item \verb#seqan/system/file_async.h#
\item \verb#seqan/system/file_sync.h#
\end{packed_enum}


\subsection{Store-IO}

It was decided that store-io should be ported and moved to the new stream module,
this covers \verb#seqan/store/store_io*#. Other than the beginning of a new 
sam-implementation (\verb#seqan/stream/read_sam.h#) none of this has yet 
happened.

\subsection{Alignment and Alignment Graph formats}

Includes TCoffeLib, BlastLib, MummerLib, NewickFormat (all in\\ 
\verb#seqan/graph/graph_align_tcoffee_io.h#) and fasta-alignment format 
(in\\ \verb#seqan/graph/graph_align_tcoffee_io.h# AND in 
\verb#seqan/file/file_format_fasta_align.h#).

These should probably be ported as well, but it was not yet decided whether 
they should be moved to the stream-module or continue to reside in the 
graph-module.



\end{document}