This file is indexed.

/usr/include/seqan/misc/svg.h is in libseqan2-dev 2.3.2+dfsg2-4ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
// ==========================================================================
//                 SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2016, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of Knut Reinert or the FU Berlin nor the names of
//       its contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================

#ifndef SEQAN_HEADER_MISC_SVG_H
#define SEQAN_HEADER_MISC_SVG_H

namespace seqan
{

//////////////////////////////////////////////////////////////////////////////
// SVG File Context
//////////////////////////////////////////////////////////////////////////////

struct SVGFile
{
//IOREV _nodoc_ no documentation whatsoever; uses custom IO, fully independent (maybe postpone adaption)
    std::fstream file;

    Pair<int> cursor;
    Pair<int> size;
    String<CharString> style;

    int dpSequence;
    int dpMatrix;
    int dpTrace;

    int text;

    int readForward;
    int readReverse;
    int readText;
    int rulerTextTicks;
    int rulerTextLabel;

    friend inline void svgWriteHeader(SVGFile &svg);
    friend inline void svgWriteFooter(SVGFile &svg);

    friend inline bool open(SVGFile &svg, char const * fileName);
    friend inline bool close(SVGFile &svg);

    SVGFile():
        cursor(0,0),
        size(0,0)
    {
        resetStyles();
    }

    SVGFile(char const *fileName):
        cursor(0,0),
        size(0,0)
    {
        resetStyles();
        open(*this, fileName);
    }

    ~SVGFile()
    {
        close(*this);
    }

private:

