<commit_before># Built-in modules #
import os, tarfile

# First party modules #
from seqsearch.databases import Database
from fasta import FASTA
from plumbing.autopaths import AutoPaths, FilePath

# Third party modules #

# Constants #
home = os.environ.get('HOME', '~') + '/'

###############################################################################
class Foraminifera(Database):
    """This is a custom database containing exlcusively Foraminifera sequences.

    https://genev.unige.ch/research/laboratory/Jan-Pawlowski

    You should place the file "foram_db_flo.fasta" in:  ~/databases/foraminifera/
    Then you can run this:
    
            from seqsearch.databases.foraminifera import foraminifera

    """

    short_name = "foraminifera"

    all_paths = """
    /foram_db_flo.fasta
    """

    def __init__(self, base_dir=None):
        # Base directory #
        if base_dir is None: base_dir = home
        self.base_dir = base_dir + 'databases/' + self.short_name + '/'
        self.p        = AutoPaths(self.base_dir, self.all_paths)
        # The results #
        self.alignment = FilePath(self.base_dir + "a")
        self.taxonomy  = FilePath(self.base_dir + "a")

    def process(self):
        raw = FASTA(self.p.flo)
        # Open files #
        # Loop #
        for seq in raw:
            name = seq.id[11:].split('|')
            num  = name.pop(0)
            # Check #
            for x in name: assert ';' not in x
            # Make ranks #
            ranks = ['Eukaryota'                       , # Domain
                     'Foraminifera'                    , # Phylum
                     name[0]                           , # Class
                     name[1]                           , # Order
                     name[2] + " (" + name[3] + ")"    , # Family
                     name[4]                           , # Genus
                     name[5]]                            # Species
            tax = ';'.join(ranks)
            # Add sequence to the new fasta file #

            # Add the taxonomy to the tax file #
            print num, tax #TODO
        # Close files #


    def unzip(self):
        pass

###############################################################################
foraminifera = Foraminifera()<commit_msg>Added foram<commit_after># Built-in modules #
import os, tarfile

# First party modules #
from seqsearch.databases import Database
from fasta import FASTA
from plumbing.autopaths import AutoPaths, FilePath

# Third party modules #

# Constants #
home = os.environ.get('HOME', '~') + '/'

###############################################################################
class Foraminifera(Database):
    """This is a custom database containing exlcusively Foraminifera sequences.

    https://genev.unige.ch/research/laboratory/Jan-Pawlowski

    You should place the file "foram_db_flo.fasta" in:  ~/databases/foraminifera/
    Then you can run this:
    
            from seqsearch.databases.foraminifera import foraminifera

    """

    short_name = "foraminifera"

    all_paths = """
    /foram_db_flo.fasta
    /foram_mothur.fasta
    /foram_mothur.tax
    """

    def __init__(self, base_dir=None):
        # Base directory #
        if base_dir is None: base_dir = home
        self.base_dir = base_dir + 'databases/' + self.short_name + '/'
        self.p        = AutoPaths(self.base_dir, self.all_paths)
        # The results #
        self.alignment = FASTA(self.p.mothur_fasta)
        self.taxonomy  = FilePath(self.p.mothur_tax)

    def process(self):
        # The file that was received by email T_T #
        raw = FASTA(self.p.flo)
        # Open files #
        self.alignment.create()
        self.taxonomy.create()
        # Loop #
        for seq in raw:
            # Parse #
            name = seq.id[11:].split('|')
            num  = name.pop(0)
            # Check #
            for x in name: assert ';' not in x
            for x in name: assert '\t' not in x
            # Make ranks #
            ranks = ['Eukaryota'                       , # Domain
                     'Foraminifera'                    , # Phylum
                     name[0]                           , # Class
                     name[1]                           , # Order
                     name[2] + " (" + name[3] + ")"    , # Family
                     name[4]                           , # Genus
                     name[5]]                            # Species
            # The taxonomy string #
            tax_line = ';'.join(ranks)
            # Add sequence to the new fasta file #
            self.alignment.add_str(str(seq.seq), name=num)
            # Add the taxonomy to the tax file #
            self.taxonomy.add_str(num + '\t' + tax_line + '\n')
        # Close files #
        self.alignment.close()
        self.taxonomy.close()

###############################################################################
foraminifera = Foraminifera()
{'fraction_non_alphanumeric': 0.15978238968365907, 'fraction_numerical': 0.0036268386056820473, 'mean_word_length': 1.6832432432432431, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3500707', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1383, 'n_words': 336}