<commit_before>"""
Class function to read in output csv files from SNPmatch
"""

import pandas as pd
import numpy as np
import os.path
from . import snpmatch


class FollowSNPmatch(object):

    def __init__(self, csv_snpmatch = {}, csv_csmatch = {}):
        #  **kwargs
        '''
        Class function to read in output csv from SNPmatch (intermediate_modified.csv)
        use kwargs to add in multiple csv for different databases (1001g, 250k etc. )
        '''
        self._instances = []
        if csv_snpmatch != {}:
            for req_name in csv_snpmatch.keys():
                req_csv = pd.read_csv(csv_snpmatch[req_name], index_col=0)
                self._instances.append( "snpmatch_" + req_name )
                ## Below we change the column datatype
                for ef in ['TopHitAccession', 'NextHit', 'ThirdHit', 'RefinedTopHit']:
                    req_csv[ef] = req_csv[ef].apply(str)
                setattr(self, "snpmatch_" + req_name, req_csv)
                setattr(self, "snpmatch_" + req_name + "_fol", os.path.dirname( csv_snpmatch[req_name] ) )
        if csv_csmatch != {}:
            for req_name in csv_csmatch.keys():
                req_csv = pd.read_csv(csv_csmatch[req_name], index_col=0)
                self._instances.append( "csmatch_" + req_name )
                ## Below we change the column datatype
                for ef in ['TopHit', 'NextHit', 'ObservedParent1','ObservedParent2']:
                    req_csv[ef] = req_csv[ef].apply(str)
                setattr(self, "csmatch_" + req_name, req_csv)
                setattr(self, "csmatch_" + req_name + "_fol", os.path.dirname( csv_csmatch[req_name] ) )
        self._instances = pd.Series(self._instances)
    
    def beauty_print(self, req_name, req_ix = None, req_index = None):
        '''
        Simple function to only print required columns.
        '''
        req_beauty_print = pd.Series([
            "TopHitAccession", 
            "NextHit",
            "ThirdHit",
            "Score",
            "FracScore",
            'identity',
            "SNPsinfoAcc",
            "TopHitsNumber",
            "dist_to_tophit",
            'percent_heterozygosity',
            "IdenticalWindows",
            "RefinedTopHit",
            'RefinedTopHitNumber'
        ])<commit_msg>python engine to read csv<commit_after>"""
Class function to read in output csv files from SNPmatch
"""

import pandas as pd
import numpy as np
import os.path
from . import snpmatch


class FollowSNPmatch(object):

    def __init__(self, csv_snpmatch = {}, csv_csmatch = {}):
        #  **kwargs
        '''
        Class function to read in output csv from SNPmatch (intermediate_modified.csv)
        use kwargs to add in multiple csv for different databases (1001g, 250k etc. )
        '''
        self._instances = []
        if csv_snpmatch != {}:
            for req_name in csv_snpmatch.keys():
                req_csv = pd.read_csv(csv_snpmatch[req_name], sep = None, engine = 'python', index_col=0)
                self._instances.append( "snpmatch_" + req_name )
                ## Below we change the column datatype
                for ef in req_csv.columns.intersection( ['TopHitAccession', 'NextHit', 'ThirdHit', 'RefinedTopHit'] ):
                    req_csv[ef] = req_csv[ef].apply(str)
                setattr(self, "snpmatch_" + req_name, req_csv)
                setattr(self, "snpmatch_" + req_name + "_fol", os.path.dirname( csv_snpmatch[req_name] ) )
        if csv_csmatch != {}:
            for req_name in csv_csmatch.keys():
                req_csv = pd.read_csv(csv_csmatch[req_name], sep = None, engine = 'python', index_col=0)
                self._instances.append( "csmatch_" + req_name )
                ## Below we change the column datatype
                for ef in ['TopHit', 'NextHit', 'ObservedParent1','ObservedParent2']:
                    req_csv[ef] = req_csv[ef].apply(str)
                setattr(self, "csmatch_" + req_name, req_csv)
                setattr(self, "csmatch_" + req_name + "_fol", os.path.dirname( csv_csmatch[req_name] ) )
        self._instances = pd.Series(self._instances)
    
    def beauty_print(self, req_name, req_ix = None, req_index = None):
        '''
        Simple function to only print required columns.
        '''
        req_beauty_print = pd.Series([
            "TopHitAccession", 
            "NextHit",
            "ThirdHit",
            "Score",
            "FracScore",
            'identity',
            "SNPsinfoAcc",
            "TopHitsNumber",
            "dist_to_tophit",
            'percent_heterozygosity',
            "IdenticalWindows",
            "RefinedTopHit",
            'RefinedTopHitNumber'
        ])
{'fraction_non_alphanumeric': 0.11021619330224672, 'fraction_numerical': 0.0046629927935565915, 'mean_word_length': 2.030828516377649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7286510', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1403, 'n_words': 331}