<commit_before>#!/usr/bin/env python
DESC="""EPP used to create csv files for the bravo robot"""

from argparse import ArgumentParser
from genologics.lims import Lims
from genologics.config import BASEURI,USERNAME,PASSWORD
from genologics.epp import attach_file, EppLogger
import logging
import os
from genologics.entities import *

def main(lims, args):
    currentStep=Process(lims,id=args.pid)
    with open("bravo.csv", "w") as stupidContext:
        for art_tuple in currentStep.input_output_maps:
            if art_tuple[0]['uri'].type=='Analyte' and art_tuple[1]['uri'].type=='Analyte': 
                source_fc=art_tuple[0]['uri'].location[0].name
                source_well=art_tuple[0]['uri'].location[1]
                dest_fc=art_tuple[1]['uri'].location[0].name
                dest_well=art_tuple[1]['uri'].location[1]
                volume=calc_vol(art_tuple)
                stupidContext.write("{0},{1},{2},{3},{4}\n".format(source_fc, source_well, volume, dest_fc, dest_well)) 
    for out in currentStep.all_outputs():
        if out.name=="Bravo CSV File":
            attach_file(os.path.join(os.getcwd(), "bravo.csv"), out)
    logging.info("Work done")
def calc_vol(art_tuple):
    try:
        assert art_tuple[0]['uri'].udf['Conc. Units'] == "ng/ul"
        amount_ng=art_tuple[1]['uri'].udf['Amount taken (ng)']
        conc=art_tuple[0]['uri'].udf['Concentration']
        print amount_ng, conc, "{0:.2f}".format(amount_ng/conc)
        return "{0:.2f}".format(amount_ng/conc) 
    except KeyError as e:
        logging.error("The input artifact is lacking a field : {}".format(e)) 
    except AssertionError:
        logging.error("This script expects the concentration to be in ng/ul, this does not seem to be the case.")
    return "#ERROR#"

if __name__=="__main__":
    parser = ArgumentParser(description=DESC)
    parser.add_argument('--pid',
                        help='Lims id for current Process')
    parser.add_argument('--log',
                        help='Log file for runtime info and errors.')
    args = parser.parse_args()

    lims = Lims(BASEURI, USERNAME, PASSWORD)
    lims.check_version()
    main(lims, args)

<commit_msg>added required modifications<commit_after>#!/usr/bin/env python
DESC="""EPP used to create csv files for the bravo robot"""

from argparse import ArgumentParser
from genologics.lims import Lims
from genologics.config import BASEURI,USERNAME,PASSWORD
from genologics.epp import attach_file, EppLogger
import logging
import os
from genologics.entities import *

def main(lims, args):
    currentStep=Process(lims,id=args.pid)
    with open("bravo.csv", "w") as stupidContext:
        with open("bravo.log", "w") as logContext:
            for art_tuple in currentStep.input_output_maps:
                if art_tuple[0]['uri'].type=='Analyte' and art_tuple[1]['uri'].type=='Analyte': 
                    source_fc=art_tuple[0]['uri'].location[0].name
                    source_well=art_tuple[0]['uri'].location[1]
                    dest_fc=art_tuple[1]['uri'].location[0].name
                    dest_well=art_tuple[1]['uri'].location[1]
                    final_volume=art_tuple[1]['uri'].udf["Total Volume (uL)"]
                    volume=calc_vol(art_tuple, logContext)
                    stupidContext.write("{0},{1},{2},{3},{4},{5}\n".format(source_fc, source_well, volume, dest_fc, dest_well, final_volume)) 
    for out in currentStep.all_outputs():
        if out.name=="Bravo CSV File":
            attach_file(os.path.join(os.getcwd(), "bravo.csv"), out)
        if out.name=="Bravo Log":
            attach_file(os.path.join(os.getcwd(), "bravo.log"), out)
    logging.info("Work done")
def calc_vol(art_tuple, logContext):
    try:
        assert art_tuple[0]['uri'].udf['Conc. Units'] == "ng/ul"
        amount_ng=art_tuple[1]['uri'].udf['Amount taken (ng)']
        conc=art_tuple[0]['uri'].udf['Concentration']
        volume=amount_ng/conc
        if volume<4:
            logContext.write("WARN : Sample {0} located {1} {2}  has a LOW volume : {3}\n".format(art_tuple[1]['uri'].samples[0].name,
                art_tuple[0]['uri'].location[0].name,art_tuple[0]['uri'].location[1], volume))
        elif volume>art_tuple[1]['uri'].udf["Total Volume (uL)"]:
            logContext.write("WARN : Sample {0} located {1} {2}  has a HIGH volume : {3}, over {4}\n".format(art_tuple[1]['uri'].samples[0].name, 
                art_tuple[0]['uri'].location[0].name, art_tuple[0]['uri'].location[1], volume,art_tuple[1]['uri'].udf["Total Volume (uL)"] ))
        else:
            logContext.write("INFO : Sample {0} looks okay.\n".format(art_tuple[1]['uri'].samples[0].name))
        return "{0:.2f}".format(volume) 
    except KeyError as e:
        logContext.write("ERROR : The input artifact is lacking a field : {}".format(e)) 
    except AssertionError:
        logContext.write("ERROR : This script expects the concentration to be in ng/ul, this does not seem to be the case.")
    return "#ERROR#"

if __name__=="__main__":
    parser = ArgumentParser(description=DESC)
    parser.add_argument('--pid',
                        help='Lims id for current Process')
    parser.add_argument('--log',
                        help='Log file for runtime info and errors.')
    args = parser.parse_args()

    lims = Lims(BASEURI, USERNAME, PASSWORD)
    lims.check_version()
    main(lims, args)


{'fraction_non_alphanumeric': 0.1516781012423512, 'fraction_numerical': 0.013165214166512146, 'mean_word_length': 3.1019011406844106, 'pattern_counts': {'":': 5, '<': 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': '1835627', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1698, 'n_words': 367}