
    RiZ                     n    d Z ddlZddZd Z G d d      Z G d d      Z G d	 d
      Z G d d      Zy)a  Hold GenBank data in a straightforward format.

Classes:
 - Record - All of the information in a GenBank record.
 - Reference - hold reference data for a record.
 - Feature - Hold the information in a Feature Table.
 - Qualifier - Qualifiers on a Feature.

    Nc                    t         j                  |z
  }| sy|r| j                  |      }n=d}g }|t        |       k  r+|j	                  | |||z           ||z  }|t        |       k  r+g }d}|D ]O  }	t        |      dz   t        |	      z   |kD  r |r|dk7  r||z  }|j	                  |       |	}@|dk(  r|	}H|||	z   z  }Q |r|j	                  |       |d   dz   }
|dd D ]  }|
d|z  |z   dz   z  }
 |
S )av  Write a line of GenBank info that can wrap over multiple lines (PRIVATE).

    This takes a line of information which can potentially wrap over
    multiple lines, and breaks it up with carriage returns and
    indentation so it fits properly into a GenBank record.

    Arguments:
     - information - The string holding the information we want
       wrapped in GenBank method.
     - indent - The indentation on the lines we are writing.
     - wrap_space - Whether or not to wrap only on spaces in the
       information.
     - split_char - A specific character to split the lines on. By default
       spaces are used.

    z.
r        
N)RecordGB_LINE_LENGTHsplitlenappend)informationindent
wrap_space
split_charinfo_length
info_partscur_posoutput_partscur_part	info_partoutput_infooutput_parts               J/home/agent/.friday_env/lib/python3.12/site-packages/Bio/GenBank/Record.py_wrapped_genbankr      sH   " ''&0K &&z2

K((k'Gk4IJK{"G K((
 LH 3	x=1s9~-;$
*H##H- H2~$J223 H% q/D(K#AB' 9sV|k1D889     c                 h    | j                  d      }|d   dz   }|dd D ]  }|d|z  |z   dz   z  } |S )a&  Write out information with the specified indent (PRIVATE).

    Unlike _wrapped_genbank, this function makes no attempt to wrap
    lines -- it assumes that the information already has newlines in the
    appropriate places, and will add the specified indent to the start of
    each line.
    r   r   r   Nr   )r
   )r   r   r   r   r   s        r   _indent_genbankr   O   sY     ""4(J Q-$&K^ 7	sV|i/$667 r   c                      e Zd ZdZdZdZdZdZdZdZ	dZ
d	 ee      z   d
z   Zdez  d	z    eeez
        z   d
z   Zdez  d	z    eeez
        z   d
z   Zd	 ee      z   d
z   Zde	z  d	z    eee	z
        z   d
z   Zd ee
      z   d
z   Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d  Z%d! Z&d" Z'd# Z(y$)%r   a#	  Hold GenBank information in a format similar to the original record.

    The Record class is meant to make data easy to get to when you are
    just interested in looking at GenBank data.

    Attributes:
     - locus - The name specified after the LOCUS keyword in the GenBank
       record. This may be the accession number, or a clone id or something else.
     - size - The size of the record.
     - residue_type - The type of residues making up the sequence in this
       record. Normally something like RNA, DNA or PROTEIN, but may be as
       esoteric as 'ss-RNA circular'.
     - data_file_division - The division this record is stored under in
       GenBank (ie. PLN -> plants; PRI -> humans, primates; BCT -> bacteria...)
     - date - The date of submission of the record, in a form like '28-JUL-1998'
     - accession - list of all accession numbers for the sequence.
     - nid - Nucleotide identifier number.
     - pid - Proteint identifier number
     - version - The accession number + version (ie. AB01234.2)
     - db_source - Information about the database the record came from
     - gi - The NCBI gi identifier for the record.
     - keywords - A list of keywords related to the record.
     - segment - If the record is one of a series, this is info about which
       segment this record is (something like '1 of 6').
     - source - The source of material where the sequence came from.
     - organism - The genus and species of the organism (ie. 'Homo sapiens')
     - taxonomy - A listing of the taxonomic classification of the organism,
       starting general and getting more specific.
     - references - A list of Reference objects.
     - comment - Text with any kind of comment about the record.
     - features - A listing of Features making up the feature table.
     - base_counts - A string with the counts of bases for the sequence.
     - origin - A string specifying info about the origin of the sequence.
     - sequence - A string with the sequence itself.
     - contig - A string of location information for a CONTIG in a RefSeq file
     - project - The genome sequencing project numbers
       (will be replaced by the dblink cross-references in 2009).
     - dblinks - The genome sequencing project number(s) and other links.
       (will replace the project information in 2009).

    O                  	   z%-sr   %c                    g | _         d| _        d| _        d| _        d| _        d| _        d| _        g | _        d| _        g | _	        d| _
        g | _        d| _        d| _        d| _        d| _        d| _        d| _        g | _        g | _        g | _        d| _        d| _        d| _        d| _        d| _        g | _        d| _        d| _        d| _        g | _        yInitialize the class.r   N)	accessionbase_countscommentcontigdata_file_divisiondate	db_sourcedblinks
