I think you're mixing up a few things here: who decides what gets funded, who does the work, who actually pays for the work, and who gets the reward, along with whether the work generates more revenue than it cost, and whether the preceding factors encourage more or less progress in the field concerned.
You can have various public/private combinations of these things, some being more controversial than others, such as the public paying for the work and then the specific employees concerned profiting from patents that have been filed. You can have policy delegated to the market, albeit with government-backed guarantees for revenue generation, which is what patents effectively are. You can have policy determined by both public agencies and private institutions; the quality of policy decided by the former need not be worse than that of the latter (contrary to the ideology of certain political schools).
Nobody is advocating the elimination of private research, and I think it is worth entertaining the idea of incentives for such research that don't involve monopolies for entire classes of endeavour, which is what patents have proven to be at least in software. Meanwhile, an analogous situation to pharmaceutical patents might be that of the granting of exploration rights to various oil and gas companies.
Certainly, a difference between oil exploration and software is that the rights granted to participants are clearly delimited in the former case, whereas only copyright provides a similar level of clarity in the latter case. If oil exploration rights were handed out like software patents, everyone would be drilling the same oilfields and spending a lot more time in court.