Hi @jng!
Have you played with qiime feature-table filter-features
? The filtering tutorial, especially the metadata filtering section and the docs linked above will give you some basic background.
It's a powerful tool, so there are a number of different approaches you might take. I haven't tested any of the following for your specific situation, but they represent a few possible approaches.
For your first question, --p-min-frequency
could probably be used, by passing the number of features in the 50th-most-prevalent feature. This is probably not the best approach, but would do the job.
For your second question, you might be able to filter tables to include all features in each group, then pass these tables as metadata, using --p-exclude-ids
to remove any overlapping (non-exclusive) features.
Good luck!
Chris