From the warm magnetized atomic medium to molecular clouds