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

\PYG{n}{input\PYGZus{}file} \PYG{o}{=} \PYG{l+s+s2}{\PYGZdq{}big\PYGZus{}file.sff\PYGZdq{}}
\PYG{n}{id\PYGZus{}file} \PYG{o}{=} \PYG{l+s+s2}{\PYGZdq{}short\PYGZus{}list.txt\PYGZdq{}}
\PYG{n}{output\PYGZus{}file} \PYG{o}{=} \PYG{l+s+s2}{\PYGZdq{}short\PYGZus{}list.sff\PYGZdq{}}

\PYG{k}{with} \PYG{n+nb}{open}\PYG{p}{(}\PYG{n}{id\PYGZus{}file}\PYG{p}{)} \PYG{k}{as} \PYG{n}{id\PYGZus{}handle}\PYG{p}{:}
    \PYG{n}{wanted} \PYG{o}{=} \PYG{n+nb}{set}\PYG{p}{(}\PYG{n}{line}\PYG{o}{.}\PYG{n}{rstrip}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{split}\PYG{p}{(}\PYG{n+nb+bp}{None}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{)[}\PYG{l+m+mi}{0}\PYG{p}{]} \PYG{k}{for} \PYG{n}{line} \PYG{o+ow}{in} \PYG{n}{id\PYGZus{}handle}\PYG{p}{)}
\PYG{k}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Found }\PYG{l+s+si}{\PYGZpc{}i}\PYG{l+s+s2}{ unique identifiers in }\PYG{l+s+si}{\PYGZpc{}s}\PYG{l+s+s2}{\PYGZdq{}} \PYG{o}{\PYGZpc{}} \PYG{p}{(}\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{wanted}\PYG{p}{),} \PYG{n}{id\PYGZus{}file}\PYG{p}{))}

\PYG{n}{records} \PYG{o}{=} \PYG{p}{(}\PYG{n}{r} \PYG{k}{for} \PYG{n}{r} \PYG{o+ow}{in} \PYG{n}{SeqIO}\PYG{o}{.}\PYG{n}{parse}\PYG{p}{(}\PYG{n}{input\PYGZus{}file}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}sff\PYGZdq{}}\PYG{p}{)} \PYG{k}{if} \PYG{n}{r}\PYG{o}{.}\PYG{n}{id} \PYG{o+ow}{in} \PYG{n}{wanted}\PYG{p}{)}
\PYG{n}{count} \PYG{o}{=} \PYG{n}{SeqIO}\PYG{o}{.}\PYG{n}{write}\PYG{p}{(}\PYG{n}{records}\PYG{p}{,} \PYG{n}{output\PYGZus{}file}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}sff\PYGZdq{}}\PYG{p}{)}
\PYG{k}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Saved }\PYG{l+s+si}{\PYGZpc{}i}\PYG{l+s+s2}{ records from }\PYG{l+s+si}{\PYGZpc{}s}\PYG{l+s+s2}{ to }\PYG{l+s+si}{\PYGZpc{}s}\PYG{l+s+s2}{\PYGZdq{}} \PYG{o}{\PYGZpc{}} \PYG{p}{(}\PYG{n}{count}\PYG{p}{,} \PYG{n}{input\PYGZus{}file}\PYG{p}{,} \PYG{n}{output\PYGZus{}file}\PYG{p}{))}
\PYG{k}{if} \PYG{n}{count} \PYG{o}{\PYGZlt{}} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{wanted}\PYG{p}{):}
    \PYG{k}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Warning }\PYG{l+s+si}{\PYGZpc{}i}\PYG{l+s+s2}{ IDs not found in }\PYG{l+s+si}{\PYGZpc{}s}\PYG{l+s+s2}{\PYGZdq{}} \PYG{o}{\PYGZpc{}} \PYG{p}{(}\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{wanted}\PYG{p}{)} \PYG{o}{\PYGZhy{}} \PYG{n}{count}\PYG{p}{,} \PYG{n}{input\PYGZus{}file}\PYG{p}{))}
\end{Verbatim}
