Esempio n. 1
0
    def rToFlux(line):
        # Examples of acceptable inputs:
        #   <flux forward="240.34" backward="5.0" net="[230:235.34:237.004]" exchange="5.0" />
        # Or:
        #   "240.34, 5.0, [230:235.34:237.004], 5.0"
        # Or:
        #   "240.34, 5.0, 235.34, 5.0"

        if isinstance(line, libsbml.XMLNode):
            forward = None
            backward = None
            net = None
            exchange = None
            if line.hasAttr("forward"):
                forward = line.getAttrValue("forward")
            if line.hasAttr("backward"):
                backward = line.getAttrValue("backward")
            if line.hasAttr("net"):
                net = line.getAttrValue("net")
            if line.hasAttr("exchange"):
                exchange = line.getAttrValue("exchange")
        else:
            v = line.split(',')
            if len(v) != 4:
                raise Exception('Wrong input for flux value from SBML')
            forward = v[0]
            backward = v[1]
            net = v[2]
            exchange = v[3]

        processed = []
        for item in [forward, backward, net, exchange]:
            # If they look like rangedNumbers, turn them into rangedNumber objects
            # before passing them to the flux instantiator.
            if isinstance(item, str):
                item = item.strip()
            if core.rangedNumber.looks_like_rangedNumber(item):
                item = core.rangedNumber.from_string(item)
            else:
                if utils.is_float(item):
                    item = float(item)
            processed.append(item)

        forward = processed[0]
        backward = processed[1]
        net = processed[2]
        exchange = processed[3]

        flux = core.flux(for_back_tup=(forward, backward),
                         net_exc_tup=(net, exchange))
        return flux
Esempio n. 2
0
def new_data():
    point = request.args.get('point', None)
    place = request.args.get('place', None)
    data_note = ""

    observer = request.args.get('observer', 'anon')
    obs_type = request.args.get('obs_type', 'REST')

    temp = request.args.get('temp')

    if not utilities.is_float(temp):
        return "No valid temperature provided"

    if point is None and place is not None:
        point = utilities.coord_from_str(place)
        data_note = f"point extrapolated from: {place}"

    if point is None:
        return "No location information provided"
    elif isinstance(point, str) and place is None:
        p = point.split(',')
        point = [p[0], p[1]]

    if point is not None:
        obs = db.upsert_observer(
            DB_CON,
            observer,
            obs_type,
            "",
        )

        temp = db.insert_data(DB_CON, obs, db.format_point(point), temp,
                              data_note)
        return f"Successfully recorded temperate observation #{temp[0]}"

    return "Unexpected parameter configuration, ignoring input"
def test_is_float():
    assert is_float('a') == False
    assert is_float(1.0) == True
    assert is_float(-1) == True
    assert is_float("'") == False