TORONTO, Jan 12 (Reuters) - Canadian lumber companies and gold miners gained and the country’s biggest marijuana producers fell sharply on Friday, leaving the main Toronto equity index slightly higher on the day but down for the week.

* The Toronto Stock Exchange’s S&P/TSX composite index ended up 21.24 points, or 0.13 percent, at 16,308.18. It lost 0.25 percent over the course of the week, after three weeks of gains.

* Among the most influential gainers on the index were two of the world’s largest gold producers, with Barrick Gold Corp gaining 2.8 percent to C$18.88 and Goldcorp Inc up 2.6 percent to C$17.89 as gold futures rose 1.3 percent to $1,338.2 an ounce.

* Lumber companies, whose softwood products are the subject of a trade spat between Canada and the United States, also advanced, with Canfor Corp up 5.6 percent to C$27.19 and West Fraser Timber Co Ltd rising 5.4 percent to C$84.83.

* Cannabis companies, which have risen sharply as they race to prepare for Canada’s legalization of recreational use, extended a recent pullback. Aphria Inc fell 112.3 percent to C$18.02 and Canopy Growth Corp was down 13.9 percent to C$32.35.

* An influx of global capital pushed many cannabis producers to record highs over the last few weeks and investors have since been booking profits, said PI Financial analyst Jason Zandberg. “Canada is a very small market on the global scene, yet it is the only really legitimate place for cannabis companies,” he said. “The weight of capital into the relatively tiny market in Canada can create waves on both the upside and downside.”

* The energy group added 0.3 percent, with Peyto Exploration and Development Corp adding 4.3 percent to C$13.76 after saying it will cut its 2018 capital budget and dividend payouts. (Reporting by Alastair Sharp and Nichola Saminather; Editing by Bernadette Baum and Sandra Maler)