How do I edit an order programatically?

What is the process to edit an order; this includes $order->cancel() the original order and creating the second order with old-order-number-1 after it with the updated item detail. I need to emulate what Magento already does for this process.