    inline void resetStyles()
    {
        clear(style);
        readText = dpSequence = length(style);
        appendValue(style, "style=\"text-anchor:middle; font-family:Bitstream Vera Sans,Verdana,sans-serif;\" font-size=\"18px\"");
        text = length(style);
        appendValue(style, "style=\"text-anchor:middle; font-family:Courier New,Verdana,sans-serif; font-weight:bold;\" font-size=\"20px\"");
        rulerTextTicks = length(style);
        appendValue(style, "style=\"text-anchor:middle; font-family:Verdana,sans-serif;\" font-size=\"6px\"");
        rulerTextLabel = length(style);
        appendValue(style, "style=\"text-anchor:left; font-family:Verdana,sans-serif; font-weight:bold;\" font-size=\"8px\"");

        dpMatrix = length(style);
        appendValue(style, "style=\"stroke:lightgray;stroke-width:1;\" marker-end=\"url(#startMarkerNormal)\"");
        dpTrace = length(style);
        appendValue(style, "style=\"stroke:black;stroke-width:2;\" marker-end=\"url(#startMarkerBold)\"");

        readForward = length(style);
        appendValue(style, "style=\"stroke:darkblue;stroke-width:3;\"");
        appendValue(style, "style=\"stroke:lightblue;stroke-width:1;\"");
        appendValue(style, "style=\"stroke:darkblue;stroke-width:3;\" marker-end=\"url(#startMarkerForward)\"");
        appendValue(style, "style=\"stroke:lightblue;stroke-width:1;\" marker-end=\"url(#startMarkerForward)\"");
        readReverse = length(style);
        appendValue(style, "style=\"stroke:darkred;stroke-width:3;\"");
        appendValue(style, "style=\"stroke:salmon;stroke-width:1;\"");
        appendValue(style, "style=\"stroke:darkred;stroke-width:3;\" marker-end=\"url(#startMarkerReverse)\"");
        appendValue(style, "style=\"stroke:salmon;stroke-width:1;\" marker-end=\"url(#startMarkerReverse)\"");
    }
};

template <>
struct DirectionIterator<SVGFile, Output>
{
    typedef SVGFile* Type;
};

inline void svgResize(SVGFile &svg, int width, int height)
{
    svg.size.i1 = width;
    svg.size.i2 = height;
}

inline void svgWriteHeader(SVGFile &svg)
{
    svg.file << "<?xml version=\"1.0\"?>" << std::endl;
    svg.file << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"" << std::endl;
    svg.file << "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" << std::endl;
    svg.file << std::endl;
    svg.file << "<svg version=\"1.1\"" << std::endl;
    svg.file << "    xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
    svg.file << "    xmlns:xlink=\"http://www.w3.org/1999/xlink\"" << std::endl;
    if (svg.size.i1 != 0)
    {
        svg.file << "    width=\"" << svg.size.i1 * 20 << "px\" height=\"" << svg.size.i2 * 20 << "px\"" << std::endl;
    }
    svg.file << ">" << std::endl;
    svg.file << "<defs>" << std::endl;

    // trace back arrow markers
    svg.file << "    <g id=\"arrowMarker\" stroke-linecap=\"round\">" << std::endl;
    svg.file << "        <line x1=\"-6\" y1=\"1.5\" x2=\"0\" y2=\"0\" />" << std::endl;
    svg.file << "        <line x1=\"-6\" y1=\"-1.5\" x2=\"0\" y2=\"0\" />" << std::endl;
    svg.file << "    </g>" << std::endl;
    svg.file << "    <marker id=\"startMarkerNormal\" markerWidth=\"6\" markerHeight=\"3\" style=\"overflow:visible\" orient=\"auto\" markerUnits=\"userSpaceOnUse\">" << std::endl;
    svg.file << "        <use xlink:href=\"#arrowMarker\" stroke=\"lightgray\" />" << std::endl;
    svg.file << "    </marker>" << std::endl;
    svg.file << "    <marker id=\"startMarkerBold\" markerWidth=\"6\" markerHeight=\"4\" style=\"overflow:visible\" orient=\"auto\" markerUnits=\"userSpaceOnUse\">" << std::endl;
    svg.file << "        <use xlink:href=\"#arrowMarker\" stroke-width=\"2\" stroke=\"black\" />" << std::endl;
    svg.file << "    </marker>" << std::endl;

    // read mapping arrow markers
    svg.file << "    <marker id=\"startMarkerForward\" markerWidth=\"10\" markerHeight=\"4\" style=\"overflow:visible\" orient=\"auto\" markerUnits=\"userSpaceOnUse\">" << std::endl;
    svg.file << "        <polyline points=\"-8,0 -9,-6 3,0 -9,6 -8,0\" fill=\"darkblue\" />" << std::endl;
    svg.file << "    </marker>" << std::endl;
    svg.file << "    <marker id=\"startMarkerReverse\" markerWidth=\"10\" markerHeight=\"4\" style=\"overflow:visible\" orient=\"auto\" markerUnits=\"userSpaceOnUse\">" << std::endl;
    svg.file << "        <polyline points=\"-8,0 -9,-6 3,0 -9,6 -8,0\" fill=\"darkred\" />" << std::endl;
    svg.file << "    </marker>" << std::endl;

    svg.file << " </defs>" << std::endl;
    svg.file << std::endl;
}

inline void svgWriteFooter(SVGFile &svg)
{
    svg.file << std::endl;
    svg.file << "</svg>" << std::endl;
}


inline bool open(SVGFile &svg, char const * fileName)
{
    svg.file.open(fileName, std::ios_base::out);
    if (!svg.file.is_open()) return false;
    svgWriteHeader(svg);
    return true;
}

inline bool close(SVGFile &svg)
{
    if (svg.file.is_open())
    {
        svgWriteFooter(svg);
        svg.file.close();
    }
    return true;
}

SVGFile *
directionIterator(SVGFile & svg, Output)
{
    return &svg;
}


template <typename TCharacter>
inline void
writeValue(SVGFile *svg, TCharacter character)
{
    char x = static_cast<char>(character);
    if (x == '\n')
    {
        ++svg->cursor.i2;
        svg->cursor.i1 = 0;
    }
    else if (x == '\t')
    {
        svg->cursor.i1 = (svg->cursor.i1 & ~7) + 8;
    }
    else
    {
        if (x != ' ')
        {
            svg->file << "<g transform=\"translate(" << svg->cursor.i1*20+10 << ',' << svg->cursor.i2*20+10
                      << ")\"><text y=\"0.3em\" " << svg->style[svg->text] << '>';
            svg->file << x;
            svg->file << "</text></g>" << std::endl;
        }
        ++svg->cursor.i1;
    }
}

template <typename TContigGaps, typename TContigName>
inline void _printContig(
    SVGFile &svg,
    AlignedReadLayout &,
    TContigGaps &contigGaps,
    TContigName const &contigName)
{
    typedef typename Iterator<TContigGaps, Standard>::Type TContigIterator;

    TContigIterator cit = begin(contigGaps, Standard());
    TContigIterator citEnd = end(contigGaps, Standard());
    for (int64_t ofs = 0; cit != citEnd; ++cit, ++ofs)
    {
        if (!isGap(cit))
        {
            if (ofs == 0)
            {
                svg.file << "<g transform=\"translate(" << ofs*20+2 << ',' << svg.cursor.i2*20+10 << ")\"><text y=\"0.3em\" " << svg.style[svg.rulerTextLabel] << '>';
                svg.file << contigName << "</text></g>" << std::endl;
            }

            int64_t seqPos = cit.current.seqPos + 1;
            if (seqPos % 5 == 0)
            {
                if (seqPos % 10 == 0)
                {
                    if (ofs >= 5)
                    {
                        svg.file << "<g transform=\"translate(" << ofs*20+10 << ',' << svg.cursor.i2*20+10 << ")\"><text y=\"0.3em\" " << svg.style[svg.rulerTextTicks] << '>';
                        svg.file << seqPos << "</text></g>" << std::endl;
                    }

                    svg.file << "<line x1=\"" << ofs*20+10 << "\" x2=\"" << ofs*20+10 << "\" ";
                    svg.file << "y1=\"" << svg.cursor.i2*20+12 << "\" y2=\"" << svg.cursor.i2*20+15 << "\" ";
                } else {
                    svg.file << "<line x1=\"" << ofs*20+10 << "\" x2=\"" << ofs*20+10 << "\" ";
                    svg.file << "y1=\"" << svg.cursor.i2*20+12 << "\" y2=\"" << svg.cursor.i2*20+15 << "\" ";
                }
                svg.file << "stroke-width=\"1\" stroke=\"gray\" />" << std::endl;
            }
        }
    }
    writeValue(&svg, '\n');

    int savedStyle = svg.text;
    svg.text = svg.readText;
    svg << contigGaps;
    svg.text = savedStyle;
}

template <typename TContigGaps, typename TReadGaps, typename TAlignedRead, typename TLine>
inline void _printRead(
    SVGFile &svg,
    AlignedReadLayout &layout,
    TContigGaps &contigGaps,
    TReadGaps &readGaps,
    TAlignedRead &alignedRead,
    TLine line)
{
    typedef typename Iterator<TContigGaps, Standard>::Type TContigIterator;
    typedef typename Iterator<TReadGaps, Standard>::Type TIterator;

    int64_t xEnd = svg.cursor.i1 * 20;
    int64_t x = 0;

    int style, arrow = 0;
    const char *first;
    const char *second;
    int64_t ofs;

    if (alignedRead.beginPos < alignedRead.endPos)
    {
        ofs = alignedRead.beginPos - svg.cursor.i1 + beginPosition(readGaps);
        first = "<line x1=\"";
        second = "\" x2=\"";
        style = svg.readForward;
    } else {
        ofs = alignedRead.endPos - svg.cursor.i1 + beginPosition(readGaps);
        first = "<line x2=\"";
        second = "\" x1=\"";
        style = svg.readReverse;
    }

    if (beginPosition(readGaps) == 0)
    {
        if (alignedRead.beginPos < alignedRead.endPos)
            x = xEnd + 5;
        else {
            x = xEnd + 10;
            arrow = 2;
        }
    }
    line = svg.cursor.i2 * 20 + 10;

    if (length(layout.mateCoords) <= alignedRead.pairMatchId)
        resize(layout.mateCoords, alignedRead.pairMatchId + 1, Pair<int>(-1,-1));
    else
    {
        if (layout.mateCoords[alignedRead.pairMatchId].i2 != -1)
        {
            Pair<int64_t> a((alignedRead.beginPos - ofs) * 20, line);
            Pair<int64_t> b(layout.mateCoords[alignedRead.pairMatchId]);
            if (a.i1 < b.i1)
            {
                Pair<int64_t> tmp = a;
                a = b;
                b = tmp;
            }
            int64_t dx = (b.i1 - a.i1);
            int64_t dy = (b.i2 - a.i2);

            svg.file << "<path d=\"M " << a.i1 << ',' << a.i2;
            svg.file << " C " << a.i1+dy/10 << ',' << a.i2-dx/10;
            svg.file << ' ' << b.i1+dy/10 << ',' << b.i2-dx/10;
            svg.file << ' ' << b.i1 << ',' << b.i2;
            svg.file << "\" stroke-width=\"2\" stroke=\"black\" stroke-opacity=\"0.2\" fill=\"none\"/>";
        }
        else
            layout.mateCoords[alignedRead.pairMatchId] = Pair<int>((alignedRead.beginPos - ofs) * 20, line);
    }


    TContigIterator cit = begin(contigGaps, Standard()) + (_min(alignedRead.beginPos, alignedRead.endPos) + beginPosition(readGaps));
    TIterator it = begin(readGaps, Standard());
    TIterator itEnd = end(readGaps, Standard());
    int lastWasGap = -1;
    int inGap;

    for (; it != itEnd; ++it, ++cit, xEnd += 20, ++svg.cursor.i1)
    {
        inGap = isGap(it);
        if (lastWasGap != inGap || inGap != static_cast<int>(isGap(cit)) || (!inGap && convert<Dna5>(*cit) != convert<Dna5>(*it)))
        {
            if (x < xEnd && lastWasGap != -1)
            {
                svg.file << first << x << "\" y1=\"" << line << second << xEnd;
                svg.file << "\" y2=\"" << line << "\" " << svg.style[style + arrow + lastWasGap] << " />" << std::endl;
                arrow = 0;
            }
            lastWasGap = inGap;
            x = xEnd;
            if (!inGap && convert<Dna5>(*cit) != convert<Dna5>(*it))
            {
                svg.file << "<g transform=\"translate(" << xEnd + 10 << ',' << line << ")\"><text y=\"0.3em\" " << svg.style[svg.readText] << '>';
                writeValue(&svg, convert<char>(*it));
                svg.file << "</text></g>" << std::endl;
                x += 20;
                arrow = 0;
            }
        }
    }
    if (x < xEnd && lastWasGap != -1)
    {
        if (static_cast<int>(_unclippedLength(readGaps)) == static_cast<int>(endPosition(readGaps)))
        {
            if (alignedRead.beginPos < alignedRead.endPos)
            {
                arrow = 2;
                xEnd -= 10;
            }
            else
            {
                xEnd -= 5;
            }
        }
        svg.file << first << x << "\" y1=\"" << line << second << xEnd;
        svg.file << "\" y2=\"" << line << "\" " << svg.style[style + arrow + lastWasGap] << " />" << std::endl;
    }
}


//////////////////////////////////////////////////////////////////////////////
// stream operators
//////////////////////////////////////////////////////////////////////////////
/*
template <typename TSource>
inline SVGFile &
operator << (SVGFile & target,
             TSource  source)
{
    typename DirectionIterator<TStream, Output>::Type it = directionIterator(target, Output());
    write(it, source);
    return target;
}
*/

//inline SVGFile &
//operator << (SVGFile & target, char source)
//{
//  typename DirectionIterator<SVGFile, Output>::Type it = directionIterator(target, Output());
//  write(it, source);
//    return target;
//}
//
//inline SVGFile &
//operator << (SVGFile & target, char const *source)
//{
//  typename DirectionIterator<SVGFile, Output>::Type it = directionIterator(target, Output());
//  write(it, source);
//    return target;
//}


template <typename TStringSet, typename TTrace, typename TIndexPair>
void
_alignNeedlemanWunschMatrix(SVGFile& svg,
                              TStringSet const& str,
                              TTrace const& trace,
                              TIndexPair const&)
{
    typedef typename Size<TStringSet>::Type TSize;
    //typedef typename Value<TTrace>::Type TTraceValue;

    // TraceBack values
    const int Diagonal = 0;
    const int Horizontal = 1;
    const int Vertical = 2;

    // Initialization
    TSize numCols = length(str[0]);
    TSize numRows = length(str[1]);

    // Print trace matrix
    for (TSize pos0 = 0; pos0 < numCols; ++pos0)
    {
        for (TSize pos1 = 0; pos1 < numRows; ++pos1)
        {
            int tv =(int)trace[pos0*numRows + pos1];
                if (tv & (1 << Diagonal))
                    svg.file << "<line x2=\"" << pos0*20+10 << "\" y2=\"" << pos1*20+10 << "\"" << " x1=\"" << (pos0+1)*20+10 << "\" y1=\"" << (pos1+1)*20+10 << "\" " << svg.style[svg.dpMatrix] << " />" << std::endl;

                if (tv & (1 << Horizontal))
                    svg.file << "<line x2=\"" << pos0*20+10 << "\" y2=\"" << (pos1+1)*20+10 << "\"" << " x1=\"" << (pos0+1)*20+10 << "\" y1=\"" << (pos1+1)*20+10 << "\" " << svg.style[svg.dpMatrix] << " />" << std::endl;

                if (tv & (1 << Vertical))
                    svg.file << "<line x2=\"" << (pos0+1)*20+10 << "\" y2=\"" << pos1*20+10 << "\"" << " x1=\"" << (pos0+1)*20+10 << "\" y1=\"" << (pos1+1)*20+10 << "\" " << svg.style[svg.dpMatrix] << " />" << std::endl;
        }
    }

    // Print sequences
    for (TSize pos0 = 0; pos0 < numCols; ++pos0)
        svg.file << "<g transform=\"translate(" << pos0*20+20 << ",5)\"><text y=\"0.3em\" " << svg.style[svg.dpSequence] << '>' << str[0][pos0] << "</text></g>" << std::endl;

    for (TSize pos1 = 0; pos1 < numRows; ++pos1)
        svg.file << "<g transform=\"translate(0," << pos1*20+25 << ")\"><text y=\"0.3em\" " << svg.style[svg.dpSequence] << '>' << str[1][pos1] << "</text></g>" << std::endl;
}

template <typename TStringSet, typename TId, typename TPos, typename TTraceValue>
inline void
_alignTracePrint(SVGFile& svg,
                   TStringSet const&,
                   TId const,
                   TPos pos1,
                   TId const,
                   TPos pos2,
                   TPos const segLen,
                   TTraceValue const tv)
{
    // TraceBack values
    TTraceValue Diagonal = 0; TTraceValue Horizontal = 1; TTraceValue Vertical = 2;

    svg.file << "<line x2=\"" << pos1*20+10 << "\" y2=\"" << pos2*20+10 << "\"";
    if (tv == Diagonal) {
        pos1 += segLen; pos2 += segLen;
    } else if (tv == Horizontal) {
        pos1 += segLen;
    } else if (tv == Vertical) {
        pos2 += segLen;
    }
    svg.file << " x1=\"" << pos1*20+10 << "\" y1=\"" << pos2*20+10;
    svg.file << "\" " << svg.style[svg.dpTrace] << " />" << std::endl;
}

//////////////////////////////////////////////////////////////////////////////



} //namespace seqan

#endif //#ifndef SEQAN_HEADER_...