aptitude can get you most of the way with its search feature. Here's how you find everything installed that wasn't only an automatic dependency:
aptitude search -F "%p" "?installed ?not(?automatic)"
This wont be optimal some of these may be able to be removed but I don't know a simple way to work that out. Perhaps the answer lies in
On second thought, with that list you could loop through it and find the dependant packages (not dependencies) for each one. If one of those is in the master list, remove the current package from the list... but only after you've parsed the whole list or you'll miss intermediates in a 3+ level dep tree.
You find dependants with a query like this:
aptitude search '~i~Dpackage'
I'd try and write the script but I'm typing this on a tiny phone keyboard. Even I have limits.
Edit: After five minute of trying to sleep, I started hacking away on this. something like this should do the job:
orig=$(aptitude search -F "%p" "?installed ?not(?automatic)")
for p in $orig; do
for dependant in `aptitude search -F "%p" "~i~D$p"`; do
if [[ $orig == "* $dependant *" ]]; then
if [[ $depended == 0 ]]; then
Note this takes a really long time to run and it might be over-keen (eg it will remove thing that you manually installed, that you want to be manually installed, if they are depended on by something else in the $orig list that you perhaps installed afterwards).