File: check_fast5_static.py

package info (click to toggle)
libslow5lib 0.7.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 25,084 kB
  • sloc: ansic: 11,825; python: 1,179; sh: 547; makefile: 90; cpp: 40
file content (57 lines) | stat: -rw-r--r-- 1,262 bytes parent folder | download | duplicates (2)
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
"""
Print out which fields of FAST5 files are static or variable for the same experiment.
Given h5dump output of any number of FAST5 files.
Show the constant values with -c flag.

Usage: python3 $0 [h5dump_FAST5_output...] [-c]
"""

from sys import argv

attrs = {}
var = []
const = []

args = argv[1:]
if "-c" in args:
    args.remove("-c")
    show_const = True
else:
    show_const = False

for fname in args:
    f = open(fname)

    for line in f:
        line = line.split()

        if line[0] == "ATTRIBUTE" or line[0] == "DATASET":
            curr_attr = line[1][1:-1]

            # Create empty set for attribute if not already there
            if curr_attr not in attrs:
                attrs[curr_attr] = set()

        # Data follows a (0)
        elif line[0] == "(0):":
            # Store attribute's data
            data = " ".join(line[1:])
            attrs[curr_attr].add(data)

for prop in attrs:
    if len(attrs[prop]) == 1:
        const.append(prop)
    else:
        var.append(prop)

# Print properties which are constant and variable
print("Constant:")
for prop in const:
    if show_const:
        print(f"{prop}: {list(attrs[prop])[0]}")
    else:
        print(f"{prop}")

print("\nVariable:")
for prop in var:
    print(prop)