Visualize a string/sequence, emphasizing certain substrings
Graphics[{Gray, EdgeForm[Gray], FaceForm[LightBlue],
SequenceReplace[Flatten[Join[{1}, {#[[1]] - 1,
Rectangle[{#[[1]], -5}, {#[[2]], 5}], #[[2]] + 1} & /@
StringPosition[seq, Alternatives @@ segments], {StringLength @ seq}]],
{a_Integer, b_Integer} :> Line[{{a, 0}, {b, 0}}]]}, ImageSize -> 800]
Also
Graphics[{EdgeForm[Gray], FaceForm[LightBlue],
Rectangle[{#[[1]], -5}, {#[[2]], 5}]& /@ StringPosition[seq, Alternatives @@ segments]},
Axes -> {True, False}, Ticks -> None,
PlotRange -> {{0, StringLength @ seq}, Automatic}, ImageSize -> 800,
Method -> {"AxesInFront" -> False}]
Alternatively, use NumberLinePlot
:
NumberLinePlot[Interval/@StringPosition[seq, Alternatives @@ segments],
Spacings -> 0, Ticks -> None, ImageSize -> 600,
PlotStyle -> Directive[Opacity[1], PointSize[0], CapForm["Butt"], Thickness[.02]],
PlotRange->{{0, StringLength @ seq}, Automatic}]
seq must be a string
Graphics[{Blue, Line[{{0, 15}, {StringLength@seq, 15}}],
Rectangle[{#, 0}, {#2, 30}] & @@@ StringPosition[seq, segments]}]