Hi... Negative thinking could have been developed because of painful past experiences or maladaptive coping mechanisms. It can be addressed using therapeutic techniques like Cognitive Behaviour Therapy (CBT).
The kind of sexual thoughts you have mentioned, suggest poor Psycho-sexual development which may occur due to numerous reasons such as - abuse, shame, poor psycho-social support, etc. in childhood/teenage.
This will require a more integrated approach using a combination of therapies like CBT, CCT, Psychoanalysis, Existentialist Approach, etc.
Next Steps
Take Counselling Sessions from a Psychologist on Weekly Basis. To Seek my Services Online you can Google me or visit my Website (https://gunjanmaithil.wixsite.com/therapy)
Health Tips
Regulating a healthy routine in terms of proper and timely Meals, Sleep, Exercise, and Breathing/Meditation will help you get back your control over your mood.