spacr 0.3.35__py3-none-any.whl → 0.3.36__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.
spacr/utils.py CHANGED
@@ -5045,14 +5045,15 @@ def generate_cytoplasm_mask(nucleus_mask, cell_mask):
5045
5045
 
5046
5046
  def add_column_to_database(settings):
5047
5047
  """
5048
- Updates a column in the database by matching on a common column from the DataFrame.
5049
-
5048
+ Adds a new column to the database table by matching on a common column from the DataFrame.
5049
+ If the column already exists in the database, it adds the column with a suffix.
5050
+
5050
5051
  Parameters:
5051
5052
  - settings: A dictionary containing the following keys:
5052
5053
  - 'csv_path': Path to the CSV file with the data to be added.
5053
5054
  - 'db_path': Path to the SQLite database (or connection string for other databases).
5054
5055
  - 'table_name': The name of the table in the database.
5055
- - 'update_column': The column to update in the database.
5056
+ - 'update_column': The name of the new column in the DataFrame to add to the database.
5056
5057
  - 'match_column': The common column used to match rows.
5057
5058
  """
5058
5059
 
@@ -5063,7 +5064,28 @@ def add_column_to_database(settings):
5063
5064
  conn = sqlite3.connect(settings['db_path'])
5064
5065
  cursor = conn.cursor()
5065
5066
 
5066
- # Iterate over the DataFrame and update the database
5067
+ # Get the existing columns in the database table
5068
+ cursor.execute(f"PRAGMA table_info({settings['table_name']})")
5069
+ columns_in_db = [col[1] for col in cursor.fetchall()]
5070
+
5071
+ # Check if the update column already exists in the database
5072
+ if settings['update_column'] in columns_in_db:
5073
+ # Add a suffix to the column name (e.g., '_new', '_1', or similar)
5074
+ suffix = 1
5075
+ new_column_name = f"{settings['update_column']}_{suffix}"
5076
+ # Ensure uniqueness by incrementing the suffix if needed
5077
+ while new_column_name in columns_in_db:
5078
+ suffix += 1
5079
+ new_column_name = f"{settings['update_column']}_{suffix}"
5080
+ print(f"Column '{settings['update_column']}' already exists. Using new column name: '{new_column_name}'")
5081
+ else:
5082
+ new_column_name = settings['update_column']
5083
+
5084
+ # Add the new column to the database table
5085
+ cursor.execute(f"ALTER TABLE {settings['table_name']} ADD COLUMN {new_column_name} TEXT")
5086
+ print(f"Added new column '{new_column_name}' to the table '{settings['table_name']}'.")
5087
+
5088
+ # Iterate over the DataFrame and update the new column in the database
5067
5089
  for index, row in df.iterrows():
5068
5090
  value_to_update = row[settings['update_column']]
5069
5091
  match_value = row[settings['match_column']]
@@ -5071,7 +5093,7 @@ def add_column_to_database(settings):
5071
5093
  # Prepare and execute the SQL update query
5072
5094
  query = f"""
5073
5095
  UPDATE {settings['table_name']}
5074
- SET {settings['update_column']} = ?
5096
+ SET {new_column_name} = ?
5075
5097
  WHERE {settings['match_column']} = ?
5076
5098
  """
5077
5099
  cursor.execute(query, (value_to_update, match_value))
@@ -5080,6 +5102,7 @@ def add_column_to_database(settings):
5080
5102
  conn.commit()
5081
5103
  conn.close()
5082
5104
 
5083
- print(f"Updated '{settings['update_column']}' in '{settings['table_name']}' using '{settings['match_column']}'.")
5105
+ print(f"Updated '{new_column_name}' in '{settings['table_name']}' using '{settings['match_column']}'.")
5106
+
5084
5107
 
5085
5108
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spacr
3
- Version: 0.3.35
3
+ Version: 0.3.36
4
4
  Summary: Spatial phenotype analysis of crisp screens (SpaCr)
5
5
  Home-page: https://github.com/EinarOlafsson/spacr
6
6
  Author: Einar Birnir Olafsson
@@ -27,7 +27,7 @@ spacr/sim.py,sha256=1xKhXimNU3ukzIw-3l9cF3Znc_brW8h20yv8fSTzvss,71173
27
27
  spacr/submodules.py,sha256=AB7s6-cULsaqz-haAaCtXfGEIi8uPZGT4xoCslUJC3Y,18391
28
28
  spacr/timelapse.py,sha256=FSYpUtAVy6xc3lwprRYgyDTT9ysUhfRQ4zrP9_h2mvg,39465
29
29
  spacr/toxo.py,sha256=us3pQyULtMTyfTq0MWPn4QJTTmQ6BwAJKChNf75jo3I,10082
30
- spacr/utils.py,sha256=hqxgN3tZTUyYvntaDc7tCRxgqlST0suAtkV3HYfbOO4,214847
30
+ spacr/utils.py,sha256=iCbweRXWjJgKGbp8DAVC20xUG9nwy2K9cvIsXORAKwA,216043
31
31
  spacr/version.py,sha256=axH5tnGwtgSnJHb5IDhiu4Zjk5GhLyAEDRe-rnaoFOA,409
32
32
  spacr/resources/MEDIAR/.gitignore,sha256=Ff1q9Nme14JUd-4Q3jZ65aeQ5X4uttptssVDgBVHYo8,152
33
33
  spacr/resources/MEDIAR/LICENSE,sha256=yEj_TRDLUfDpHDNM0StALXIt6mLqSgaV2hcCwa6_TcY,1065
@@ -150,9 +150,9 @@ spacr/resources/icons/umap.png,sha256=dOLF3DeLYy9k0nkUybiZMe1wzHQwLJFRmgccppw-8b
150
150
  spacr/resources/images/plate1_E01_T0001F001L01A01Z01C02.tif,sha256=Tl0ZUfZ_AYAbu0up_nO0tPRtF1BxXhWQ3T3pURBCCRo,7958528
151
151
  spacr/resources/images/plate1_E01_T0001F001L01A02Z01C01.tif,sha256=m8N-V71rA1TT4dFlENNg8s0Q0YEXXs8slIn7yObmZJQ,7958528
152
152
  spacr/resources/images/plate1_E01_T0001F001L01A03Z01C03.tif,sha256=Pbhk7xn-KUP6RSIhJsxQcrHFImBm3GEpLkzx7WOc-5M,7958528
153
- spacr-0.3.35.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
154
- spacr-0.3.35.dist-info/METADATA,sha256=xBdKUQpQuuru72Lgt9dirwo_Of5GdAwOKqs7bH7Sd0k,5949
155
- spacr-0.3.35.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
156
- spacr-0.3.35.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
157
- spacr-0.3.35.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
158
- spacr-0.3.35.dist-info/RECORD,,
153
+ spacr-0.3.36.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
154
+ spacr-0.3.36.dist-info/METADATA,sha256=NvcSKD3mIWOPeTDAAbugslvW-1_T0Dzd9k8WzSVNwbY,5949
155
+ spacr-0.3.36.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
156
+ spacr-0.3.36.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
157
+ spacr-0.3.36.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
158
+ spacr-0.3.36.dist-info/RECORD,,
File without changes