generate matrix for upstream, downstream and body