definitionfeaturesgikeywordslocusmolecule_typenidorganismoriginpidprimaryprojects
referencesresidue_typesegmentsequencesizesourcetaxonomytopologyversionwgs
wgs_scafldselfs    r   __init__zRecord.__init__   s    "$	
	r   c                    | j                         }|| j                         z  }|| j                         z  }|| j                         z  }|| j	                         z  }|| j                         z  }|| j                         z  }|| j                         z  }|| j                         z  }|| j                         z  }|| j                         z  }|| j                         z  }|| j                         z  }| j                  D ]  }|t        |      z  } || j                         z  }|| j!                         z  }| j"                  D ]  }|t        |      z  } || j%                         z  }|| j'                         z  }|| j)                         z  }|| j+                         z  }|| j-                         z  }|| j/                         z  }|dz  }|S )a  Provide a GenBank formatted output option for a Record.

        The objective of this is to provide an easy way to read in a GenBank
        record, modify it somehow, and then output it in 'GenBank format.'
        We are striving to make this work so that a parsed Record that is
        output using this function will look exactly like the original
        record.

        Much of the output is based on format description info at:

        ftp://ncbi.nlm.nih.gov/genbank/gbrel.txt
        z//)_locus_line_definition_line_accession_line_version_line_project_line_dblink_line	_nid_line	_pid_line_keywords_line_db_source_line_segment_line_source_line_organism_liner?   str_comment_line_features_liner4   _base_count_line_origin_line_sequence_line	_wgs_line_wgs_scafld_line_contig_line)rK   output	referencefeatures       r   __str__zRecord.__str__   s    !!#$''))$&&(($$$&&$$$&&$##%%$..""$..""$%%''$&&(($$$&&$##%%$%%'' 	%Ic)n$F	%$$$&&$%%''}} 	#Gc'l"F	#$''))$##%%$%%''$..""$''))$##%%$r   c                    d}|dz  }|d| j                   z  z  }|dz  }|d| j                  z  z  }d| j                  v r|dz  }n|dz  }d	| j                  v r|d
| j                  z  z  }nBd| j                  v r|d| j                  z  z  }|dz  }n|dz  }|d| j                  z  z  }|dz  }|dz  }|d| j                  z  z  }|dz  }|d| j                  z  z  }|dz  }|S )z7Provide the output string for the LOCUS line (PRIVATE).LOCUSz       z%-9sr   z%7sPROTEINz aaz bp circularz%17s-z
          z   z%-4s  z%3sz%11sr   )r7   rC   r@   r/   r0   rK   rd   s     r   rN   zRecord._locus_line   s&   '&4::%%#%$))##)))eOFfF ***ft0000FD%%%ed////FhFgFft0000FhF'%$1111'&499$$$r   c                     t         j                  dz  }|t        | j                  dz   t         j                        z  }|S )z1Provide output for the DEFINITION line (PRIVATE).
