Stocks rose on Thursday after six days of losses as a narrowed U.S. trade deficit was seen as one positive point in a recent string of weak economic data.

Various economists said the narrower deficit for April could prompt upward revisions of gross domestic product growth in the second quarter.

A lot of the improvement in the trade deficit was related to the Japan earthquake, which ironically has been distorting the data the other way for months now, said John Canally, investment strategist and economist at LPL Financial in Boston.

The S&P 500 posted its best day so far this month, but the mood remained fragile, with many analysts expecting the benchmark index to retest its March 2010 low after the latest data from the labor market provided little room for optimism.

A test of 1,250 is pretty likely in the next couple of weeks, Canally said. We do think it's going to hold, unless we get another round of bad news from Europe. Data from May is going to look weak, but earnings estimates are still relatively unchanged.

The link to the Japanese earthquake in the data also backs widespread opinions that the recent economic soft patch is temporary and not pointing to a dip back into recession in the United States.

S&P sectors most linked to a growing economy led the market higher, with materials <.GSPM> up 1.7 percent and energy <.GSPE> up 1.2 percent. The Morgan Stanley cyclical index <.CYC>, which is down more than 5 percent in June, rose 1.1 percent on Thursday.

The Dow Jones industrial average <.DJI> gained 93.92 points, or 0.78 percent, to 12,142.86. The Standard & Poor's 500 Index <.SPX> added 10.38 points, or 0.81 percent, to 1,289.94. The Nasdaq Composite Index <.IXIC> rose 12.38 points, or 0.46 percent, to 2,687.76.

The PHLX semiconductor index <.SOX> bounced off its 200-day moving average and was holding above 410, a key level that provided strong support in March.

It's telling you that these supply chain disruptions in Japan may be ebbing, and once that happens business can tick up again, LPL's Canally said. Demand is still out there, consumers just couldn't get what they wanted.

Texas Instruments Inc shares rose 1.1 percent to $33.04 even after cutting its earnings and revenue forecasts late on Wednesday. The company blamed the shortfall on major client Nokia's ailing cellphone business.

Shares of China-based Taomee Holdings Ltd fell 4 percent in their stock market debut as U.S.-listed Chinese companies come under more scrutiny following a series of accounting scandals. U.S. regulators, brokers and investors are sharpening their look at Chinese companies.

Details of Thursday's economic data showed the U.S. trade deficit narrowed unexpectedly in April as U.S. exports rose to a record and imports from Japan tumbled more than 25 percent.

A separate report showed the number of Americans filing new claims for unemployment benefits rose by 1,000 last week, while continued claims fell more than expected.

(Reporting by Rodrigo Campos; additional reporting by Edward Krudy and Clare Baldwin; Editing by Padraic Cassidy)