File: fileops.py

package info (click to toggle)
python-cooler 0.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,596 kB
  • sloc: python: 10,555; makefile: 198; sh: 31
file content (160 lines) | stat: -rw-r--r-- 3,343 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import click

from .. import fileops
from . import cli


@cli.command()
@click.argument(
    "cool_path",
    metavar="COOL_PATH"
)
@click.option(
    "--long", "-l",
    help="Long listing format",
    is_flag=True
)
def ls(cool_path, long):
    """
    List all coolers inside a file.

    """
    from ..api import Cooler

    for group_path in fileops.list_coolers(cool_path):
        uri = cool_path + "::" + group_path
        if long:
            binsize = Cooler(uri).binsize
            if binsize is None:
                s = f"{uri}\t<variable>"
            else:
                s = f"{uri}\t{binsize:,}"
            click.echo(s)
        else:
            click.echo(uri)


@cli.command()
@click.argument(
    "src_uri",
    type=str
)
@click.argument(
    "dst_uri",
    type=str
)
@click.option(
    "--overwrite", "-w",
    help="Truncate and replace destination file if it already exists.",
    is_flag=True,
    default=False,
)
def cp(src_uri, dst_uri, overwrite):
    """
    Copy a cooler from one file to another or within the same file.

    See also: h5copy, h5repack tools from HDF5 suite.

    """
    # \b\bArguments:
    # SRC_URI : Path to source file or URI to source Cooler group
    # DST_URI : Path to destination file or URI to destination Cooler group
    # if dst_group in dst and dst_group != '/':
    #     click.confirm(
    #         "A group named '{}' already exists in '{}'. Overwrite?".format(
    #             dst_group, dst_path),
    #         abort=True)
    #     del dst[dst_group]
    fileops.cp(src_uri, dst_uri, overwrite=overwrite)


@cli.command()
@click.argument(
    "src_uri",
    type=str
)
@click.argument(
    "dst_uri",
    type=str
)
@click.option(
    "--overwrite", "-w",
    help="Truncate and replace destination file if it already exists.",
    is_flag=True,
    default=False,
)
@click.option(
    "--soft", "-s",
    help="Creates a soft link rather than a hard link if the source and "
    "destination file are the same. Otherwise, creates an external link. "
    "This type of link uses a path rather than a pointer.",
    is_flag=True,
    default=False,
)
def ln(src_uri, dst_uri, overwrite, soft):
    """
    Create a hard link to a cooler (rather than a true copy) in the same file.
    Also supports soft links (in the same file) or external links (different
    files).

    """
    fileops.ln(src_uri, dst_uri, overwrite=overwrite, soft=soft)


@cli.command()
@click.argument(
    "src_uri",
    type=str
)
@click.argument(
    "dst_uri",
    type=str
)
@click.option(
    "--overwrite", "-w",
    help="Truncate and replace destination file if it already exists.",
    is_flag=True,
    default=False,
)
def mv(src_uri, dst_uri, overwrite):
    """
    Rename a cooler within the same file.

    """
    fileops.mv(src_uri, dst_uri, overwrite=overwrite)


@cli.command()
@click.argument(
    "uri",
    type=str
)
@click.option(
    "-L", "--level",
    type=int
)
def tree(uri, level):
    """
    Display a file's data hierarchy.

    """
    t = fileops.pprint_data_tree(uri, level)
    click.echo(t)


@cli.command()
@click.argument(
    "uri",
    type=str
)
@click.option(
    "-L", "--level",
    type=int
)
def attrs(uri, level):
    """
    Display a file's attribute hierarchy.

    """
    t = fileops.pprint_attr_tree(uri, level)
    click.echo(t)