One of my students was once playing an invention in D major of J.S. Bach on the piano and I asked her what key was an episode she was currently playing. She had a difficult time discovering the key but after a long pause she decided it was B minor. True enough, it had two sharps and an additional G# and A# which are the signs of the melodic version of B minor.
This answer wasn't enough for me and I decided to go even further with her.
"Why do you think it's B minor here?", I asked.
After this question, the student was lost. No evident reasoning was apparent to her so I explained my point of view:
Since the original key of the Invention is D major, composers of the Baroque period tended to modulate to closely related keys (with some notable exceptions). Now B minor has the same number of accidentals as D major which shows it's a relative key.
In any given piece you might find the tonic key and its relative, the dominant key and its relative, and the subdominant key and its relative. In the case of D major, it would be B minor, A major, F# minor, G major, and E minor.
Do you think it's wise for organists to try to analyse their pieces they play or should this skill be left only for professional musicologists, music theoreticians and composers?