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

TypeError: cannot convert the series to <class 'int'> #26

Open
inspirewind opened this issue Sep 29, 2024 · 2 comments
Open

TypeError: cannot convert the series to <class 'int'> #26

inspirewind opened this issue Sep 29, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@inspirewind
Copy link

MeSS version
mess 0.9.0 pyhdfd78af_0 bioconda
Describe the bug
[Sun Sep 29 14:55:46 2024]
Finished job 7.
11 of 19 steps (58%) done
InputFunctionException in rule art_illumina in file /home/inspirewind/miniconda3/envs/mess/lib/python3.12/site-packages/mess/workflow/rules/simulate/short_reads.smk, line 38:
Error:
TypeError: cannot convert the series to <class 'int'>
Wildcards:
sample=sample
fasta=GCF_016127215.1
contig=NZ_CP065991.1
Traceback:
File "/home/inspirewind/miniconda3/envs/mess/lib/python3.12/site-packages/mess/workflow/rules/simulate/short_reads.smk", line 49, in
File "/home/inspirewind/miniconda3/envs/mess/lib/python3.12/site-packages/pandas/core/series.py", line 248, in wrapper (rule art_illumina, line 38, /home/inspirewind/miniconda3/envs/mess/lib/python3.12/site-packages/mess/workflow/rules/simulate/short_reads.smk)

Minimal example

Additional context

@inspirewind
Copy link
Author

Based on the get_value function and the content of the CSV file, it appears that val is returning a Series because the same samplename and contig correspond to multiple seed and cov_sim values in the CSV.

To ensure a scalar value is returned, we can add logic to handle this situation in the get_value function. For example, if val is a Series, choose to return the first value or handle it in another way. Modify get_value as follows:

def get_value(table, wildcards, value):
    if table not in table_cache:
        df = pd.read_csv(
            table,
            sep="\t",
            index_col=["samplename", "fasta", "contig"],
        )
        table_cache[table] = df
    df = table_cache[table]
    val = df.loc[wildcards.sample].loc[wildcards.fasta].loc[wildcards.contig][value]

    print(f"[debug]: table: {table}")
    print(f"[debug]: df: {df}")
    print(f"[debug]: val: {val}")

    if isinstance(val, pd.Series):
        return val.iloc[0] 
    return val

@farchaab
Copy link
Collaborator

Hello @inspirewind, and thank you for using MeSS !

Can you provide an example input file under the minimal example section, so we can reproduce the bug and fix it ?

On a side note, I encountered a similar bug and fixed with this commit. However, I did not make a release, so the fix is not live on bioconda yet !

Could you try to install mess from source (see installation) and let me know if it fixed your error ?

@farchaab farchaab self-assigned this Sep 30, 2024
@farchaab farchaab added the bug Something isn't working label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants