  We study the problem of similarity detection by sequence alignment with gaps,
using a recently established theoretical framework based on the morphology of
alignment paths. Alignments of sequences without mutual correlations are found
to have scale-invariant statistics. This is the basis for a scaling theory of
alignments of correlated sequences. Using a simple Markov model of evolution,
we generate sequences with well-defined mutual correlations and quantify the
fidelity of an alignment in an unambiguous way. The scaling theory predicts the
dependence of the fidelity on the alignment parameters and on the statistical
evolution parameters characterizing the sequence correlations. Specific
criteria for the optimal choice of alignment parameters emerge from this
theory. The results are verified by extensive numerical simulations.
