Example #1
0
def operate_swipe_up_half(operate, driver):
    width = driver.get_window_size()["width"]
    height = driver.get_window_size()["height"]
    for i in range(operate["screens"] + 1):
        driver.swipe(width / 2, height * 3 / 4 / 2, width / 2, height / 4 / 2,
                     500)
        set_time(2)
Example #2
0
def servers_run():
    server = AppiumServer(devices)

    while True:
        server_status = server.is_runnig()
        for device, status in server_status.items():
            if status == 200:
                return True
            else:
                server.start_server()
                set_time(10)
            set_time(3)
Example #3
0
    def operate_element(self, operate_list, flag=-2):
        if self.find_element(operate_list):
            elements = {
                Variable.CLICK:
                lambda: operate_click(operate_list, self.driver),
                Variable.SEND_KEYS:
                lambda: send_keys(operate_list, self.driver),
                Variable.SEND_CODE:
                lambda: set_time(2),
                Variable.UP:
                lambda: operate_swipe_up(operate_list, self.driver),
                Variable.DOWN:
                lambda: operate_swipe_down(operate_list, self.driver),
                Variable.LEFT:
                lambda: operate_swipe_left(operate_list, self.driver),
                Variable.RIGHT:
                lambda: operate_swipe_right(operate_list, self.driver),
                Variable.SWIPE_CLICK:
                lambda: operate_swipe(operate_list, self.driver),
                Variable.BACK_CODE:
                lambda: operate_back(operate_list, self.driver),
            }

            elements[operate_list["operate_type"]]()
            flag = 1

        return flag
Example #4
0
    def execute(self, *args, **kwargs):
        res = dict()
        tasks = get_yam(kwargs.get("f"))
        res.setdefault("total", len(tasks))
        for task in tasks:
            log.info("start for task: %s, for device: %s", task, self.device)

            if self.reset and task.get("reset", None):
                log.warn("this task not need run.")
                continue

            if task.get("operate_type") == Variable.CHECK:
                status = self.action.find_element(task)
                if status:
                    log.info("pass check this element, and run next action")
                    continue
                else:
                    log.info("no pass check this element, and run next job")
                    break

            if task.get('webview'):
                print self.driver.contexts
                self.driver.switch_to.context('WEBVIEW_com.tencent.tbs')
                all_handles = self.driver.window_handles
                for handle in all_handles:
                    self.driver.switch_to_window(handle)
                    print self.driver.page_source
                    print "*" * 90

            self.action.operate_element(task)

            # load page source need sleeps
            need_sleeps = task.get("sleeps")
            log.info("this task: %s, need sleep for: %s", task, need_sleeps)
            if need_sleeps:
                set_time(need_sleeps)
Example #5
0
def bigwigs_to_multivec(input_files, output_file=None, starting_resolution=1):
    """
    Convert a bigwig file to a multivec file.

    Parameters
    ----------
    input_files: array of file paths
    output_file: output file path
    starting_resolution: int (default 1)
        The starting resolution of the input data
    """

    utils.set_time()

    ## Handling Errors.
    # None input file.
    if len(input_files) is 0:
        print("No input file suggested.")
        return
    print(len(input_files), "files prepared.")

    # Not a bigwig file.
    for in_file in input_files:
        bw = pyBigWig.open(in_file)
        if not bw.isBigWig():
            print("Input files are not in a BigWig format:", in_file)
            bw.close()
            return
        bw.close()

    # Define const variables.
    EMPTY_VALUE = np.nan

    ## Convert
    # Store data in a cache file.
    with tempfile.TemporaryDirectory() as td:
        print("temporary dir:", td)

        temp_file = op.join(td, "temp.mv5")
        f_out = h5py.File(temp_file, "w")

        # Store largest sizes of individual chromosomes.
        # Expect to be identical, but make sure.
        chromsizes = []
        for in_file in input_files:
            bw = pyBigWig.open(in_file)
            _chromsizes = bw.chroms()  # dictionary
            if len(chromsizes) is 0:
                chromsizes = _chromsizes
            else:
                for (k, v) in _chromsizes.items():
                    if k not in chromsizes:
                        chromsizes[k] = v
                    elif k in chromsizes and chromsizes[k] < v:
                        chromsizes[k] = v
            bw.close()

        # Convert dict to a list of tuples to input to multivec function.
        chromsizes = sorted([(k, v) for k, v in chromsizes.items()],
                            key=utils.sort_by_chrom)

        # TODO: Remove this line when tested with a single chromosome.
        if IS_DEBUG:
            # chromsizes = [("chr1", 248956422)]
            chromsizes = [("chr9", 138394717)]

        # Init a variable.
        raw_data = {
            chrom: np.zeros(
                (len(input_files), math.ceil(size / starting_resolution)))
            for (chrom, size) in chromsizes
        }
        # Create caches using name and size
        for (chrom, size) in chromsizes:
            f_out.create_dataset(chrom, (
                math.ceil(size / starting_resolution),
                len(input_files),
            ),
                                 fillvalue=EMPTY_VALUE,
                                 compression="gzip")

        print("Data initialized.", utils.get_time_duration())

        for file_index, cur_in_file in enumerate(input_files):
            bw = pyBigWig.open(cur_in_file)

            for (chrom, size) in bw.chroms().items():

                for interval in bw.intervals(chrom):
                    (interval_start, interval_end, value) = interval

                    fixed_interval_start = interval_start // starting_resolution
                    fixed_interval_end = math.ceil(interval_end /
                                                   starting_resolution)

                    raw_data[chrom][file_index][
                        fixed_interval_start:fixed_interval_end] = np.full(
                            (fixed_interval_end - fixed_interval_start), value)

            bw.close()
            print("File processed:", cur_in_file, utils.get_time_duration())

        # Store raw data to a cache file.
        # Use chunk for h5py to enhance performance.
        # https://stackoverflow.com/a/27713489
        is_chunck = False  # TODO: chunck not working with non-one resolution.
        chunck_size = 100000000
        for (chrom, size) in chromsizes:
            if is_chunck:
                cur_size = 0
                while cur_size < size:
                    next_size = cur_size + chunck_size if cur_size + chunck_size < size else size
                    f_out[chrom][cur_size:next_size] = raw_data[chrom].T[
                        cur_size:next_size]
                    cur_size = next_size
            else:
                f_out[chrom][0:math.ceil(size / starting_resolution
                                         )] = raw_data[chrom].T

        print("Cache file saved", f_out[chrom].shape,
              utils.get_time_duration())
        f_out.close()

        tf = temp_file
        f_in = h5py.File(tf, "r")

        # The path of an output file.
        if output_file is None:
            output_file = op.splitext([input_files[0]][0])[0] + ".multires.mv5"
        print("output_file:", output_file, utils.get_time_duration())

        # Override the output file if it existts.
        if op.exists(output_file):
            os.remove(output_file)

        cmv.create_multivec_multires(
            f_in,
            chromsizes=chromsizes,
            agg=lambda x: np.nansum(x.T.reshape(
                (x.shape[1], -1, 2)), axis=2).T,  # Default aggregation lamda.
            starting_resolution=starting_resolution,
            tile_size=256,
            output_file=output_file)
        print("Done Converting.", utils.get_time_duration())
Example #6
0
def operate_swipe_left(operate, driver):
    width = driver.get_window_size()["width"]
    height = driver.get_window_size()["height"]
    for i in range(operate["screens"] + 1):
        driver.swipe(width / 4 * 3, height / 2, width / 4, height / 2, 500)
        set_time(2)