You can add and remove (and thus modify) liquid templates via the API. This is not tremendously well documented, but the Shopify Textmate bundle does it and I use that extensively to modify themes of my stores. You can read through the PHP code used to accomplish that here: https://github.com/meeech/shopify.tmbundle/tree/master/Support
I haven't personally code anything to use the API to modify themes, but it certainly is possible.