[Tex/LaTex] Iterate through a list by index

loopsnodestikz-pgf

I'm making a TikZ picture in which I have a list of node names and coordinates and I want to go through the lists putting ith node name at the ith coordinate. My MWE:

\documentclass{beamer}
\usepackage{tikz}
\tikzstyle{arrow} = [thick,->]
\tikzstyle{aAllele} = [text opacity=0, circle,text centered, fill=blue, text=white, minimum size = 0.5cm]
\tikzstyle{bAllele} = [text opacity=0, circle, text centered, fill=red, text=white, minimum size = 0.5cm]

\begin{document}
\begin{frame}
    \centering
    \begin{tikzpicture}
        \def\names{{24,23,33,22,32,11,21,31,41,00,10,20,30,40}}
        \def\coords{(2,4),(2,3),(3,3),(2,2),(3,2),(1,1),(2,1),(3,1),(4,1),(0,0),(1,0),(2,0),(3,0),(4,0)}
        \foreach \x in {0,1,2,3,4}{%
            \foreach \y in {0,1,2,3,4}{%
                \fill[red] (\x,\y) circle (0.25cm);%
            }
        }
        \foreach \i in {0,...,14}{%
            \node (\names[\i]) [aAllele] at \coords[\i] {};%
        }

    \end{tikzpicture}
\end{frame}
\end{document}

the coalescent

In this picture, the circles given by coords should be colored blue. I'm using nodes because I'd eventually like to connect them with lines; I've already gotten it to work simply by iterating over the coordinates, however I need them to be named so I can use lines to connect them. Replacing lines 18-20 with the following:

\foreach \coord in \coords{%
    \node (\coord) [aAllele] at \coord {};
}

compiles correctly, though isn't the desired result because I can't easily connect nodes by name (I think) because the nodes are given the "name" of the coordinates used to generate them.

the coalescent 2

Thanks

Best Answer

I would use nodes for the red circles and name them:

\documentclass{beamer}
\usepackage{tikz}
\tikzstyle{arrow} = [thick,->]
\tikzstyle{aAllele} = [text opacity=0, circle,text centered, fill=blue, text=white, minimum size = 0.5cm]
\tikzstyle{bAllele} = [text opacity=0, circle, text centered, fill=red, text=white, minimum size = 0.5cm]

\begin{document}
\begin{frame}
\centering
\begin{tikzpicture}
    \def\names{24,23,33,22,32,11,21,31,41,00,10,20,30,40}
    %\def\coords{(2,4),(2,3),(3,3),(2,2),(3,2),(1,1),(2,1),(3,1),(4,1),(0,0),(1,0),(2,0),(3,0),(4,0)}
    \foreach \x in {0,1,2,3,4}{%
        \foreach \y in {0,1,2,3,4}{%
            \node[bAllele](\x\y)at (\x,\y){};%
        }
    }
    \foreach \i in \names{%
        \node[aAllele] at (\i) {};%
    }
    \path[green,thick](22)
      edge(23)
      edge(32);
\end{tikzpicture}
\end{frame}
\end{document}

Result:

enter image description here