Beispiel #1
0
def download(_, outputs, sample):
    """inputs (_) is None"""
    msg_id = str(sample)
    # e.g. sra
    # test_data_downloaded_for_genesis/rsem_output/human/GSE24455/GSM602557/SRX029242/SRR070177/SRR070177.sra
    sra, flag_file = outputs  # the others are sra files
    sra_outdir = os.path.dirname(sra)
    if not os.path.exists(sra_outdir):
        os.makedirs(sra_outdir)
    # e.g. url_path:
    # /sra/sra-instant/reads/ByExp/sra/SRX/SRX029/SRX029242
    url_path = urlparse.urlparse(sample.url).path
    sra_url_path = os.path.join(url_path, *sra.split('/')[-2:])

    cmd = config['CMD_ASCP'].format(log_dir=sra_outdir,
                                    url_path=sra_url_path,
                                    output_dir=sra_outdir)
    returncode = misc.execute(cmd, msg_id, flag_file, options.debug)
    if returncode != 0 or returncode is None:
        # try wget
        # cmd template looks like this:
        # wget ftp://ftp-trace.ncbi.nlm.nih.gov{url_path} -P {output_dir} -N
        cmd = config['CMD_WGET'].format(url_path=sra_url_path,
                                        output_dir=sra_outdir)
        misc.execute(cmd, msg_id, flag_file, options.debug)
Beispiel #2
0
 def test_execute_started_and_finished_successfully(self, mock_subprocess, mock_touch, L):
     mock_subprocess.call.return_value = 0
     self.assertEqual(misc.execute('some cmd', 'msg_id', 'some_flag.txt'), 0)
     L.check(('rsempipeline.utils.misc', 'INFO', 'executing CMD: some cmd'),
             ('rsempipeline.utils.misc', 'INFO',
              'msg_id: execution succeeded with a returncode of 0. CMD: "some cmd"'))
     mock_touch.assert_called_with('some_flag.txt')
Beispiel #3
0
 def test_execute_started_but_fail_to_finish(self, mock_subprocess, mock_touch, L):
     mock_subprocess.call.return_value = 1
     self.assertEqual(misc.execute('some cmd', 'msg_id'), 1)
     L.check(('rsempipeline.utils.misc', 'INFO', 'executing CMD: some cmd'),
             ('rsempipeline.utils.misc', 'ERROR',
              'msg_id: started, but failed to finish with a returncode of 1. CMD: "some cmd"'))
     self.assertFalse(mock_touch.called)
Beispiel #4
0
 def test_execute_fail_to_start(self, mock_subprocess, L):
     mock_subprocess.call.side_effect = OSError('some err msg')
     self.assertIsNone(misc.execute('some cmd', 'msg_id'))
     L.check((
         'rsempipeline.utils.misc', 'INFO', 'executing CMD: some cmd'
     ), ('rsempipeline.utils.misc', 'ERROR',
         'msg_id: failed to start, raising OSError some err msg. CMD: "some cmd"'
         ))
Beispiel #5
0
 def test_execute_started_but_fail_to_finish(self, mock_subprocess,
                                             mock_touch, L):
     mock_subprocess.call.return_value = 1
     self.assertEqual(misc.execute('some cmd', 'msg_id'), 1)
     L.check((
         'rsempipeline.utils.misc', 'INFO', 'executing CMD: some cmd'
     ), ('rsempipeline.utils.misc', 'ERROR',
         'msg_id: started, but failed to finish with a returncode of 1. CMD: "some cmd"'
         ))
     self.assertFalse(mock_touch.called)
Beispiel #6
0
 def test_execute_started_and_finished_successfully(self, mock_subprocess,
                                                    mock_touch, L):
     mock_subprocess.call.return_value = 0
     self.assertEqual(misc.execute('some cmd', 'msg_id', 'some_flag.txt'),
                      0)
     L.check((
         'rsempipeline.utils.misc', 'INFO', 'executing CMD: some cmd'
     ), ('rsempipeline.utils.misc', 'INFO',
         'msg_id: execution succeeded with a returncode of 0. CMD: "some cmd"'
         ))
     mock_touch.assert_called_with('some_flag.txt')
Beispiel #7
0
def download(_, outputs, sample):
    """inputs (_) is None"""
    msg_id = str(sample)
    # e.g. sra
    # test_data_downloaded_for_genesis/rsem_output/human/GSE24455/GSM602557/SRX029242/SRR070177/SRR070177.sra
    sra, flag_file = outputs    # the others are sra files
    sra_outdir = os.path.dirname(sra)
    if not os.path.exists(sra_outdir):
        os.makedirs(sra_outdir)
    # e.g. url_path:
    # /sra/sra-instant/reads/ByExp/sra/SRX/SRX029/SRX029242
    url_path = urlparse.urlparse(sample.url).path
    sra_url_path = os.path.join(url_path, *sra.split('/')[-2:])

    cmd = config['CMD_ASCP'].format(
        log_dir=sra_outdir, url_path=sra_url_path, output_dir=sra_outdir)
    returncode = misc.execute(cmd, msg_id, flag_file, options.debug)
    if returncode != 0 or returncode is None:
        # try wget
        # cmd template looks like this:
        # wget ftp://ftp-trace.ncbi.nlm.nih.gov{url_path} -P {output_dir} -N
        cmd = config['CMD_WGET'].format(
            url_path=sra_url_path, output_dir=sra_outdir)
        misc.execute(cmd, msg_id, flag_file, options.debug)
Beispiel #8
0
 def test_execute_fail_to_start(self, mock_subprocess, L):
     mock_subprocess.call.side_effect = OSError('some err msg')
     self.assertIsNone(misc.execute('some cmd', 'msg_id'))
     L.check(('rsempipeline.utils.misc', 'INFO', 'executing CMD: some cmd'),
             ('rsempipeline.utils.misc', 'ERROR',
              'msg_id: failed to start, raising OSError some err msg. CMD: "some cmd"'))