@@ -61,6 +61,8 @@ class FastaSequence:
6161 TypeError
6262 When calling __init__, if sequence, id_, description, sequence_type or infer_type are of the wrong type.
6363 When calling from_fastasequence(), if fastasequence is of the wrong type.
64+ When setting id, if id_value is not str.
65+ When setting description, if description_value is not str.
6466 When setting sequence_type, if sequence_type_value is of the wrong type.
6567 When calling complement(), if sequence_type is 'aminoacid' or reverse is not bool.
6668 When calling gc_content(), if sequence_type is 'aminoacid' or as_percentage is not bool.
@@ -99,19 +101,8 @@ def __init__(self, sequence, id_='', description='', sequence_type=None, infer_t
99101 TypeError
100102 If sequence, id_, description, sequence_type or infer_type are of the wrong type.
101103 """
102- if isinstance (id_ , str ):
103- id_ = '' .join (id_ .strip ().replace (' ' , '_' ).split ()) # remove spaces and newlines
104- if id_ .startswith ('>' ): # remove '>' if any
105- id_ = id_ [1 :]
106- self ._id = id_
107- else :
108- raise TypeError ('id_ must be str' )
109-
110- if isinstance (description , str ):
111- self ._description = ' ' .join (description .strip ().split ()) # remove extra spaces and newlines
112- else :
113- raise TypeError ('description must be str' )
114-
104+ self ._update_id (id_ )
105+ self ._update_description (description )
115106 self ._update_sequence_type (sequence_type , update_letter_code_objects = False )
116107
117108 if isinstance (sequence , str ) and len (sequence ) > 0 :
@@ -165,11 +156,63 @@ def id(self):
165156 """return id."""
166157 return self ._id
167158
159+ @id .setter
160+ def id (self , id_value ):
161+ """
162+ Sets id.
163+ '>' and newlines will be removed, if any. Spaces will be converted to '_'.
164+ Can be an empty string.
165+
166+ Parameters
167+ ----------
168+ id_value : str
169+ ID portion of the definition line (header).
170+
171+ Raises
172+ ------
173+ TypeError
174+ If id_value is not str.
175+ """
176+ self ._update_id (id_value )
177+
178+ @id .deleter
179+ def id (self ):
180+ """
181+ Sets id to the default value ('').
182+ """
183+ self ._update_id ('' )
184+
168185 @property
169186 def description (self ):
170187 """return description."""
171188 return self ._description
172189
190+ @description .setter
191+ def description (self , description_value ):
192+ """
193+ Sets description.
194+ Newlines will be removed, if any.
195+ Can be an empty string.
196+
197+ Parameters
198+ ----------
199+ description_value : str
200+ Description portion of the definition line (header).
201+
202+ Raises
203+ ------
204+ TypeError
205+ If description_value is not str.
206+ """
207+ self ._update_description (description_value )
208+
209+ @description .deleter
210+ def description (self ):
211+ """
212+ Sets description to the default value ('').
213+ """
214+ self ._update_description ('' )
215+
173216 @property
174217 def sequence (self ):
175218 """return sequence."""
@@ -197,6 +240,13 @@ def sequence_type(self, sequence_type_value):
197240 """
198241 self ._update_sequence_type (sequence_type_value )
199242
243+ @sequence_type .deleter
244+ def sequence_type (self ):
245+ """
246+ Sets sequence_type to the default value (None) and updates all other relevant properties as needed.
247+ """
248+ self ._update_sequence_type (None )
249+
200250 @property
201251 def inferred_type (self ):
202252 """return inferred_type."""
@@ -374,7 +424,7 @@ def count_letter_codes_degenerate(self):
374424 return {letter : counts for letter , counts in self ._counts .items ()
375425 if letter in LETTER_CODES [self ._sequence_type ][1 ]}
376426 raise TypeError ('To count degenerate letter codes the sequence_type must be '
377- 'explicitly \' %s\' ' % ( '\' or \' ' .join (LETTER_CODES ), ))
427+ 'explicitly \' %s\' ' % '\' or \' ' .join (LETTER_CODES ))
378428
379429 def formatted_definition_line (self ):
380430 """
@@ -457,6 +507,51 @@ def reverse(self):
457507 """
458508 return self .__reversed__ ()
459509
510+ def _update_id (self , id_ ):
511+ """
512+ Updates ID portion of the definition line (header).
513+ '>' and newlines will be removed, if any. Spaces will be converted to '_'.
514+ Can be an empty string.
515+
516+ Parameters
517+ ----------
518+ id_ : str
519+ ID portion of the definition line (header).
520+
521+ Raises
522+ ------
523+ TypeError
524+ If id_ is not str.
525+ """
526+ if isinstance (id_ , str ):
527+ id_ = '' .join (id_ .strip ().replace (' ' , '_' ).split ()) # remove spaces and newlines
528+ if id_ .startswith ('>' ): # remove '>' if any
529+ id_ = id_ [1 :]
530+ self ._id = id_
531+ else :
532+ raise TypeError ('id_ must be str' )
533+
534+ def _update_description (self , description ):
535+ """
536+ Updates description portion of the definition line (header).
537+ Newlines will be removed, if any.
538+ Can be an empty string.
539+
540+ Parameters
541+ ----------
542+ description : str
543+ Description portion of the definition line (header).
544+
545+ Raises
546+ ------
547+ TypeError
548+ If description is not str.
549+ """
550+ if isinstance (description , str ):
551+ self ._description = ' ' .join (description .strip ().split ()) # remove extra spaces and newlines
552+ else :
553+ raise TypeError ('description must be str' )
554+
460555 def _update_sequence_type (self , sequence_type , update_letter_code_objects = True ):
461556 """
462557 Updates sequence_type and all other relevant properties as needed.
@@ -477,7 +572,7 @@ def _update_sequence_type(self, sequence_type, update_letter_code_objects=True):
477572 self ._sequence_type = sequence_type
478573 self ._inferred_type = False
479574 else :
480- raise TypeError ('sequence_type must be one of: %s or None' % LETTER_CODES )
575+ raise TypeError ('sequence_type must be one of: \' %s \' or None' % ' \' , \' ' . join ( LETTER_CODES ) )
481576 if isinstance (update_letter_code_objects , bool ):
482577 if update_letter_code_objects :
483578 for letter_code_object in self ._sequence : # update LetterCode objects
0 commit comments