Yoko wouldn't have taken chemistry if it hadn't been necessary.

Literal

Yoko [topic-は] necessary was-not [if-なら] chemistry [object-を] take-did-not [probably-でしょう].

A counterfactual conditional using ~なら on the negative past 必要でなかった. Note the somewhat unusual placement of the subject: the sentence makes 必要 ('necessary') a statement about chemistry, with its subject omitted. 化学を取る ('to take a class') is the standard collocation for enrolling in a subject.