Imaging has become one of the most important tools for categorizing neurons based on their function. However, for a cell type identified only by its pattern of activity, the process of identifying molecular markers remains laborious. We developed physiological optical tagging sequencing (PhOTseq), a technique for tagging and ex- pression profiling of cells on the basis of their functional properties. We developed a reporter combining a green calcium indicator (GCaMP) with a photoactivatable red reporter (PAmCherry). When visualizing neuronal activity in such animals, real-time analysis allowed digital selection of cells exhibiting specific activity patterns, and photoactivation was directed specifically to those cells to tag them for later harvesting and analysis. We found that PhOTseq was capable of selecting rare cell types and enriching them by nearly 100-fold. We applied PhOTseq to the challenge of mapping receptor-ligand pairings among pheromone-sensing neurons in mice, and densely mapped the cell types responsible for encoding a specific portion of the sensory world.