If you have a 130/140/485/LC pending, you can not claim non-reresident based on "closer relationship to a foreign country" to avoid substantial presence test (obviously the other exception such as F, J still apply). In addition,the treaty benefit still exists and you are a dual-resident under the treaty. You need to use 1040NR to file your tax return and compute your tax as a nonresident.