\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{Bio.KEGG} \PYG{k+kn}{import} \PYG{n}{REST}

\PYG{n}{human\PYGZus{}pathways} \PYG{o}{=} \PYG{n}{REST}\PYG{o}{.}\PYG{n}{kegg\PYGZus{}list}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}pathway\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}hsa\PYGZdq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{read}\PYG{p}{()}

\PYG{c+c1}{\PYGZsh{} Filter all human pathways for repair pathways}
\PYG{n}{repair\PYGZus{}pathways} \PYG{o}{=} \PYG{p}{[]}
\PYG{k}{for} \PYG{n}{line} \PYG{o+ow}{in} \PYG{n}{human\PYGZus{}pathways}\PYG{o}{.}\PYG{n}{rstrip}\PYG{p}{()}\PYG{o}{.}\PYG{n}{split}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{):}
    \PYG{n}{entry}\PYG{p}{,} \PYG{n}{description} \PYG{o}{=} \PYG{n}{line}\PYG{o}{.}\PYG{n}{split}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}t}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
    \PYG{k}{if} \PYG{l+s+s2}{\PYGZdq{}repair\PYGZdq{}} \PYG{o+ow}{in} \PYG{n}{description}\PYG{p}{:}
        \PYG{n}{repair\PYGZus{}pathways}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{entry}\PYG{p}{)}

\PYG{c+c1}{\PYGZsh{} Get the genes for pathways and add them to a list}
\PYG{n}{repair\PYGZus{}genes} \PYG{o}{=} \PYG{p}{[]}
\PYG{k}{for} \PYG{n}{pathway} \PYG{o+ow}{in} \PYG{n}{repair\PYGZus{}pathways}\PYG{p}{:}
    \PYG{n}{pathway\PYGZus{}file} \PYG{o}{=} \PYG{n}{REST}\PYG{o}{.}\PYG{n}{kegg\PYGZus{}get}\PYG{p}{(}\PYG{n}{pathway}\PYG{p}{)}\PYG{o}{.}\PYG{n}{read}\PYG{p}{()}  \PYG{c+c1}{\PYGZsh{} query and read each pathway}

    \PYG{c+c1}{\PYGZsh{} iterate through each KEGG pathway file, keeping track of which section}
    \PYG{c+c1}{\PYGZsh{} of the file we\PYGZsq{}re in, only read the gene in each pathway}
    \PYG{n}{current\PYGZus{}section} \PYG{o}{=} \PYG{n+nb+bp}{None}
    \PYG{k}{for} \PYG{n}{line} \PYG{o+ow}{in} \PYG{n}{pathway\PYGZus{}file}\PYG{o}{.}\PYG{n}{rstrip}\PYG{p}{()}\PYG{o}{.}\PYG{n}{split}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{):}
        \PYG{n}{section} \PYG{o}{=} \PYG{n}{line}\PYG{p}{[:}\PYG{l+m+mi}{12}\PYG{p}{]}\PYG{o}{.}\PYG{n}{strip}\PYG{p}{()}  \PYG{c+c1}{\PYGZsh{} section names are within 12 columns}
        \PYG{k}{if} \PYG{o+ow}{not} \PYG{n}{section} \PYG{o}{==} \PYG{l+s+s2}{\PYGZdq{}\PYGZdq{}}\PYG{p}{:}
            \PYG{n}{current\PYGZus{}section} \PYG{o}{=} \PYG{n}{section}

        \PYG{k}{if} \PYG{n}{current\PYGZus{}section} \PYG{o}{==} \PYG{l+s+s2}{\PYGZdq{}GENE\PYGZdq{}}\PYG{p}{:}
            \PYG{n}{gene\PYGZus{}identifiers}\PYG{p}{,} \PYG{n}{gene\PYGZus{}description} \PYG{o}{=} \PYG{n}{line}\PYG{p}{[}\PYG{l+m+mi}{12}\PYG{p}{:]}\PYG{o}{.}\PYG{n}{split}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}; \PYGZdq{}}\PYG{p}{)}
            \PYG{n}{gene\PYGZus{}id}\PYG{p}{,} \PYG{n}{gene\PYGZus{}symbol} \PYG{o}{=} \PYG{n}{gene\PYGZus{}identifiers}\PYG{o}{.}\PYG{n}{split}\PYG{p}{()}

            \PYG{k}{if} \PYG{o+ow}{not} \PYG{n}{gene\PYGZus{}symbol} \PYG{o+ow}{in} \PYG{n}{repair\PYGZus{}genes}\PYG{p}{:}
                \PYG{n}{repair\PYGZus{}genes}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{gene\PYGZus{}symbol}\PYG{p}{)}

\PYG{k}{print}\PYG{p}{(}
    \PYG{l+s+s2}{\PYGZdq{}There are }\PYG{l+s+si}{\PYGZpc{}d}\PYG{l+s+s2}{ repair pathways and }\PYG{l+s+si}{\PYGZpc{}d}\PYG{l+s+s2}{ repair genes. The genes are:\PYGZdq{}}
    \PYG{o}{\PYGZpc{}} \PYG{p}{(}\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{repair\PYGZus{}pathways}\PYG{p}{),} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{repair\PYGZus{}genes}\PYG{p}{))}
\PYG{p}{)}
\PYG{k}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}, \PYGZdq{}}\PYG{o}{.}\PYG{n}{join}\PYG{p}{(}\PYG{n}{repair\PYGZus{}genes}\PYG{p}{))}
\end{Verbatim}