DEFINITION.)r   BASE_FORMATr   r3   GB_BASE_INDENTrn   s     r   rO   zRecord._definition_line  s8    ##l2"4??S#8&:O:OPPr   c                     | j                   r]t        j                  dz  }d}| j                   D ]
  }|| dz  } |j                         }|t	        |t        j
                        z  }|S d}|S )z(Output for the ACCESSION line (PRIVATE).	ACCESSIONr   r   )r+   r   rr   rstripr   rs   )rK   rd   acc_infor+   s       r   rP   zRecord._accession_line  sz    >>''+5FH!^^ ,	ykO+,  (H&x1F1FGGF  Fr   c                     | j                   r;t        j                  dz  }|| j                   z  }|dz  }|| j                   dz  }|S d}|S )z&Output for the VERSION line (PRIVATE).VERSIONz  GI:r   r   )rG   r   rr   r5   rn   s     r   rQ   zRecord._version_line+  sX    <<'')3Fdll"FgF	n$F  Fr   c                     d}t        | j                        dkD  r4t        j                  dz  }|dj	                  | j                         dz  }|S )Nr   r   PROJECTrm   r   )r   r>   r   rr   joinrn   s     r   rR   zRecord._project_line6  sL    t}}!'')3F4==12"55Fr   c                     d}t        | j                        dkD  rKt        j                  dz  }dj	                  | j                        }|t        |t        j                        z  }|S )Nr   r   DBLINKr   )r   r2   r   rr   r|   r   rs   )rK   rd   dblink_infos      r   rS   zRecord._dblink_line=  sW    t||q ''(2F))DLL1K&{F4I4IJJFr   c                 p    | j                   r't        j                  dz  }|| j                    dz  }|S d}|S )zKOutput for the NID line. Use of NID is obsolete in GenBank files (PRIVATE).NIDr   r   )r9   r   rr   rn   s     r   rT   zRecord._nid_lineE  @    88''%/F
"o%F  Fr   c                 p    | j                   r't        j                  dz  }|| j                    dz  }|S d}|S )zFOutput for PID line. Presumedly, PID usage is also obsolete (PRIVATE).PIDr   r   )r<   r   rr   rn   s     r   rU   zRecord._pid_lineN  r   r   c                     d}| j                   rX|t        j                  dz  z  }d}| j                   D ]
  }|| dz  } |dd }|dz  }|t        |t        j                        z  }|S )z'Output for the KEYWORDS line (PRIVATE).r   KEYWORDS; Nrq   )r6   r   rr   r   rs   )rK   rd   keyword_infokeywords       r   rV   zRecord._keywords_lineW  s    ==f((:55FL== /7)2./ (,LCL&|V5J5JKKFr   c                 p    | j                   r't        j                  dz  }|| j                    dz  }|S d}|S )z#Output for DBSOURCE line (PRIVATE).DBSOURCEr   r   )r1   r   rr   rn   s     r   rW   zRecord._db_source_lineg  sB    >>''*4F(++F  Fr   c                     d}| j                   r=|t        j                  dz  z  }|t        | j                   t        j                        z  }|S )z&Output for the SEGMENT line (PRIVATE).r   SEGMENT)rA   r   rr   r   rs   rn   s     r   rX   zRecord._segment_linep  sD    <<f((944F&t||V5J5JKKFr   c                 z    t         j                  dz  }|t        | j                  t         j                        z  }|S )z?Output for SOURCE line on where the sample came from (PRIVATE).SOURCE)r   rr   r   rD   rs   rn   s     r   rY   zRecord._source_linex  s3    ##h."4;;0E0EFFr   c                 *   t         j                  dz  }|t        | j                  t         j                        z  }|dt         j                  z  z  }d}| j
                  D ]
  }|| dz  } |dd }|dz  }|t        |t         j                        z  }|S )z6Output for ORGANISM line with taxonomy info (PRIVATE).ORGANISMr   r   r   Nr   rq   )r   INTERNAL_FORMATr   r:   rs   rE   )rK   rd   taxonomy_infotaxs       r   rZ   zRecord._organism_line~  s    ''*4"4==&2G2GHH#----== 	(CuBZ'M	( &cr*"=&2G2GHHr   c                     d}| j                   r=|t        j                  dz  z  }|t        | j                   t        j                        z  }|S )z'Output for the COMMENT lines (PRIVATE).r   COMMENT)r-   r   rr   r   rs   rn   s     r   r\   zRecord._comment_line  sC    <<f((944FodllF4I4IJJFr   c                 p    d}t        | j                        dkD  r|t        j                  dz  z  }|dz  }|S )z'Output for the FEATURES line (PRIVATE).r   r   FEATURESzLocation/Qualifiers
)r   r4   r   BASE_FEATURE_FORMATrn   s     r   r]   zRecord._features_line  s=    t}}!f00:==F--Fr   c                    d}| j                   r|t        j                  dz  z  }| j                   j                  d      }d|v r|j	                  d       d|v rt        |      dz  dk(  rKt        |      dkD  rL|j                  d      }|j                  d      }||dd| z  }t        |      dkD  r<n|| j                   z  }|dz  }|S )z?Output for the BASE COUNT line with base information (PRIVATE).r   zBASE COUNT  r   r"   r   z>7r   )r,   r   rr   r
   remover   pop)rK   rd   count_parts
