def _cromwell_move_outputs(metadata, final_dir):
    """Move Cromwell outputs to the final upload directory.
    """
    sample_key = [k for k in metadata["outputs"].keys() if k.endswith(("rgnames__sample", "rgnames__sample_out"))][0]
    project_dir = utils.safe_makedir(os.path.join(final_dir, "project"))
    samples = metadata["outputs"][sample_key]
    def _copy_with_secondary(f, dirname):
        if len(f["secondaryFiles"]) > 1:
            dirname = utils.safe_makedir(os.path.join(dirname, os.path.basename(os.path.dirname(f["location"]))))
        if not objectstore.is_remote(f["location"]):
            finalf = os.path.join(dirname, os.path.basename(f["location"]))
            if not utils.file_uptodate(finalf, f["location"]):
                shutil.copy(f["location"], dirname)
        [_copy_with_secondary(sf, dirname) for sf in f["secondaryFiles"]]
    def _write_to_dir(val, dirname):
        if isinstance(val, (list, tuple)):
            [_write_to_dir(v, dirname) for v in val]
        else:
            _copy_with_secondary(val, dirname)
    for k, vals in metadata["outputs"].items():
        if k != sample_key:
            if k.endswith(("summary__multiqc")):
                vs = [v for v in vals if v]
                assert len(vs) == 1
                _write_to_dir(vs[0], project_dir)
            elif len(vals) == len(samples):
                for s, v in zip(samples, vals):
                    if v:
                        _write_to_dir(v, utils.safe_makedir(os.path.join(final_dir, s)))
            elif len(vals) == 1:
                _write_to_dir(vals[0], project_dir)
            elif len(vals) > 0:
                raise ValueError("Unexpected sample and outputs: %s %s %s" % (k, samples, vals))
def _cromwell_move_outputs ( metadata , final_dir ) : sample_key = [ k for k in metadata [ "outputs" ] . keys ( ) if k . endswith ( ( "rgnames__sample" , "rgnames__sample_out" ) ) ] [ 0 ] project_dir = utils . safe_makedir ( os . path . join ( final_dir , "project" ) ) samples = metadata [ "outputs" ] [ sample_key ] def _copy_with_secondary ( f , dirname ) : if len ( f [ "secondaryFiles" ] ) > 1 : dirname = utils . safe_makedir ( os . path . join ( dirname , os . path . basename ( os . path . dirname ( f [ "location" ] ) ) ) ) if not objectstore . is_remote ( f [ "location" ] ) : finalf = os . path . join ( dirname , os . path . basename ( f [ "location" ] ) ) if not utils . file_uptodate ( finalf , f [ "location" ] ) : shutil . copy ( f [ "location" ] , dirname ) [ _copy_with_secondary ( sf , dirname ) for sf in f [ "secondaryFiles" ] ] def _write_to_dir ( val , dirname ) : if isinstance ( val , ( list , tuple ) ) : [ _write_to_dir ( v , dirname ) for v in val ] else : _copy_with_secondary ( val , dirname ) for k , vals in metadata [ "outputs" ] . items ( ) : if k != sample_key : if k . endswith ( ( "summary__multiqc" ) ) : vs = [ v for v in vals if v ] assert len ( vs ) == 1 _write_to_dir ( vs [ 0 ] , project_dir ) elif len ( vals ) == len ( samples ) : for s , v in zip ( samples , vals ) : if v : _write_to_dir ( v , utils . safe_makedir ( os . path . join ( final_dir , s ) ) ) elif len ( vals ) == 1 : _write_to_dir ( vals [ 0 ] , project_dir ) elif len ( vals ) > 0 : raise ValueError ( "Unexpected sample and outputs: %s %s %s" % ( k , samples , vals ) )
Move Cromwell outputs to the final upload directory.