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

Refactor the core visualise function #159

Open
AntonPetrov opened this issue Nov 15, 2024 · 0 comments
Open

Refactor the core visualise function #159

AntonPetrov opened this issue Nov 15, 2024 · 0 comments
Assignees

Comments

@AntonPetrov
Copy link
Member

I will work on refactoring the visualise function in core.py to break it up in smaller functions and improve the way temporary files are managed.

Here is some starter code generated by GitHub Copilot that streamlines tempfile management:

from dataclasses import dataclass

@dataclass
class TempFiles:
    filename_template: str

    def __post_init__(self):
        suffixes = [
            "fasta", "sto", "depaired", "stk", "stk_original", "sto_unfiltered",
            "seed_list", "post_prob", "pfam_stk", "pfam_stk_original", "afa",
            "afa_original", "map"
        ]
        for suffix in suffixes:
            setattr(self, suffix, self.generate_filename(suffix))

    def generate_filename(self, suffix: str) -> str:
        return self.filename_template.replace("type", suffix)

# Example usage
if not os.path.exists(output_folder):
    os.makedirs(output_folder)
filename_template = os.path.join(output_folder, f"{seq_id.replace('/', '_')}_type.txt")
temp_files = TempFiles(filename_template)

# Access the temporary file paths using dot syntax
temp_fasta = temp_files.fasta
temp_sto = temp_files.sto
temp_depaired = temp_files.depaired
temp_stk = temp_files.stk
temp_stk_original = temp_files.stk_original
temp_sto_unfiltered = temp_files.sto_unfiltered
temp_acc_list = temp_files.seed_list
temp_post_prob = temp_files.post_prob
temp_pfam_stk = temp_files.pfam_stk
temp_pfam_stk_original = temp_files.pfam_stk_original
temp_afa = temp_files.afa
temp_afa_original = temp_files.afa_original
temp_map = temp_files.map

# Example usage: print all temporary file paths
print(temp_files)

# get sequence from fasta file
seq_range = f"-c {start}..{end}" if start and end else ""
if not os.path.exists(f"{fasta_input}.ssi"):
    runner.run(f"esl-sfetch --index {fasta_input}")
cmd = f"esl-sfetch {seq_range} {fasta_input} {seq_id} > {temp_fasta}"
result = runner.run(cmd)
@AntonPetrov AntonPetrov self-assigned this Nov 15, 2024
@github-project-automation github-project-automation bot moved this to Backlog in R2DT Issues Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant