Optimal detection and estimation of straight patterns