Is it possible to alter the source code and still have a valid Bitcoin transaction? Say I wanted to run an alternative version of Bitcoin, and I changed 1 line in the bitcoin source code.

Is the signature/hash of the completed transaction going be the same or different when I run the original bitcoin software and my altered version? Or would they be two separate transactions?

How do miners know what transactions are valid if there are two different implementations of the BTC protocol?
It depends what you change. If you don't agree with other clients on what is a valid transaction and what is a valid block, then you won't agree on who holds what bitcoins.


  How do miners know what transactions are valid if there are two different implementations of the BTC protocol?


All the people who wish to interoperate with each other have to use the same rules for what constitutes a valid transaction and what constitutes a valid block. Groups that can't agree fork the network into two networks as happened when bitcoin split into bitcoin and bitcoin cash.