We recently demonstrated that the superconductor-to-insulator transition induced by ionic liquid gating of the high temperature superconductor YBa2Cu3O7 (YBCO) is accompanied by a deoxygenation of the sample [A. M. Perez-Munoz et al., Proc. Natl. Acad. Sci. U. S. A. 114, 215 (2017)]. Density functional theory calculations helped establish that the pronounced changes in the spectral features of the Cu K-edge absorption spectra measured in situ during the gating experiment arise from a decrease of the Cu coordination within the CuO chains. In this work, we provide a detailed analysis of the electronic structure origin of the changes in the spectra resulting from three different types of doping: (i) the formation of oxygen vacancies within the CuO chains, (ii) the formation of oxygen vacancies within the CuO2 planes, and (iii) the electrostatic doping. For each case, three stoichiometries are studied and compared to the stoichiometric YBa2Cu3O7, i.e., YBa2Cu3O6.75, YBa2Cu3O6.50, and YBa2Cu3O6.25. Computed vacancy formation energies further support the chain-vacancy mechanism. In the case of doping by vacancies within the chains, we study the effect of oxygen ordering on the spectral features and we clarify the connection between the polarization of the x-rays and this doping mechanism. Finally, the inclusion of the Hubbard U correction on the computed spectra for antiferromagnetic YBa2Cu3O6.25 is discussed.