count_info
count_types        r   r^   zRecord._base_count_line  s    f((>99F**005K#""2& # ;!#q(+&*!,!3J!,!3JBq==F	 +&* $***dNFr   c                     d}| j                   rP|t        j                  dz  z  }| j                  r)|t	        | j                  t        j
                        z  }|S |dz  }|S )z%Output for the ORIGIN line (PRIVATE).r   ORIGINr   )rB   r   rr   r;   r   rs   rn   s     r   r_   zRecord._origin_line  s]    ==f((833F{{*4;;8M8MNN  $r   c                    d}| j                   rd}|t        | j                         k  r|t        j                  t	        |dz         z  z  }t        d      D ]N  }||dz  z   }|dz   }| j                   || }|d|j                          z  }|t        | j                         kD  sN n |dz  }|dz  }|t        | j                         k  r|S )	z)Output for all of the sequence (PRIVATE).r   r   r      
   r   r   <   )rB   r   r   SEQUENCE_FORMATr[   rangelower)rK   rd   cur_seq_possection	start_posend_posseq_sections          r   r`   zRecord._sequence_line  s    ==KDMM 22&003{Q3GGG$Qx G +gl :I'"nG"&--	'"BK+"3"3"5!677F T]]!33 $r! DMM 22 r   c                 l    d}| j                   r%|t        j                  dz  z  }|| j                   z  }|S )Nr   WGS)rH   r   rr   rn   s     r   ra   zRecord._wgs_line  s6    88f((500FdhhFr   c                 l    d}| j                   r%|t        j                  dz  z  }|| j                   z  }|S )Nr   
WGS_SCAFLD)rI   r   rr   rn   s     r   rb   zRecord._wgs_scafld_line  s6    ??f((<77Fdoo%Fr   c                     d}| j                   r?|t        j                  dz  z  }|t        | j                   t        j                  d      z  }|S )z=Output for CONTIG location information from RefSeq (PRIVATE).r   CONTIG,r   )r.   r   rr   r   rs   rn   s     r   rc   zRecord._contig_line  sM    ;;f((833F&V22s F r   N))__name__
__module____qualname____doc__r	   rs   GB_FEATURE_INDENTGB_INTERNAL_INDENTGB_OTHER_INTERNAL_INDENTGB_FEATURE_INTERNAL_INDENTGB_SEQUENCE_INDENTr[   rr   r   OTHER_INTERNAL_FORMATr   INTERNAL_FEATURE_FORMATr   rL   rg   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r\   r]   r^   r_   r`   ra   rb   rc    r   r   r   r   b   s}   (V NN !"^,,s2K  4'#n?Q.Q*RRUXX  	&&
	
n77
8	9 	  %6!77#=((
	
"<<
=	> 	  C 233c9O D'R@ 	  2
,r   r   c                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)	ReferenceaJ  Hold information from a GenBank reference.

    Attributes:
     - number - The number of the reference in the listing of references.
     - bases - The bases in the sequence the reference refers to.
     - authors - String with all of the authors.
     - consrtm - Consortium the authors belong to.
     - title - The title of the reference.
     - journal - Information about the journal where the reference appeared.
     - medline_id - The medline id for the reference.
     - pubmed_id - The pubmed_id for the reference.
     - remark - Free-form remarks about the reference.

    c                     d| _         d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        yr)   )	numberbasesauthorsconsrtmtitlejournal
medline_id	pubmed_idremarkrJ   s    r   rL   zReference.__init__  sA    

