batoolset 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- batoolset/GUI/__init__.py +0 -0
- batoolset/GUI/list_gui.py +513 -0
- batoolset/GUI/multi_image_display.py +989 -0
- batoolset/GUI/open.py +325 -0
- batoolset/GUI/overlay_hints.py +45 -0
- batoolset/GUI/paint2.py +1345 -0
- batoolset/GUI/scrollablepaint.py +1152 -0
- batoolset/IJ_ROIs/__init__.py +0 -0
- batoolset/IJ_ROIs/tools.py +40 -0
- batoolset/PATH/__init__.py +0 -0
- batoolset/PATH/tools.py +79 -0
- batoolset/SQLite_tools/__init__.py +0 -0
- batoolset/SQLite_tools/tools.py +840 -0
- batoolset/__init__.py +0 -0
- batoolset/binary/__init__.py +0 -0
- batoolset/binary/tools.py +123 -0
- batoolset/binarytools/__init__.py +0 -0
- batoolset/binarytools/cell_center_detector.py +290 -0
- batoolset/clipboard_tools/__init__.py +0 -0
- batoolset/clipboard_tools/tools.py +7 -0
- batoolset/colors/__init__.py +0 -0
- batoolset/colors/colorgen.py +193 -0
- batoolset/colors/tools.py +22 -0
- batoolset/command_line/__init__.py +0 -0
- batoolset/command_line/tools.py +18 -0
- batoolset/dialogs/__init__.py +0 -0
- batoolset/dialogs/opensave.py +228 -0
- batoolset/dicts/__init__.py +0 -0
- batoolset/dicts/tools.py +299 -0
- batoolset/dims/__init__.py +0 -0
- batoolset/dims/tools.py +83 -0
- batoolset/draw/__init__.py +0 -0
- batoolset/draw/shapes/Position.py +183 -0
- batoolset/draw/shapes/__init__.py +0 -0
- batoolset/draw/shapes/automated_alignment_drawing_refactored.py +346 -0
- batoolset/draw/shapes/circle2d.py +99 -0
- batoolset/draw/shapes/compute_optimal_size_all_merged.py +317 -0
- batoolset/draw/shapes/ellipse2d.py +336 -0
- batoolset/draw/shapes/freehand2d.py +235 -0
- batoolset/draw/shapes/group.py +1830 -0
- batoolset/draw/shapes/image2d.py +2469 -0
- batoolset/draw/shapes/line2d.py +575 -0
- batoolset/draw/shapes/point2d.py +257 -0
- batoolset/draw/shapes/polygon2d.py +357 -0
- batoolset/draw/shapes/polyline2d.py +235 -0
- batoolset/draw/shapes/rect2d.py +388 -0
- batoolset/draw/shapes/rectangle2d.py +601 -0
- batoolset/draw/shapes/scalebar.py +304 -0
- batoolset/draw/shapes/serializablefont.py +126 -0
- batoolset/draw/shapes/serializableguiparams.py +10 -0
- batoolset/draw/shapes/square2d.py +103 -0
- batoolset/draw/shapes/textorientation.py +45 -0
- batoolset/draw/shapes/tools.py +467 -0
- batoolset/draw/shapes/transform2D.py +350 -0
- batoolset/draw/shapes/txt2d.py +550 -0
- batoolset/draw/widgets/__init__.py +0 -0
- batoolset/draw/widgets/col.py +343 -0
- batoolset/draw/widgets/image_group.py +248 -0
- batoolset/draw/widgets/image_organizer.py +96 -0
- batoolset/draw/widgets/paint.py +184 -0
- batoolset/draw/widgets/vectorial.py +257 -0
- batoolset/figure/__init__.py +0 -0
- batoolset/figure/alignment.py +814 -0
- batoolset/figure/column.py +1117 -0
- batoolset/figure/fig_tools.py +285 -0
- batoolset/figure/minimal_debugger_scale_etc.py +139 -0
- batoolset/figure/panel.py +697 -0
- batoolset/figure/row.py +852 -0
- batoolset/figure/user_selection.py +287 -0
- batoolset/files/__init__.py +0 -0
- batoolset/files/tools.py +1321 -0
- batoolset/images/__init__.py +0 -0
- batoolset/images/tools.py +81 -0
- batoolset/img.py +5216 -0
- batoolset/linux/__init__.py +0 -0
- batoolset/linux/tools.py +72 -0
- batoolset/lists/__init__.py +0 -0
- batoolset/lists/tools.py +436 -0
- batoolset/luts/__init__.py +0 -0
- batoolset/luts/lut_minimal_test.py +1207 -0
- batoolset/matplolib/__init__.py +0 -0
- batoolset/matplolib/tools.py +44 -0
- batoolset/np_tools/__init__.py +0 -0
- batoolset/np_tools/tools.py +252 -0
- batoolset/np_tools/trash.py +15 -0
- batoolset/pandas_tools/__init__.py +0 -0
- batoolset/pandas_tools/tools.py +880 -0
- batoolset/partials/__init__.py +0 -0
- batoolset/partials/tools.py +83 -0
- batoolset/plot_tools/__init__.py +0 -0
- batoolset/plot_tools/tools.py +70 -0
- batoolset/pyqt/__init__.py +0 -0
- batoolset/pyqt/tools.py +691 -0
- batoolset/re_tools/__init__.py +0 -0
- batoolset/re_tools/tools.py +35 -0
- batoolset/serialization/__init__.py +0 -0
- batoolset/serialization/tools.py +1192 -0
- batoolset/sets/__init__.py +0 -0
- batoolset/sets/tools.py +109 -0
- batoolset/settings/__init__.py +0 -0
- batoolset/settings/global_settings.py +134 -0
- batoolset/strings/__init__.py +0 -0
- batoolset/strings/tools.py +225 -0
- batoolset/ta/__init__.py +0 -0
- batoolset/ta/database/__init__.py +0 -0
- batoolset/ta/database/advanced_sql_plotter.py +1170 -0
- batoolset/ta/database/my_qt_table.py +79 -0
- batoolset/ta/database/preview_and_edit_sqlite_db.py +405 -0
- batoolset/ta/database/sql.py +2141 -0
- batoolset/ta/database/sql_column_name_dialog.py +122 -0
- batoolset/ta/measurements/TAmeasures.py +2226 -0
- batoolset/ta/measurements/__init__.py +0 -0
- batoolset/ta/measurements/measurements3D/__init__.py +0 -0
- batoolset/ta/measurements/measurements3D/get_point_on_surface_if_centroid_is_bad.py +175 -0
- batoolset/ta/measurements/measurements3D/height_map_to_projection.py +82 -0
- batoolset/ta/measurements/measurements3D/measures3D.py +208 -0
- batoolset/ta/measurements/measurements3D/triangulate.py +331 -0
- batoolset/ta/measurements/nematic.py +562 -0
- batoolset/ta/measurements/nematic_measurements.py +107 -0
- batoolset/ta/segmentation/__init__.py +0 -0
- batoolset/ta/segmentation/neo_wshed.py +314 -0
- batoolset/ta/selections/__init__.py +0 -0
- batoolset/ta/selections/selection.py +329 -0
- batoolset/ta/tracking/__init__.py +0 -0
- batoolset/ta/tracking/last_tracking_based_on_matching_or_on_translation_from_mermaid_warp.py +653 -0
- batoolset/ta/tracking/local_to_track_correspondance.py +138 -0
- batoolset/ta/tracking/rapid_detection_of_vertices.py +517 -0
- batoolset/ta/tracking/registration.py +108 -0
- batoolset/ta/tracking/swap_detector_and_fixer.py +296 -0
- batoolset/ta/tracking/track_correction.py +238 -0
- batoolset/ta/tracking/tracking_error_detector_and_fixer.py +3099 -0
- batoolset/ta/tracking/tracking_yet_another_approach_pyramidal_registration_n_neo_swapping_correction.py +725 -0
- batoolset/ta/utils/TA_tools.py +43 -0
- batoolset/ta/utils/__init__.py +0 -0
- batoolset/ta/utils/rps_tools.py +1783 -0
- batoolset/tests/__init__.py +0 -0
- batoolset/tests/rps_tools.py +51 -0
- batoolset/tests/tools.py +10 -0
- batoolset/tools/__init__.py +0 -0
- batoolset/tools/early_stopper_class.py +9 -0
- batoolset/tools/guided_data_recoverer.py +110 -0
- batoolset/tools/logger.py +100 -0
- batoolset/tools/mytimer.py +31 -0
- batoolset/tools/prompt_color.py +160 -0
- batoolset/tools/qthandler.py +118 -0
- batoolset/uitools/__init__.py +0 -0
- batoolset/uitools/blinker.py +56 -0
- batoolset/unsafe/__init__.py +0 -0
- batoolset/unsafe/tools.py +115 -0
- batoolset/utils/__init__.py +0 -0
- batoolset/utils/commontools.py +158 -0
- batoolset/utils/loadlist.py +728 -0
- batoolset/version.py +10 -0
- batoolset/xml/__init__.py +0 -0
- batoolset/xml/tools.py +65 -0
- batoolset/zip_tools/__init__.py +0 -0
- batoolset/zip_tools/tools.py +76 -0
- batoolset-0.1.0.dist-info/LICENSE +24 -0
- batoolset-0.1.0.dist-info/METADATA +45 -0
- batoolset-0.1.0.dist-info/RECORD +162 -0
- batoolset-0.1.0.dist-info/WHEEL +5 -0
- batoolset-0.1.0.dist-info/top_level.txt +1 -0
|
File without changes
|
batoolset/linux/tools.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess
|
|
3
|
+
import shutil
|
|
4
|
+
import traceback
|
|
5
|
+
|
|
6
|
+
from batoolset.files.tools import smart_name_parser
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def create_linux_desktop_shortcut(script_path, shortcut_name, shortcut_description="", icon_path="", store_in_application_folder=True):
|
|
10
|
+
# MEGA TODO --> improve the code --> if the icon already exists in the folder --> change its name or offer overwrite it or offer rename it and apply the change --> appart from that not so bad !!!
|
|
11
|
+
|
|
12
|
+
if not store_in_application_folder:
|
|
13
|
+
try:
|
|
14
|
+
desktop_folder_name = subprocess.check_output(["xdg-user-dir", "DESKTOP"], universal_newlines=True).strip()
|
|
15
|
+
except subprocess.CalledProcessError:
|
|
16
|
+
# Fallback to a default name if the command fails
|
|
17
|
+
desktop_folder_name = "Desktop"
|
|
18
|
+
# Fallback to a default name if the command fails
|
|
19
|
+
desktop_path = os.path.join(os.path.expanduser("~"), desktop_folder_name)
|
|
20
|
+
desktop_file_path = f"{desktop_path}/{shortcut_name}.desktop"
|
|
21
|
+
else:
|
|
22
|
+
desktop_file_path = f"{os.path.join(os.path.expanduser('~'),'.local/share/applications/')}/{shortcut_name}.desktop"
|
|
23
|
+
neo_icon_path=None
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
if icon_path is not None and icon_path and 'applications' in desktop_file_path:
|
|
27
|
+
neo_icon_path = smart_name_parser(desktop_file_path, 'parent') + '/icons'
|
|
28
|
+
neo_icon_path = os.path.join(neo_icon_path, smart_name_parser(icon_path, 'short'))
|
|
29
|
+
os.makedirs(os.path.dirname(neo_icon_path), exist_ok=True)
|
|
30
|
+
try:
|
|
31
|
+
if icon_path != neo_icon_path: # no need to duplicate the image if already there
|
|
32
|
+
shutil.copy2(icon_path, neo_icon_path)
|
|
33
|
+
except:
|
|
34
|
+
traceback.print_exc()
|
|
35
|
+
except:
|
|
36
|
+
traceback.print_exc()
|
|
37
|
+
|
|
38
|
+
content = f"""[Desktop Entry]
|
|
39
|
+
Version=1.0
|
|
40
|
+
Type=Application
|
|
41
|
+
Terminal=true
|
|
42
|
+
Exec={script_path}
|
|
43
|
+
Name={shortcut_name}
|
|
44
|
+
Comment={shortcut_description}
|
|
45
|
+
Icon={icon_path if neo_icon_path is None else neo_icon_path}
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
with open(desktop_file_path, "w") as desktop_file:
|
|
49
|
+
desktop_file.write(content)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
print(f"Desktop shortcut created at: {desktop_file_path}")
|
|
54
|
+
# move to application folder and run change stuff
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if __name__ == '__main__':
|
|
58
|
+
|
|
59
|
+
# TODO ADD 'sudo lshw -C display' --> command to show nvidia
|
|
60
|
+
# sudo ubuntu-drivers install ? https://www.cyberciti.biz/faq/ubuntu-linux-install-nvidia-driver-latest-proprietary-driver/
|
|
61
|
+
|
|
62
|
+
# Example usage:
|
|
63
|
+
script_path = "/home/aigouy/miniconda3/bin/python /home/aigouy/mon_prog/Python/epyseg_pkg/personal/hiC_microC_tmp/EVO_BLASTER_GUI.py"
|
|
64
|
+
shortcut_name = "EVO Blaster"
|
|
65
|
+
shortcut_description = "Runs local blast and identifies the most conserved gene in every species"
|
|
66
|
+
# icon_path = "/home/aigouy/Téléchargements/logo1.png"
|
|
67
|
+
icon_path = "/home/aigouy/.local/share/applications/icons/logo1.png"
|
|
68
|
+
|
|
69
|
+
#/home/aigouy/.local/share/applications/
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
create_linux_desktop_shortcut(script_path, shortcut_name, shortcut_description, icon_path)
|
|
File without changes
|
batoolset/lists/tools.py
ADDED
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
# contains a set of useful methods for list and list operations
|
|
2
|
+
import itertools
|
|
3
|
+
import itertools
|
|
4
|
+
import sys
|
|
5
|
+
from itertools import combinations
|
|
6
|
+
|
|
7
|
+
def compare_lists_sets(list1, list2):
|
|
8
|
+
return set(list1) == set(list2)
|
|
9
|
+
|
|
10
|
+
def divide_list_into_sublists(lst, num_rows, num_cols):
|
|
11
|
+
# Calculate the total number of elements
|
|
12
|
+
total_elements = num_rows * num_cols
|
|
13
|
+
|
|
14
|
+
# If the list has fewer elements than expected, add None to fill the gaps
|
|
15
|
+
if len(lst) < total_elements:
|
|
16
|
+
lst.extend([None] * (total_elements - len(lst)))
|
|
17
|
+
|
|
18
|
+
# Divide the list into sublists
|
|
19
|
+
sublists = [lst[i:i + num_cols] for i in range(0, total_elements, num_cols)]
|
|
20
|
+
|
|
21
|
+
return sublists
|
|
22
|
+
|
|
23
|
+
def bool_list_to_index_list(bool_list):
|
|
24
|
+
index_list = []
|
|
25
|
+
for i, val in enumerate(bool_list):
|
|
26
|
+
if val:
|
|
27
|
+
index_list.append(i)
|
|
28
|
+
return index_list
|
|
29
|
+
|
|
30
|
+
def is_iterable(obj):
|
|
31
|
+
try:
|
|
32
|
+
iter(obj)
|
|
33
|
+
return True
|
|
34
|
+
except TypeError:
|
|
35
|
+
return False
|
|
36
|
+
|
|
37
|
+
def combine_lists(list1, list2):
|
|
38
|
+
combined_list = [(item1, item2) for item1 in list1 for item2 in list2]
|
|
39
|
+
return combined_list
|
|
40
|
+
|
|
41
|
+
def flatten_iterable(iterable):
|
|
42
|
+
non_iterable_objects = []
|
|
43
|
+
|
|
44
|
+
for obj in iterable:
|
|
45
|
+
# If the object is not iterable, add it to the list of non-iterable objects
|
|
46
|
+
if not is_iterable(obj):
|
|
47
|
+
non_iterable_objects.append(obj)
|
|
48
|
+
# If the object is iterable, recursively call the function on the object
|
|
49
|
+
else:
|
|
50
|
+
non_iterable_objects.extend(flatten_iterable(obj))
|
|
51
|
+
|
|
52
|
+
return non_iterable_objects
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def find_first_object_of_type(obj_list, obj_type):
|
|
56
|
+
try:
|
|
57
|
+
# Find the first object of the given type in the list
|
|
58
|
+
obj = next(obj for obj in obj_list if isinstance(obj, obj_type))
|
|
59
|
+
return obj
|
|
60
|
+
except StopIteration:
|
|
61
|
+
# No object of the given type was found in the list
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def find_all_objects_of_type(obj_list, obj_type):
|
|
66
|
+
if not obj_list:
|
|
67
|
+
return None
|
|
68
|
+
# Find all the objects of the given type in the list
|
|
69
|
+
objects = [obj for obj in obj_list if isinstance(obj, obj_type)]
|
|
70
|
+
return objects
|
|
71
|
+
|
|
72
|
+
def find_first_index(element, my_list):
|
|
73
|
+
try:
|
|
74
|
+
# Find the index of the first occurrence of the element in the list
|
|
75
|
+
index = my_list.index(element)
|
|
76
|
+
return index
|
|
77
|
+
except ValueError:
|
|
78
|
+
# The element is not in the list
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
def get_list_combinatorial(lst, repack_all_to_lists_if_not_lists=True, return_list=True):
|
|
82
|
+
"""
|
|
83
|
+
Creates all possible combinations of the elements in a list.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
lst (list): The input list.
|
|
87
|
+
repack_all_to_lists_if_not_lists (bool): If True, converts non-list elements to lists.
|
|
88
|
+
return_list (bool): If True, returns the combinations as a list of lists.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
list: The list of all possible combinations.
|
|
92
|
+
|
|
93
|
+
Examples:
|
|
94
|
+
>>> lst = ['D', ['1P', 'hinge_undefined'], '1P']
|
|
95
|
+
>>> result = get_list_combinatorial(lst)
|
|
96
|
+
>>> print(result)
|
|
97
|
+
[['D', '1P', '1P'], ['D', 'hinge_undefined', '1P']]
|
|
98
|
+
"""
|
|
99
|
+
optimized_list = lst
|
|
100
|
+
|
|
101
|
+
if repack_all_to_lists_if_not_lists:
|
|
102
|
+
optimized_list = [[item] if not isinstance(item, list) else item for item in lst]
|
|
103
|
+
|
|
104
|
+
tmp = list(itertools.product(*optimized_list))
|
|
105
|
+
|
|
106
|
+
if return_list:
|
|
107
|
+
tmp = [list(el) for el in tmp]
|
|
108
|
+
|
|
109
|
+
return tmp
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def list_contains_sublist(lst):
|
|
113
|
+
"""
|
|
114
|
+
Checks if a list contains any sublists.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
lst (list): The input list.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
bool: True if the list contains sublists, False otherwise.
|
|
121
|
+
|
|
122
|
+
Examples:
|
|
123
|
+
>>> lst = ['a', 'b', ['c', 'd']]
|
|
124
|
+
>>> result = list_contains_sublist(lst)
|
|
125
|
+
>>> print(result)
|
|
126
|
+
True
|
|
127
|
+
"""
|
|
128
|
+
for el in lst:
|
|
129
|
+
if isinstance(el, list):
|
|
130
|
+
return True
|
|
131
|
+
|
|
132
|
+
return False
|
|
133
|
+
|
|
134
|
+
def get_consecutive_file_pairs(file_paths):
|
|
135
|
+
"""
|
|
136
|
+
Given a list of file paths, returns a list of tuples,
|
|
137
|
+
where each tuple contains the consecutive pair of file paths.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
file_paths (list): The list of file paths.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
list: The list of tuples containing consecutive file pairs.
|
|
144
|
+
|
|
145
|
+
Examples:
|
|
146
|
+
>>> file_paths = ['file1.txt', 'file2.txt', 'file3.txt']
|
|
147
|
+
>>> result = get_consecutive_file_pairs(file_paths)
|
|
148
|
+
>>> print(result)
|
|
149
|
+
[('file1.txt', 'file2.txt'), ('file2.txt', 'file3.txt')]
|
|
150
|
+
"""
|
|
151
|
+
return [(file_paths[i], file_paths[i+1]) for i in range(len(file_paths)-1)]
|
|
152
|
+
|
|
153
|
+
def flatten_list(input_list):
|
|
154
|
+
"""
|
|
155
|
+
Flattens a list containing nested tuples or other elements.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
input_list (list): The input list to be flattened.
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
list: A new list with nested elements flattened.
|
|
162
|
+
|
|
163
|
+
Examples:
|
|
164
|
+
>>> input_list = ['toto', 'tutu', ('bob', 'beb'), 'tata']
|
|
165
|
+
>>> flattened_list = flatten_list(input_list)
|
|
166
|
+
>>> print(flattened_list)
|
|
167
|
+
['toto', 'tutu', 'bob', 'beb', 'tata']
|
|
168
|
+
"""
|
|
169
|
+
# Flatten the list using a list comprehension
|
|
170
|
+
flattened_list = [item for sublist in input_list for item in (sublist if isinstance(sublist, (tuple, list)) else [sublist])]
|
|
171
|
+
return flattened_list
|
|
172
|
+
|
|
173
|
+
def create_all_possible_pairs(single_cutters):
|
|
174
|
+
"""
|
|
175
|
+
Create all possible pairs of keys from a dictionary of single-cut restriction enzymes.
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
single_cutters (dict): A dictionary where keys represent enzyme names and values
|
|
179
|
+
are associated information for single-cut restriction enzymes.
|
|
180
|
+
|
|
181
|
+
Returns:
|
|
182
|
+
list: A list of tuples containing all unique pairs of enzyme names from the dictionary.
|
|
183
|
+
|
|
184
|
+
Examples:
|
|
185
|
+
>>> single_cutters = {'EcoRI': {'site': 'GAATTC', 'recognition_site': 'G^AATTC', 'cut_site': 1},
|
|
186
|
+
... 'BamHI': {'site': 'GGATCC', 'recognition_site': 'G^GATCC', 'cut_site': 1}}
|
|
187
|
+
>>> pairs = create_all_possible_pairs(single_cutters)
|
|
188
|
+
>>> print(pairs)
|
|
189
|
+
[('EcoRI', 'BamHI')]
|
|
190
|
+
>>> single_cutters = ['EcoRI','BamHI']
|
|
191
|
+
>>> pairs = create_all_possible_pairs(single_cutters)
|
|
192
|
+
>>> print(pairs)
|
|
193
|
+
[('EcoRI', 'BamHI')]
|
|
194
|
+
"""
|
|
195
|
+
if isinstance(single_cutters, dict):
|
|
196
|
+
single_cutters =single_cutters.keys()
|
|
197
|
+
key_pairs = [pair for pair in combinations(single_cutters, 2)]
|
|
198
|
+
return key_pairs
|
|
199
|
+
|
|
200
|
+
def swap_items(lst, index1, index2):
|
|
201
|
+
# Check if the indices are valid
|
|
202
|
+
if index1 < 0 or index1 >= len(lst) or index2 < 0 or index2 >= len(lst):
|
|
203
|
+
print("Invalid indices")
|
|
204
|
+
return
|
|
205
|
+
|
|
206
|
+
print('before swapping', lst)
|
|
207
|
+
# Swap the items
|
|
208
|
+
temp = lst[index1]
|
|
209
|
+
lst[index1] = lst[index2]
|
|
210
|
+
lst[index2] = temp
|
|
211
|
+
|
|
212
|
+
print("Swapped items: ", lst)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
# def move_left(lst, indices, distance):
|
|
216
|
+
# # Create a copy of the list
|
|
217
|
+
# lst = lst[:]
|
|
218
|
+
#
|
|
219
|
+
# # Sort the indices in descending order
|
|
220
|
+
# indices = sorted(indices, reverse=True)
|
|
221
|
+
#
|
|
222
|
+
# # Move each element to the left by the given distance
|
|
223
|
+
# for index in indices:
|
|
224
|
+
# element = lst.pop(index)
|
|
225
|
+
# lst.insert(index - distance, element)
|
|
226
|
+
#
|
|
227
|
+
# return lst
|
|
228
|
+
|
|
229
|
+
# def move_left(lst, indices, distance):
|
|
230
|
+
# # Create a copy of the list
|
|
231
|
+
# lst = lst[:]
|
|
232
|
+
#
|
|
233
|
+
# # Sort the indices in descending order
|
|
234
|
+
# indices = sorted(indices, reverse=True)
|
|
235
|
+
#
|
|
236
|
+
# # Move each element to the left by the given distance
|
|
237
|
+
# for index in indices:
|
|
238
|
+
# element = lst.pop(index)
|
|
239
|
+
# lst.insert((index - distance) % len(lst), element)
|
|
240
|
+
#
|
|
241
|
+
# return lst
|
|
242
|
+
# def move_left(lst, indices, distance):
|
|
243
|
+
# """
|
|
244
|
+
# Moves the elements at the specified indices to the left by a given distance in the list.
|
|
245
|
+
# Returns a new list with the elements moved.
|
|
246
|
+
# """
|
|
247
|
+
# new_lst = lst[:] # Make a copy of the original list
|
|
248
|
+
# indices = sorted(indices, reverse=True) # Sort indices in descending order
|
|
249
|
+
#
|
|
250
|
+
# for idx in indices:
|
|
251
|
+
# if idx < distance:
|
|
252
|
+
# continue # Skip if the index is smaller than the distance
|
|
253
|
+
#
|
|
254
|
+
# elem = new_lst.pop(idx) # Remove the element at the index
|
|
255
|
+
# new_lst.insert(idx - distance, elem) # Insert the element at the new position
|
|
256
|
+
#
|
|
257
|
+
# return new_lst
|
|
258
|
+
def move_left(lst, indices, distance=1):
|
|
259
|
+
"""
|
|
260
|
+
Moves the elements at the specified indices to the left by a given distance in the list.
|
|
261
|
+
Returns a new list with the elements moved.
|
|
262
|
+
"""
|
|
263
|
+
new_lst = lst[:] # Make a copy of the original list
|
|
264
|
+
indices = sorted(indices) # Sort indices in ascending order
|
|
265
|
+
|
|
266
|
+
for idx in indices:
|
|
267
|
+
if idx < distance:
|
|
268
|
+
new_lst.insert(0, new_lst.pop(idx)) # Move element to the front
|
|
269
|
+
else:
|
|
270
|
+
elem = new_lst.pop(idx)
|
|
271
|
+
new_lst.insert(idx - distance, elem)
|
|
272
|
+
|
|
273
|
+
return new_lst
|
|
274
|
+
|
|
275
|
+
def move_right(lst, indices, distance=1):
|
|
276
|
+
"""
|
|
277
|
+
Moves the elements at the specified indices to the right by a given distance in the list.
|
|
278
|
+
Returns a new list with the elements moved.
|
|
279
|
+
"""
|
|
280
|
+
new_lst = lst[:] # Make a copy of the original list
|
|
281
|
+
indices = sorted(indices, reverse=True) # Sort indices in descending order
|
|
282
|
+
|
|
283
|
+
for idx in indices:
|
|
284
|
+
if idx + distance >= len(new_lst):
|
|
285
|
+
elem = new_lst.pop(idx)
|
|
286
|
+
new_lst.append(elem) # Move element to the end
|
|
287
|
+
else:
|
|
288
|
+
elem = new_lst.pop(idx)
|
|
289
|
+
new_lst.insert(idx + distance, elem)
|
|
290
|
+
|
|
291
|
+
return new_lst
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
# that is the best I have so far
|
|
295
|
+
# def move_up(items, selected_indices):
|
|
296
|
+
# # Sort selected indices in descending order to prevent interference with previous movements
|
|
297
|
+
# selected_indices.sort(reverse=True)
|
|
298
|
+
# for index in selected_indices:
|
|
299
|
+
# if index > 0:
|
|
300
|
+
# # Swap the item at the current index with the item above it
|
|
301
|
+
# items[index], items[index - 1] = items[index - 1], items[index]
|
|
302
|
+
#
|
|
303
|
+
# def move_down(items, selected_indices):
|
|
304
|
+
# # Sort selected indices in ascending order to prevent interference with previous movements
|
|
305
|
+
# selected_indices.sort()
|
|
306
|
+
# for index in selected_indices:
|
|
307
|
+
# if index < len(items) - 1:
|
|
308
|
+
# # Swap the item at the current index with the item below it
|
|
309
|
+
# items[index], items[index + 1] = items[index + 1], items[index]
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
# def move_right(lst, indices, distance):
|
|
313
|
+
# """
|
|
314
|
+
# Moves the elements at the specified indices to the right by a given distance in the list.
|
|
315
|
+
# Returns a new list with the elements moved.
|
|
316
|
+
# """
|
|
317
|
+
# new_lst = lst[:] # Make a copy of the original list
|
|
318
|
+
# indices = sorted(indices, reverse=True) # Sort indices in descending order
|
|
319
|
+
#
|
|
320
|
+
# # Keep track of the new index of each element as it is moved
|
|
321
|
+
# new_indices = []
|
|
322
|
+
#
|
|
323
|
+
# for idx in indices:
|
|
324
|
+
# if new_indices:
|
|
325
|
+
# # Adjust the distance for subsequent elements based on the new index of the previous element
|
|
326
|
+
# last_new_idx = new_indices[-1]
|
|
327
|
+
# if last_new_idx + 1 < len(new_lst):
|
|
328
|
+
# distance = min(distance, last_new_idx + 1 - idx)
|
|
329
|
+
# else:
|
|
330
|
+
# distance = 0
|
|
331
|
+
#
|
|
332
|
+
# if idx + distance >= len(new_lst):
|
|
333
|
+
# elem = new_lst.pop(idx)
|
|
334
|
+
# new_lst.append(elem) # Move element to the end
|
|
335
|
+
# new_indices.append(len(new_lst) - 1)
|
|
336
|
+
# else:
|
|
337
|
+
# elem = new_lst.pop(idx)
|
|
338
|
+
# new_lst.insert(idx + distance, elem)
|
|
339
|
+
# new_indices.append(idx + distance)
|
|
340
|
+
#
|
|
341
|
+
# return new_lst
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
# def move_left(lst, indices, distance):
|
|
346
|
+
# """
|
|
347
|
+
# Moves the elements at the specified indices to the left by a given distance in the list.
|
|
348
|
+
# Preserves the original order of the elements being moved.
|
|
349
|
+
# Returns a new list with the elements moved.
|
|
350
|
+
# """
|
|
351
|
+
# new_lst = lst[:] # Make a copy of the original list
|
|
352
|
+
# indices = sorted(indices) # Sort indices in ascending order
|
|
353
|
+
#
|
|
354
|
+
# moved_elems = [] # Store the elements being moved
|
|
355
|
+
# for idx in indices:
|
|
356
|
+
# elem = new_lst.pop(idx)
|
|
357
|
+
# if idx < len(lst) - distance:
|
|
358
|
+
# moved_elems.append(elem)
|
|
359
|
+
# else:
|
|
360
|
+
# new_lst.insert(idx - distance, elem)
|
|
361
|
+
#
|
|
362
|
+
# # Insert the moved elements at the beginning of the list
|
|
363
|
+
# new_lst[:0] = moved_elems
|
|
364
|
+
#
|
|
365
|
+
# return new_lst
|
|
366
|
+
# def move_items_by_distance(data, indices, distance, direction="up"):
|
|
367
|
+
# temp_list = [data[i] for i in indices]
|
|
368
|
+
# for i in sorted(indices, reverse=True):
|
|
369
|
+
# del data[i]
|
|
370
|
+
#
|
|
371
|
+
# if direction == "up":
|
|
372
|
+
# target_index = min(indices) - distance
|
|
373
|
+
# else: # direction == "down"
|
|
374
|
+
# target_index = max(indices) + distance + 1
|
|
375
|
+
#
|
|
376
|
+
# # Ensure target_index is within list bounds
|
|
377
|
+
# target_index = max(0, min(target_index, len(data)))
|
|
378
|
+
#
|
|
379
|
+
# data[target_index:target_index] = temp_list
|
|
380
|
+
|
|
381
|
+
if __name__ == '__main__':
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
if True:
|
|
385
|
+
# Define a list
|
|
386
|
+
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
387
|
+
|
|
388
|
+
# Define the number of rows and columns
|
|
389
|
+
num_rows = 3
|
|
390
|
+
num_cols = 3
|
|
391
|
+
|
|
392
|
+
# Divide the list into sublists
|
|
393
|
+
sublists = divide_list_into_sublists(lst, num_rows, num_cols)
|
|
394
|
+
|
|
395
|
+
# Print the sublists
|
|
396
|
+
for sublist in sublists:
|
|
397
|
+
print(sublist)
|
|
398
|
+
|
|
399
|
+
sys.exit(0)
|
|
400
|
+
|
|
401
|
+
if True:
|
|
402
|
+
# Example usage
|
|
403
|
+
lst = [0, 1, 2, 3, 4, 5, 6, 7]
|
|
404
|
+
indices = [1, 6]
|
|
405
|
+
distance = 5
|
|
406
|
+
print(move_left(lst, indices, distance)) # Output: [1, 0, 2, 3, 4, 6, 5, 7]
|
|
407
|
+
|
|
408
|
+
lst = [0, 1, 2, 3, 4, 5, 6, 7, 8]
|
|
409
|
+
indices = [1, 5, 6]
|
|
410
|
+
distance = 10
|
|
411
|
+
|
|
412
|
+
new_lst = move_right(lst, indices, distance)
|
|
413
|
+
print(new_lst) # Output: [0, 2, 3, 1, 4, 5, 7, 6]
|
|
414
|
+
|
|
415
|
+
# # Example usage:
|
|
416
|
+
# my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8] #['a', 'b', 'c', 'd', 'e', 'f']
|
|
417
|
+
# indices_to_move = [1, 3, 5] # Move 'b', 'd', and 'f'
|
|
418
|
+
#
|
|
419
|
+
# move_items_by_distance(my_list, indices_to_move,1, direction="up")
|
|
420
|
+
# print(my_list) # Output: ['a', 'c', 'e', 'b', 'd', 'f']
|
|
421
|
+
|
|
422
|
+
sys.exit(0)
|
|
423
|
+
|
|
424
|
+
if True:
|
|
425
|
+
import os
|
|
426
|
+
|
|
427
|
+
# list of file paths as strings
|
|
428
|
+
file_paths = ["/path/to/file1.txt", "/path/to/file2.txt", "/path/to/file3.txt"]
|
|
429
|
+
|
|
430
|
+
print(get_consecutive_file_pairs(file_paths))
|
|
431
|
+
|
|
432
|
+
test = ['D', ['1P', 'hinge_undefined'], '1P']
|
|
433
|
+
print(list_contains_sublist(test)) # True
|
|
434
|
+
combi = get_list_combinatorial(test)
|
|
435
|
+
print(combi) # [['D', '1P', '1P'], ['D', 'hinge_undefined', '1P']]
|
|
436
|
+
print(list_contains_sublist(combi[0])) # False
|
|
File without changes
|