
\begin{algorithm}
  \begin{algorithmic}
    
    \Function{edit}{$G$, $P$}
    \State \Comment{Generate a new graph which embeds $G$ and the paths in $P$.}
    %\State $P \gets \Call{simplify}{P}$
    \State $breakpoints \gets \Call{find\_breakpoints}{P}$
    \EndFunction

    %\Function{simplify}{$P$}
    %\ForAll{path $p$ in $P$}
    %\State $simplified\_path \gets []$
    %\ForAll{mapping $m$ in $p$}
    %\EndFor
    %\EndFor
    %\EndFunction

    \Function{find\_breakpoints}{$P$}
    \State \Comment{Collect positions where we must cut the graph to include the paths.}
    \State $breakpoints \gets \emptyset$
    \ForAll{path $p$ in $P$}
    \ForAll{mapping $m$ in $p$}
    \State $p \gets \Call{position}{m}$
    \State $n \gets \Call{node}{p}$
    \State $o \gets \Call{offset}{p}$
    %\State $s \gets \Call{strand}{p}$
    %\If {$strand$ = $-$}
    %\State $p \gets \Call{reverse}{p}$
    \ForAll{edit $e$ in $m$}
    \State $from\_length \gets \Call{from\_length}{e}$
    \State $p \gets \Call{increment}{p, f}$
    \If{$\Call{offset}{p} < \Call{length}{n}$}
    \State $breakpoints \gets breakpoints \cup p$
    \EndIf
    \EndFor
    \EndFor
    \EndFor
    \Return $\Call{forwardize}{breakpoints}$
    \EndFunction

    \Function{cut}{$G$, $breakpoints$}
    \State $translation \gets \emptyset$
    
    \Return $\{ translation, G \}$
    \EndFunction

    \Function{forwardize}{$positions$}
    \State \Comment{Represent the positions on the forward strand.}
    \ForAll{position $p$ in $breakpoints$}
    \State $forward\_positions \gets \emptyset$
    \If{$\Call{strand}{p} = -$}
    \State $forward\_positions \gets forward\_positions \cup \Call{reverse}{p}$
    \Else
    \State $forward\_positions \gets forward\_positions \cup p$
    \EndIf
    \EndFor
    \Return $forward\_positions$
    \EndFunction

    \Function{position}{$mapping$}
    \Return beginning position of $mapping$
    \EndFunction

    \Function{node}{$position$}
    \Return node of $position$
    \EndFunction

    \Function{offset}{$position$}
    \Return offset of $position$ in node
    \EndFunction

    \Function{strand}{$position$}
    \Return strand of $position$
    \EndFunction

    \Function{flip}{$strand$}
    \If{$strand$ = $+$}
    \Return $-$
    \Else{}
    \Return $+$
    \EndIf
    \EndFunction

    \Function{length}{$node$}
    \Return length of the label of $node$
    \EndFunction

    \Function{reverse}{$position$}
    \State $n \gets \Call{node}{position}$
    \State $l \gets \Call{length}{n}$
    \Return $\{ \Call{node}{position}, \Call{flip}{strand}, l \}$
    \EndFunction

    \Function{from\_length}{$edit$}
    \Return reference length of $edit$
    \EndFunction

    \Function{to\_length}{$edit$}
    \Return target length of $edit$
    \EndFunction

  \end{algorithmic}
  \caption{Edit the graph.}
\end{algorithm}
