I would ask how long the gasping goes on. If it is for more than two minutes even after sitting up - really fighting for air and not really able to speak - then you should get medical advice, as that would sound like overloaded pulmonary veins from cardiac or kidney problems.
If the gasping dies down after about half a minute to a minute and you feel OK again I agree with adreno that this might be sleep apnoea (when you think you were awake you might have nodded off without realising it). I also think this may be some sort of hypersensitivity of lung J receptors. Pulmonary venous pressure goes up in all of us when we lie down and I think it is conceivable that in some situations that lung is oversensitive to this. I can get something like this at night if it is very hot and I have done a lot of exercise that day. It would make sense to me that in ME the sensory sensitivity could do this, although that is me speculating again. I found I could get rid of my version by sleeping slightly propped up on three pillows and keeping a window open.
The only thing I think would be important to check out, as I say, would be pulmonary venous overload, but if it is that it tends to go on a long time and you know something is badly wrong.