Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache manual entries to blech_exp_info #300

Open
abuzarmahmood opened this issue Jan 8, 2025 · 3 comments
Open

cache manual entries to blech_exp_info #300

abuzarmahmood opened this issue Jan 8, 2025 · 3 comments

Comments

@abuzarmahmood
Copy link
Member

No description provided.

@abuzarmahmood
Copy link
Member Author

To address the issue of caching manual entries in the blech_exp_info.py file of the katzlabbrandeis/blech_clust repository, the following suggestions and changes were made:

  1. Add a Cache File: Create a JSON file to store cached entries. This file will be used to save and retrieve manual entries.

  2. Modify the Code to Use Cache: Update the code to check for existing entries in the cache before asking for manual input. If an entry is found, use it; otherwise, proceed with the manual input and update the cache.

Here is a concrete example of how these changes can be implemented:

Step 1: Define Cache File Path

Add a variable to define the path to the cache file.

cache_file_path = os.path.join(dir_path, 'manual_entries_cache.json')

Step 2: Load Cache

Load the cache at the beginning of the script.

if os.path.exists(cache_file_path):
    with open(cache_file_path, 'r') as cache_file:
        cache = json.load(cache_file)
else:
    cache = {}

Step 3: Update Manual Entry Sections

Modify sections where manual entries are made to check the cache first. For example, in the section where taste dig-ins are entered:

# Check cache for taste dig-ins
if 'taste_dig_ins' in cache:
    taste_dig_inds = cache['taste_dig_ins']
else:
    if not args.programmatic:
        taste_dig_in_str, continue_bool = entry_checker(
            msg=' INDEX of Taste dig_ins used (IN ORDER, anything separated) :: ',
            check_func=count_check,
            fail_response='Please enter integers only')
        if continue_bool:
            nums = re.findall('[0-9]+', taste_dig_in_str)
            taste_dig_inds = [int(x) for x in nums]
            # Update cache
            cache['taste_dig_ins'] = taste_dig_inds
            with open(cache_file_path, 'w') as cache_file:
                json.dump(cache, cache_file)
        else:
            exit()
    else:
        if args.taste_digins:
            taste_dig_inds = parse_csv(args.taste_digins, int)
        else:
            raise ValueError('Taste dig-ins not provided, use --taste-digins')

Step 4: Repeat for Other Manual Entries

Repeat the above pattern for other manual entries like tastes, concentrations, palatability rankings, laser parameters, etc.

By implementing these changes, manual entries can be efficiently cached, reducing the need for repeated manual input.


This response was automatically generated by blech_bot

@abuzarmahmood
Copy link
Member Author

abuzarmahmood commented Mar 5, 2025

Store cache in blech_clust/cache_and_logs...rather than the data_dir

@abuzarmahmood
Copy link
Member Author

To address the feedback regarding storing the cache in blech_clust/cache_and_logs rather than the data_dir, you can make the following modifications to the blech_exp_info.py file:

Step 1: Define Cache Directory Path

First, ensure that the cache directory exists and define the path to the cache file within this directory.

# Define the cache directory and ensure it exists
cache_dir = os.path.join('blech_clust', 'cache_and_logs')
os.makedirs(cache_dir, exist_ok=True)

# Define the cache file path
cache_file_path = os.path.join(cache_dir, 'manual_entries_cache.json')

Step 2: Update Cache Loading and Saving

Ensure that the cache is loaded from and saved to the new cache file path.

Load Cache

if os.path.exists(cache_file_path):
    with open(cache_file_path, 'r') as cache_file:
        cache = json.load(cache_file)
else:
    cache = {}

Save Cache

When updating the cache, save it to the new location:

# Update cache
cache['taste_dig_ins'] = taste_dig_inds
with open(cache_file_path, 'w') as cache_file:
    json.dump(cache, cache_file)

Step 3: Apply Changes to Other Manual Entries

Repeat the pattern of checking and updating the cache for other manual entries like tastes, concentrations, palatability rankings, laser parameters, etc., using the new cache file path.

By implementing these changes, the cache will be stored in the specified blech_clust/cache_and_logs directory, aligning with the user's feedback. This approach ensures that the cache is organized and separated from the data directory.


This response was automatically generated by blech_bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant