AttributeError: 'Seq' object has no attribute 'replace'

While I was running
strainphlan -s consensus_markers/*.pkl -m db_markers/t__SGB8047.fna -o output -n 8 -c t__SGB8047 --mutation_rates, I faced the error.

Traceback (most recent call last):
File “/data/workdir/huwa/software/miniconda3/envs/mpa4/bin/strainphlan”, line 10, in
sys.exit(main())
File “/data/workdir/huwa/software/miniconda3/envs/mpa4/lib/python3.7/site-packages/metaphlan/strainphlan.py”, line 621, in main
strainphlan_runner.run_strainphlan()
File “/data/workdir/huwa/software/miniconda3/envs/mpa4/lib/python3.7/site-packages/metaphlan/strainphlan.py”, line 463, in run_strainphlan
self.cleaned_clade_markers_to_fasta()
File “/data/workdir/huwa/software/miniconda3/envs/mpa4/lib/python3.7/site-packages/metaphlan/strainphlan.py”, line 218, in cleaned_clade_markers_to_fasta
self.trim_sequences), marker_fna, ‘fasta’)
File “/data/workdir/huwa/software/miniconda3/envs/mpa4/lib/python3.7/site-packages/metaphlan/utils/consensus_markers.py”, line 35, in get_sequence
return SeqRecord(Seq(self.sequence[trim_sequences:-trim_sequences].replace(“*”, “-”).replace(‘-’, ‘N’)), id=marker_name, description=marker_name)
AttributeError: ‘Seq’ object has no attribute ‘replace’

I will appreciate if you can answer me soon. Thanks

1 Like

I also have the same error:
Thu Feb 16 10:06:01 2023: Start StrainPhlAn 4.0.3 execution
Thu Feb 16 10:06:01 2023: Creating temporary directory…
Thu Feb 16 10:06:01 2023: Done.
Thu Feb 16 10:06:01 2023: Filtering markers and samples…
Thu Feb 16 10:06:01 2023: Getting markers from main samples…
Thu Feb 16 10:06:55 2023: Done.
Thu Feb 16 10:06:55 2023: Getting markers from main references…
Thu Feb 16 10:06:56 2023: Done.
Thu Feb 16 10:06:56 2023: Removing bad markers / samples…
Thu Feb 16 10:06:56 2023: Done.
Thu Feb 16 10:06:56 2023: Getting markers from secondary samples and references…
Thu Feb 16 10:06:56 2023: Done.
Thu Feb 16 10:06:56 2023: Done.
Thu Feb 16 10:06:56 2023: Writing samples as markers’ FASTA files…
Thu Feb 16 10:06:56 2023: Done.
Thu Feb 16 10:06:56 2023: Writing filtered clade markers as FASTA file…
Traceback (most recent call last):
File “/scratch/msarhan/snakemake_wf/.snakemake/conda/800674343f06c7b0df4d950a08666634_/bin/strainphlan”, line 10, in
sys.exit(main())
File “/scratch/msarhan/snakemake_wf/.snakemake/conda/800674343f06c7b0df4d950a08666634_/lib/python3.9/site-packages/metaphlan/strainphlan.py”, line 621, in main
strainphlan_runner.run_strainphlan()
File “/scratch/msarhan/snakemake_wf/.snakemake/conda/800674343f06c7b0df4d950a08666634_/lib/python3.9/site-packages/metaphlan/strainphlan.py”, line 463, in run_strainphlan
self.cleaned_clade_markers_to_fasta()
File “/scratch/msarhan/snakemake_wf/.snakemake/conda/800674343f06c7b0df4d950a08666634_/lib/python3.9/site-packages/metaphlan/strainphlan.py”, line 217, in cleaned_clade_markers_to_fasta
SeqIO.write(marker.get_sequence(
File “/scratch/msarhan/snakemake_wf/.snakemake/conda/800674343f06c7b0df4d950a08666634_/lib/python3.9/site-packages/metaphlan/utils/consensus_markers.py”, line 35, in get_sequence
return SeqRecord(Seq(self.sequence[trim_sequences:-trim_sequences].replace(“*”, “-”).replace(‘-’, ‘N’)), id=marker_name, description=marker_name)
AttributeError: ‘Seq’ object has no attribute ‘replace’

I tried to solve this issue for the moment by defining the sequence as string to do the replacement of the gaps in consensus_markers.py file, like this:
Line 35:

return SeqRecord(Seq(str(self.sequence[trim_sequences:-trim_sequences]).replace(“*”, “-”).replace(‘-’, ‘N’)), id=marker_name, description=marker_name)

But also had to do the same to the phylophlan.py, like this:
Line 2928:

AlignIO.write(MultipleSeqAlignment([SeqRecord(Seq(str(aln.seq).replace(‘N’, ‘-’)), id=aln.id, description=‘’)

Like this, the phylogenies were generated successfully

1 Like

I will try, thanks for your help

I have solved this, maybe what I tried before put the inconsistent error away :smiley: