<commit_before>from ssbio.core.object import Object
from os import path as op
from Bio import SeqIO
import ssbio.utils
import ssbio.sequence.utils.fasta
import ssbio.sequence.properties.residues
from cobra.core import DictList
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.Alphabet import IUPAC
from copy import deepcopy
from collections import defaultdict
import logging

log = logging.getLogger(__name__)


class SeqProp(Object):
    """Class for protein sequence properties.

    SeqProp provides:
    1. Attributes for mapping to other database identifiers
        - .bigg: BiGG Models ID
        - .kegg: KEGG ID
        - .uniprot: UniProt ACC/ID
        - .gene_name: Human readable gene name
        - .pdbs: Mapped PDB IDs

    2. Basic sequence attributes
        - .seq_len: Length of the amino acid sequence

    3. Pointers to filepaths
        - .sequence_file: Basename of sequence file in FASTA format
        - .sequence_path: Full path to sequence file
        - .metadata_file: Basename of metadata file in any format
        - .metadata_path: Full path to metadata file

    4. Pointers to


    """

    def __init__(self, ident, description=None, sequence_file=None, metadata_file=None, seq_record=None, seq_str=None,
                 write_fasta_file=False, outname=None, outdir=None, force_rewrite=False):
        """Parses basic sequence properties like identifiers and sequence length.
        Provides paths to sequence and metadata files.

        Args:
            ident: Identifier of the sequence (can be any string)
            sequence_file: Path to FASTA file of the sequence
            metadata_file: Path to metadata file of the sequence
            seq_record: Biopython SeqRecord object
            seq_str: Sequence formatted as a string

        """
        Object.__init__(self, id=ident, description=description)

        self.bigg = None
        self.kegg = None
        self.refseq = None
        self.uniprot = None
        self.gene_name = None
        self.pdbs = None
        self.seq_record = seq_record

        self.sequence_path = sequence_file
        self.metadata_path = metadata_file

        if seq_str:
            self.seq_record = ssbio.sequence.utils.fasta.load_seq_string_as_seqrecord(seq_str, self.id)
        if sequence_file:
            self.load_seq_file(sequence_file)

        if write_fasta_file:
            self.write_fasta_file(outname=outname, outdir=outdir, force_rerun=force_rewrite)

        # Store AlignIO objects of this sequence to others in alignments
        self.sequence_alignments = DictList()
        self.structure_alignments = DictList()<commit_msg>Allow input of str, Seq, or SeqRecord into SeqProp<commit_after>from ssbio.core.object import Object
from os import path as op
from Bio import SeqIO
import ssbio.utils
import ssbio.sequence.utils
import ssbio.sequence.utils.fasta
import ssbio.sequence.properties.residues
from cobra.core import DictList
from copy import deepcopy
from collections import defaultdict
import logging

log = logging.getLogger(__name__)


class SeqProp(Object):
    """Class for protein sequence properties.

    SeqProp provides:
    1. Attributes for mapping to other database identifiers
        - .bigg: BiGG Models ID
        - .kegg: KEGG ID
        - .uniprot: UniProt ACC/ID
        - .gene_name: Human readable gene name
        - .pdbs: Mapped PDB IDs

    2. Basic sequence attributes
        - .seq_str: Sequence formatted as a string
        - .seq_len: Length of the amino acid sequence

    3. Pointers to filepaths
        - .sequence_path: Full path to sequence file
        - .metadata_path: Full path to metadata file

    """

    def __init__(self, ident, sequence_file=None, metadata_file=None, seq=None, description="<unknown description>",
                 write_fasta_file=False, outname=None, outdir=None, force_rewrite=False):
        """Parses basic sequence properties like identifiers and sequence length.
        Provides paths to sequence and metadata files.

        Args:
            ident (str): Identifier of the sequence
            description:
            sequence_file: Path to FASTA file of the sequence
            metadata_file: Path to metadata file of the sequence
            seq (str, Seq, SeqRecord): Sequence string, Biopython Seq or SeqRecord object
            write_fasta_file:
            outname:
            outdir:
            force_rewrite:
        """
        Object.__init__(self, id=ident, description=description)

        self.bigg = None
        self.kegg = None
        self.refseq = None
        self.uniprot = None
        self.gene_name = None
        self.pdbs = None
        self.seq_record = None

        self.sequence_path = sequence_file
        self.metadata_path = metadata_file

        if seq:
            self.seq_record = ssbio.sequence.utils.cast_to_seq_record(obj=seq, id=ident, description=description)
        if sequence_file:
            self.load_seq_file(sequence_file)

        if write_fasta_file:
            self.write_fasta_file(outname=outname, outdir=outdir, force_rerun=force_rewrite)

        # Store AlignIO objects of this sequence to others in alignments
        self.sequence_alignments = DictList()
        self.structure_alignments = DictList()
{'fraction_non_alphanumeric': 0.06317382258369586, 'fraction_numerical': 0.0013240022697181767, 'mean_word_length': 2.577807848443843, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3484079', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1447, 'n_words': 472}