r   c                 0   | j                         }|| j                         z  }|| j                         z  }|| j                         z  }|| j	                         z  }|| j                         z  }|| j                         z  }|| j                         z  }|S )z1Convert the reference to a GenBank format string.)_reference_line_authors_line_consrtm_line_title_line_journal_line_medline_line_pubmed_line_remark_linern   s     r   rg   zReference.__str__  s    %%'$$$&&$$$&&$""$$$$$&&$$$&&$##%%$##%%r   c                     t         j                  dz  }| j                  r?| j                  r#|d| j                  z  z  }|| j                   z  }n|| j                   z  }|dz  }|S )z%Output for REFERENCE lines (PRIVATE).	REFERENCEz%-3sr   )r   rr   r   r   rn   s     r   r   zReference._reference_line  sa    ##k1;;zz&4;;..TZZL)T[[M*$r   c                     d}| j                   r=|t        j                  dz  z  }|t        | j                   t        j                        z  }|S )z)Output for AUTHORS information (PRIVATE).r   AUTHORS)r   r   r   r   rs   rn   s     r   r   zReference._authors_line(  D    <<f,,y88F&t||V5J5JKKFr   c                     d}| j                   r=|t        j                  dz  z  }|t        | j                   t        j                        z  }|S )z)Output for CONSRTM information (PRIVATE).r   CONSRTM)r   r   r   r   rs   rn   s     r   r   zReference._consrtm_line0  r   r   c                     d}| j                   r=|t        j                  dz  z  }|t        | j                   t        j                        z  }|S )z'Output for TITLE information (PRIVATE).r   TITLE)r   r   r   r   rs   rn   s     r   r   zReference._title_line8  sD    ::f,,w66F&tzz63H3HIIFr   c                     d}| j                   r=|t        j                  dz  z  }|t        | j                   t        j                        z  }|S )z)Output for JOURNAL information (PRIVATE).r   JOURNAL)r   r   r   r   rs   rn   s     r   r   zReference._journal_line@  r   r   c                 r    d}| j                   r(|t        j                  dz  z  }|| j                   dz   z  }|S )z)Output for MEDLINE information (PRIVATE).r   MEDLINEr   )r   r   r   rn   s     r   r   zReference._medline_lineH  s;    ??f,,y88Fdoo,,Fr   c                 r    d}| j                   r(|t        j                  dz  z  }|| j                   dz   z  }|S )z(Output for PUBMED information (PRIVATE).r   PUBMEDr   )r   r   r   rn   s     r   r   zReference._pubmed_lineP  s;    >>f22X==Fdnnt++Fr   c                     d}| j                   r=|t        j                  dz  z  }|t        | j                   t        j                        z  }|S )z(Output for REMARK information (PRIVATE).r   REMARK)r   r   r   r   rs   rn   s     r   r   zReference._remark_lineX  sD    ;;f,,x77F&t{{F4I4IJJFr   N)r   r   r   r   rL   rg   r   r   r   r   r   r   r   r   r   r   r   r   r     s9    
r   r   c                   $    e Zd ZdZddZd Zd Zy)Featurea  Hold information about a Feature in the Feature Table of GenBank record.

    Attributes:
     - key - The key name of the feature (ie. source)
     - location - The string specifying the location of the feature.
     - qualifiers - A list of Qualifier objects in the feature.

    c                 .    || _         || _        g | _        yr*   N)keylocation
qualifiers)rK   r   r   s      r   rL   zFeature.__init__k  s     r   c                 <    d| j                   d| j                  dS )6Representation of the object for debugging or logging.zFeature(key=z, location=))r   r   rJ   s    r   __repr__zFeature.__repr__q  s     dhh\T]]4EQGGr   c                     t         j                  | j                  z  }|t        | j                  t         j
                  d      z  }| j                  D ]  }|t        |      z  } |S )z*Return feature as a GenBank format string.r   r   )r   r   r   r   r   r   r   r[   )rK   rd   	qualifiers      r   rg   zFeature.__str__u  sa    //$((:"MM633
 	
  	%Ic)n$F	%r   Nr   r   r   r   r   r   rL   r   rg   r   r   r   r   r   a  s    Hr   r   c                   $    e Zd ZdZddZd Zd Zy)	QualifierzHold information about a qualifier in a GenBank feature.

    Attributes:
     - key - The key name of the qualifier (ie. /organism=)
     - value - The value of the qualifier ("Dictyostelium discoideum").

    c                      || _         || _        yr   r   value)rK   r   r   s      r   rL   zQualifier.__init__  s    
r   c                 <    d| j                   d| j                  dS )r   zQualifier(key=z, value=r   r   rJ   s    r   r   zQualifier.__repr__  s    |8DJJ>CCr   c                 
   dt         j                  z  }d}t        j                  j                  j
                  D ]  }|| j                  v sd} |t        | j                  | j                  z   t         j                  |      z   S )z4Return feature qualifier as a GenBank format string.r   r   r   )	r   r   BioGenBank_BaseGenBankConsumerremove_space_keysr   r   r   )rK   rd   
space_wrapno_space_keys       r   rg   zQualifier.__str__  sx    v///
KK<<NN 	Ltxx'
	 (HHtzz!6#;#;Z
 
 	
r   Nr   r   r   r   r   r   r     s    
D
r   r   )r   r   )	r   Bio.GenBankr   r   r   r   r   r   r   r   r   r   <module>r     sH    9x&M M`l l^ >
 
r   