<commit_before>from csv import reader
import numpy as np
from sklearn.linear_model import LinearRegression, LogisticRegression
import mods.saveOutput as saveOutput

def protQuant (standards_file, protein_file, N_mass=25, regression_style='Linear'):
    '''
    standards_file = csv or tsv file where first row are the standard concentrations and other rows are fluoresence
    protein_file = csv or tsv file where rows are fluoresences
    N_mass = FLOAT: amount of protein wanted (in same units as in input)
    regression_style = STRING: type of regression to be used: 'Linear', 
    '''
    try:
        float_test = float(N_mass)
    except:
        print ("Error: The 'N mass' needs to be an integer or decimal value!")
        return
    
    # Reading files
    standard_concs, standard_fluors = readStandards(standards_file)
    prot_fluors = readProteins(protein_file)
    
    # Averaging multiple samples...
    standard_fluors = averageRows(standard_fluors)
    prot_fluors = averageRows(prot_fluors)
    
    # Finding regression...
    prot_concs = regressor(standard_concs, standard_fluors, prot_fluors, regression_style)
    
    # Finding N volume needed for N mass...
    N_vols = []
    for prot_conc in prot_concs:
        try:
            N_vol = float(N_mass)/prot_conc
        except:
            print ("Error: Protein Concentration regresses to zero!")
            return
        N_vols.append(N_vol)
    
    out_text = str(prot_concs)
    for item in N_vols:
        out_text=out_text+("%s\n" % item)
        
    saveOutput.saveData(out_text, "ProtQuant")

def readStandards (filename):
    standards_concs = []
    standard_fluors = []
    
    # Reading standards...
    with open(filename) as file:
        if '.tsv' in filename:
            i = 0
            for line in reader(file, delimiter="\t"):
                if i == 0:
                    standard_concs = []
                    for item in line:
                        standard_concs.append(float(item))
                else:
                    standard_fluors.append(line)
                    # Raises error if number of cols doesn't match
                    if len(standard_fluors[i-1]) != len(standard_concs):
                        raise Exception('Please make sure that the input is rectangular.')
                i += 1
            
        elif '.csv' in filename:
            i = 0
            for line in reader(file, delimiter=","):
                if i == 0:
                    standard_concs = []<commit_msg>Cleaned up output<commit_after>from csv import reader
import numpy as np
from sklearn.linear_model import LinearRegression, LogisticRegression
import mods.saveOutput as saveOutput

def protQuant (standards_file, protein_file, N_mass=25, regression_style='Linear'):
    '''
    standards_file = csv or tsv file where first row are the standard concentrations and other rows are fluoresence
    protein_file = csv or tsv file where rows are fluoresences
    N_mass = FLOAT: amount of protein wanted (in same units as in input)
    regression_style = STRING: type of regression to be used: 'Linear', 
    '''
    try:
        float_test = float(N_mass)
    except:
        print ("Error: The 'N mass' needs to be an integer or decimal value!")
        return
    
    # Reading files
    standard_concs, standard_fluors = readStandards(standards_file)
    prot_fluors = readProteins(protein_file)
    
    # Averaging multiple samples...
    standard_fluors = averageRows(standard_fluors)
    prot_fluors = averageRows(prot_fluors)
    
    # Finding regression...
    prot_concs = regressor(standard_concs, standard_fluors, prot_fluors, regression_style)
    
    # Finding N volume needed for N mass...
    N_vols = []
    for prot_conc in prot_concs:
        try:
            N_vol = float(N_mass)/prot_conc
        except:
            print ("Error: Protein Concentration regresses to zero!")
            return
        N_vols.append(N_vol)
    
    out_text = 'Protein Concentrations: '+str(prot_concs)+'\n'
    for item in N_vols:
        out_text=out_text+("\n%s" % item)
        
    saveOutput.saveData(out_text, "ProtQuant")

def readStandards(filename):
    standards_concs = []
    standard_fluors = []
    
    # Reading standards...
    with open(filename) as file:
        if '.tsv' in filename:
            i = 0
            for line in reader(file, delimiter="\t"):
                if i == 0:
                    standard_concs = []
                    for item in line:
                        standard_concs.append(float(item))
                else:
                    standard_fluors.append(line)
                    # Raises error if number of cols doesn't match
                    if len(standard_fluors[i-1]) != len(standard_concs):
                        raise Exception('Please make sure that the input is rectangular.')
                i += 1
            
        elif '.csv' in filename:
            i = 0
            for line in reader(file, delimiter=","):
                if i == 0:
                    standard_concs = []
{'fraction_non_alphanumeric': 0.08048924837246005, 'fraction_numerical': 0.003156441112645492, 'mean_word_length': 2.074590661006671, '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': '887570', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1409, 'n_words': 431}