A new algorithm can identify people at risk of self-harm before obvious warning signs appear, offering earlier intervention for depression sufferers.