Shape transition of semi-flexible macromolecules confined in channel and cavity