<commit_before>#!/usr/bin/env python

"""
Tools for assisting in parsing data to input into analysis procedure.
"""

#=============================================================================================
# Imports
#=============================================================================================

from assaytools import platereader
import string
import numpy as np

#=============================================================================================
# Functions and things to help with parsing
#=============================================================================================

def reorder2list(data,well):

    sorted_keys = sorted(well.keys(), key=lambda k:well[k])

    reorder_data = []

    for key in sorted_keys:
        try:
            reorder_data.append(data[key])
        except:
            pass

    reorder_data = [r.replace('OVER','70000') for r in reorder_data]

    reorder_data = np.asarray(reorder_data,np.float64)

    return reorder_data

ALPHABET = string.ascii_uppercase

well = dict()
for j in string.ascii_uppercase:
    for i in range(1,25):
        well['%s' %j + '%s' %i] = i

#=============================================================================================
# Parsing functions
#=============================================================================================


def get_data_using_inputs(inputs):

    """
    Parses your data according to inputs dictionary. Currently requires single xml file input or spectra analysis.
    Parameters
    ----------
    inputs : dict
        Dictionary of input information
    """

    if 'wavelength' in inputs:
        
        complex_fluorescence = {}
        ligand_fluorescence = {}
        
        for protein in inputs['file_set'].keys():

            #concatenate four spectra xmls into one dictionary with all ligand data

            my_file = []

            data = platereader.read_icontrol_xml(inputs['file_set']['%s'%protein][0])
            for file in inputs['file_set']['%s'%protein]:
                my_file.append(file)
                new_dict = platereader.read_icontrol_xml(file)
                for key in data:
                    data[key].update(new_dict[key])
    
            for i in range(0,7,2):
                protein_row = ALPHABET[i]
                buffer_row = ALPHABET[i+1]

                name = "%s-%s-%s%s"%(protein,inputs['ligand_order'][int(i/2)],protein_row,buffer_row)
 
                complex_fluorescence_data = platereader.select_data(data, inputs['section'], protein_row, wavelength = '%s' %inputs['wavelength'])
                ligand_fluorescence_data = platereader.select_data(data, inputs['section'], buffer_row, wavelength = '%s' %inputs['wavelength'])

                complex_fluorescence[name] = reorder2list(complex_fluorescence_data,well)
                ligand_fluorescence[name] = reorder2list(ligand_fluorescence_data,well)
    
    else:

        data = platereader.read_icontrol_xml(inputs['my_file'])
    
        complex_fluorescence = {}
        ligand_fluorescence = {}
    
        for i in range(0,15,2):
            protein_row = ALPHABET[i]
            buffer_row = ALPHABET[i+1]

            name = "%s-%s%s"%(inputs['ligand_order'][int(i/2)],protein_row,buffer_row)

            complex_fluorescence_data = platereader.select_data(data, inputs['section'], protein_row)
            ligand_fluorescence_data = platereader.select_data(data, inputs['section'], buffer_row)

            complex_fluorescence[name] = reorder2list(complex_fluorescence_data,well)
            ligand_fluorescence[name] = reorder2list(ligand_fluorescence_data,well)

    return [complex_fluorescence, ligand_fluorescence]
 
<commit_msg>made parser.py usable for single wavelength assays<commit_after>#!/usr/bin/env python

"""
Tools for assisting in parsing data to input into analysis procedure.
"""

#=============================================================================================
# Imports
#=============================================================================================

from assaytools import platereader
import string
import numpy as np

#=============================================================================================
# Functions and things to help with parsing
#=============================================================================================

def reorder2list(data,well):

    sorted_keys = sorted(well.keys(), key=lambda k:well[k])

    reorder_data = []

    for key in sorted_keys:
        try:
            reorder_data.append(data[key])
        except:
            pass

    reorder_data = [r.replace('OVER','70000') for r in reorder_data]

    reorder_data = np.asarray(reorder_data,np.float64)

    return reorder_data

ALPHABET = string.ascii_uppercase

well = dict()
for j in string.ascii_uppercase:
    for i in range(1,25):
        well['%s' %j + '%s' %i] = i

#=============================================================================================
# Parsing functions
#=============================================================================================


def get_data_using_inputs(inputs):

    """
    Parses your data according to inputs dictionary. Requires you have a 'file_set' in your inputs.
    Parameters
    ----------
    inputs : dict
        Dictionary of input information
    """
    complex_fluorescence = {}
    ligand_fluorescence = {}
        
    for protein in inputs['file_set'].keys():

        #concatenate xmls into one dictionary with all ligand data

        my_file = []

        # Data just helps define our keys, which will be our data sections.
        # We are importing the first two files, because sometimes we have two files per
        # data collection, e.g. if we wanted a lot of types of reads 
        # (there is a limited number of type of read on the infinite per script).
        data = platereader.read_icontrol_xml(inputs['file_set']['%s'%protein][0])
        try:
            data.update(platereader.read_icontrol_xml(inputs['file_set']['%s'%protein][1]))
        except:
            pass
        
        for file in inputs['file_set']['%s'%protein]:
            my_file.append(file)
            new_dict = platereader.read_icontrol_xml(file)
            for key in data:
                try:
                    data[key].update(new_dict[key])
                except:
                    pass
    
        for i in range(0,7,2):
            protein_row = ALPHABET[i]
            buffer_row = ALPHABET[i+1]

            name = "%s-%s-%s%s"%(protein,inputs['ligand_order'][int(i/2)],protein_row,buffer_row)
 
            # for spectra assays
            if 'wavelength' in inputs:
        
                complex_fluorescence_data = platereader.select_data(data, inputs['section'], protein_row, wavelength = '%s' %inputs['wavelength'])
                ligand_fluorescence_data = platereader.select_data(data, inputs['section'], buffer_row, wavelength = '%s' %inputs['wavelength'])

            # for single wavelength assays
            else:
                
                complex_fluorescence_data = platereader.select_data(data, inputs['section'], protein_row)
                ligand_fluorescence_data = platereader.select_data(data, inputs['section'], buffer_row)
                
            complex_fluorescence[name] = reorder2list(complex_fluorescence_data,well)
            ligand_fluorescence[name] = reorder2list(ligand_fluorescence_data,well) 

    return [complex_fluorescence, ligand_fluorescence]

 

{'fraction_non_alphanumeric': 0.23711066931742877, 'fraction_numerical': 0.006229290921139828, 'mean_word_length': 3.182926829268293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 9}, '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': '2715902', 'n_tokens_mistral': 2141, 'n_tokens_neox': 1895, 'n_words': 439}