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

**URL:** <https://forum.biobakery.org/t/attributeerror-seq-object-has-no-attribute-replace/4798>\
**Category:** StrainPhlAn\
**Created:** [February 14, 2023, 9:00am UTC](https://forum.biobakery.org/t/attributeerror-seq-object-has-no-attribute-replace/4798 "2023-02-14T09:00:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![StickHu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/stickhu/32/1951_2.png) [@StickHu](https://forum.biobakery.org/u/StickHu)\
**Post date:** [February 14, 2023, 9:00am UTC](https://forum.biobakery.org/t/attributeerror-seq-object-has-no-attribute-replace/4798/1 "2023-02-14T09:00:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sabry](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/sabry/32/1962_2.png) [@Sabry](https://forum.biobakery.org/u/Sabry)\
**Post date:** [February 16, 2023, 9:27am UTC](https://forum.biobakery.org/t/attributeerror-seq-object-has-no-attribute-replace/4798/2 "2023-02-16T09:27:02Z")

</div>

> [@StickHu](#):
>
> AttributeError: ‘Seq’ object has no attribute ‘replace’

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’

---

<div class="post-metadata">

**Author:** ![Sabry](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/sabry/32/1962_2.png) [@Sabry](https://forum.biobakery.org/u/Sabry)\
**Post date:** [February 16, 2023, 12:24pm UTC](https://forum.biobakery.org/t/attributeerror-seq-object-has-no-attribute-replace/4798/3 "2023-02-16T12:24:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![StickHu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/stickhu/32/1951_2.png) [@StickHu](https://forum.biobakery.org/u/StickHu)\
**Post date:** [February 17, 2023, 8:54am UTC](https://forum.biobakery.org/t/attributeerror-seq-object-has-no-attribute-replace/4798/4 "2023-02-17T08:54:59Z")

</div>

> [@Sabry](#):
>
> Like this, the phylogenies were generated succ

I will try, thanks for your help

---

<div class="post-metadata">

**Author:** ![StickHu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/stickhu/32/1951_2.png) [@StickHu](https://forum.biobakery.org/u/StickHu)\
**Post date:** [February 17, 2023, 9:51am UTC](https://forum.biobakery.org/t/attributeerror-seq-object-has-no-attribute-replace/4798/5 "2023-02-17T09:51:03Z")

</div>

> [@StickHu](#):
>
> 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

> [@StickHu](#):
>
> 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

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