Pass view contextual filter arguments programmatically
I got the solution. It can be done using hook_views_pre_view(). Since hook_views_pre_view() allows altering a view at the very beginning of views processing, before anything is done, I am able to feed the arguments to the view.

function MODULE_NAME_views_pre_view(&amp;$view, &amp;$display_id, &amp;$args) {
  if ($view-&gt;name == 'myview' &amp;&amp; $display_id == 'page_1') {
    $tids = custom_function();
    $args[] = implode('+', $tids);
  }
}


Hope this is useful to someone :)