There's an article, "Pitch-Class Distribution and the Identification of Key",
David Temperley and Elizabeth West Marvin, that give some information along this line. I got it on JSTOR but it was published in "Music Perception" which journal you might have access to.

The distribution varies depending on the overall style (Baroque, Classical, Romantic, popular, jazz, etc.) There has been lots of work on the subject but much is only available from university libraries or behind paywalls.
There are some ambiguities in the original question. One can ask, "What is the distribution of tones by the number of occurrences? " or ask, " what is the total duration of each note?" These are not identical questions. The figure consisting of a chain of off-beat quarter notes (or half notes as in fourth species counterpoint) may be split into pairs of eighths or quarters respectively. These have the same harmonic and melodic significance but the counting methods may not agree.
Likewise, the existence of enharmonics matters from the point of view of the musical structures. An Ab7 chord is Ab-C-Eb-Gb (and normally resolves to a Db chord of some type) whereas the German Sixth Ab-C-Eb-F# usually resolves to a C64 chord. It's written with an F# to indicate the next note is G. It's a complication that you might wish to look into.
music21to do the transformation ( https://web.mit.edu/music21/doc/moduleReference/moduleStreamBase.html#music21.stream.base.Stream.analyze ). However, music21 is slow. So I tried to implement a simple stupid transformation myself. I smile take the piece, transpose it to all 12 possibilities and pick the one with least sharp notes, since I am in CMaj or Amin. It actually works. – hr0m Sep 13 '21 at 06:55It is actually durable with music21, my "optimization" would not be necessary, yet it halves the execution time... But I got curious :)
– hr0m Sep 13 '21 at 06:57