示例#1
0
 def test_backup_file_with_previously_backuped_file(self, mock_exists,
                                                    mock_rename):
     mock_exists.side_effect = [True, True, False]
     with LogCapture() as L:
         misc.backup_file('path/file')
     L.check(('rsempipeline.utils.misc', 'INFO',
              'Backing up path/file to path/#file.2#'), )
     mock_rename.called_once_with('path/file', 'path/#file.2#')
示例#2
0
 def test_backup_file(self, mock_exists, mock_rename):
     # Need to mock multiple return values for mock_exists because the file
     # to backup has to exist, but the backuped file with new name cannnot
     # exist
     # http://stackoverflow.com/questions/24897145/python-mock-multiple-return-values
     mock_exists.side_effect = [True, False]
     with LogCapture() as L:
         misc.backup_file('path/file')
     L.check(('rsempipeline.utils.misc', 'INFO', 'Backing up path/file to path/#file.1#'),)
     mock_rename.called_once_with('path/file', 'path/#file.1#')
示例#3
0
 def test_backup_file(self, mock_exists, mock_rename):
     # Need to mock multiple return values for mock_exists because the file
     # to backup has to exist, but the backuped file with new name cannnot
     # exist
     # http://stackoverflow.com/questions/24897145/python-mock-multiple-return-values
     mock_exists.side_effect = [True, False]
     with LogCapture() as L:
         misc.backup_file('path/file')
     L.check(('rsempipeline.utils.misc', 'INFO',
              'Backing up path/file to path/#file.1#'), )
     mock_rename.called_once_with('path/file', 'path/#file.1#')
示例#4
0
def generate_csv(input_csv, outdir, num_threads):
    # Sometimes GSM data could be private, so no species information will be
    # extracted. e.g. GSE49366 GSM1198168
    res, res_no_species = [], []

    # execute in parallel
    queue = Queue.Queue()

    def worker():
        while True:
            GSE, GSM = queue.get()
            species = find_species(GSE, GSM, outdir)
            row = [GSE, species, GSM]
            if species:
                res.append(row)
            else:
                res_no_species.append(row)
            queue.task_done()

    for i in range(num_threads):
        thrd = threading.Thread(target=worker)
        thrd.daemon = True
        thrd.start()

    for gse, gsm in read(input_csv):
        queue.put([gse, gsm])
    queue.join()

    # write output
    out_csv = os.path.join(outdir, SPECIES_CSV_BASENAME)
    no_species_csv = os.path.join(outdir, NO_SPECIES_CSV_BASENAME)
    backup_file(out_csv)
    write_csv(res, out_csv)

    if res_no_species:
        backup_file(no_species_csv)
        write_csv(res_no_species, no_species_csv)
示例#5
0
def generate_csv(input_csv, outdir, num_threads):
    # Sometimes GSM data could be private, so no species information will be
    # extracted. e.g. GSE49366 GSM1198168
    res, res_no_species = [], []

    # execute in parallel
    queue = Queue.Queue()
    def worker():
        while True:
            GSE, GSM = queue.get()
            species = find_species(GSE, GSM, outdir)
            row = [GSE, species, GSM]
            if species:
                res.append(row)
            else:
                res_no_species.append(row)
            queue.task_done()

    for i in range(num_threads):
        thrd = threading.Thread(target=worker)
        thrd.daemon = True
        thrd.start()

    for gse, gsm in read(input_csv):
        queue.put([gse, gsm])
    queue.join()

    # write output
    out_csv = os.path.join(outdir, SPECIES_CSV_BASENAME)
    no_species_csv = os.path.join(outdir, NO_SPECIES_CSV_BASENAME)
    backup_file(out_csv)
    write_csv(res, out_csv)

    if res_no_species:
        backup_file(no_species_csv)
        write_csv(res_no_species, no_species_csv)
示例#6
0
 def test_backup_file_with_nonexistent_file(self, mock_os):
     mock_os.path.exists.return_value = False
     with LogCapture() as L:
         misc.backup_file('some_nonexistent_file')
     L.check(('rsempipeline.utils.misc', 'WARNING',
              'some_nonexistent_file doesn\'t exist'), )
示例#7
0
 def test_backup_file_with_nonexistent_file(self, mock_os):
     mock_os.path.exists.return_value = False
     with LogCapture() as L:
         misc.backup_file('some_nonexistent_file')
     L.check(('rsempipeline.utils.misc', 'WARNING', 'some_nonexistent_file doesn\'t exist'),)
示例#8
0
 def test_backup_file_with_previously_backuped_file(self, mock_exists, mock_rename):
     mock_exists.side_effect = [True, True, False]
     with LogCapture() as L:
         misc.backup_file('path/file')
     L.check(('rsempipeline.utils.misc', 'INFO', 'Backing up path/file to path/#file.2#'),)
     mock_rename.called_once_with('path/file', 'path/#file.2#')