예제 #1
0
def reactions_from_txt(enzyme_module, reactions_filepath):
    """Create reactions from a text file."""
    # Create ID map dict for reactions
    enzyme_module.id_map["reactions"] = {}

    # Read reactions from files
    with open(reactions_filepath, "r") as f:
        reaction_strings = [l.strip() for l in f.readlines()]

    for reaction_str in reaction_strings:
        # Split reaction ID from reaction formula
        orig_id, reaction_str = reaction_str.split(r": ")
        new_id = prefix_number_id(re.sub(r"\$", "_", orig_id))
        # Make EnzymeModuleReaction object and add to model
        reaction = EnzymeModuleReaction(id_or_reaction=new_id,
                                        enzyme_module_id=enzyme_module.id)
        enzyme_module.add_reactions([reaction])

        # Fix specie IDs in reaction string
        species_list = iconcat(
            *[s.split(r" + ") for s in reaction_str.strip().split(r" <=> ")])
        for specie_id in species_list:
            reaction_str = re.sub(
                specie_id.replace(r"[", r"\[").replace(r"]", r"\]"),
                enzyme_module.id_map["species"][specie_id], reaction_str, 1)
        # Build reaction from string.
        reaction.build_reaction_from_string(reaction_str)
        # Store ID mapping
        enzyme_module.id_map["reactions"][orig_id] = new_id

    return None
예제 #2
0
def main():

    x,y = 5,6
    a,b = 7,8

    # Incremental Add : x += y
    iAdd = operator.iadd(5, 6)
    print("iAdd: ", iAdd)

    # Incremental Concatenate
    iConCat = operator.iconcat("Hello", "World")
    print("iConCat:", iConCat)

    # Incremental Subtraction
    iSub = operator.isub(5, 6)
    print("iSub: ", iSub)

    # Incremental Multiplication
    iMul = operator.imul(5,6)
    print("iMul:", iMul)

    # Incremental Division
    iDiv = operator.itruediv(10, 5)
    print("iDiv: ", iDiv)

    # Incremental Modulus
    iMod = operator.imod(10, 6)
    print("iMod: ", iMod)

    # Incremental Exponential
    iPow = operator.ipow(2, 4)
    print("iPow: ", iPow)
예제 #3
0
 def test_inplace(self):
     #operator = self.module
     class C(object):
         def __iadd__     (self, other): return "iadd"
         def __iand__     (self, other): return "iand"
         def __ifloordiv__(self, other): return "ifloordiv"
         def __ilshift__  (self, other): return "ilshift"
         def __imod__     (self, other): return "imod"
         def __imul__     (self, other): return "imul"
         def __ior__      (self, other): return "ior"
         def __ipow__     (self, other): return "ipow"
         def __irshift__  (self, other): return "irshift"
         def __isub__     (self, other): return "isub"
         def __itruediv__ (self, other): return "itruediv"
         def __ixor__     (self, other): return "ixor"
         def __getitem__(self, other): return 5  # so that C is a sequence
     c = C()
     self.assertEqual(operator.iadd     (c, 5), "iadd")
     self.assertEqual(operator.iand     (c, 5), "iand")
     self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
     self.assertEqual(operator.ilshift  (c, 5), "ilshift")
     self.assertEqual(operator.imod     (c, 5), "imod")
     self.assertEqual(operator.imul     (c, 5), "imul")
     self.assertEqual(operator.ior      (c, 5), "ior")
     self.assertEqual(operator.ipow     (c, 5), "ipow")
     self.assertEqual(operator.irshift  (c, 5), "irshift")
     self.assertEqual(operator.isub     (c, 5), "isub")
     self.assertEqual(operator.itruediv (c, 5), "itruediv")
     self.assertEqual(operator.ixor     (c, 5), "ixor")
     self.assertEqual(operator.iconcat  (c, c), "iadd")
예제 #4
0
    def test_inplace(self):
        #operator = self.module
        class C(object):
            def __iadd__(self, other):
                return "iadd"

            def __iand__(self, other):
                return "iand"

            def __ifloordiv__(self, other):
                return "ifloordiv"

            def __ilshift__(self, other):
                return "ilshift"

            def __imod__(self, other):
                return "imod"

            def __imul__(self, other):
                return "imul"

            def __ior__(self, other):
                return "ior"

            def __ipow__(self, other):
                return "ipow"

            def __irshift__(self, other):
                return "irshift"

            def __isub__(self, other):
                return "isub"

            def __itruediv__(self, other):
                return "itruediv"

            def __ixor__(self, other):
                return "ixor"

            def __getitem__(self, other):
                return 5  # so that C is a sequence

        c = C()
        self.assertEqual(operator.iadd(c, 5), "iadd")
        self.assertEqual(operator.iand(c, 5), "iand")
        self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
        self.assertEqual(operator.ilshift(c, 5), "ilshift")
        self.assertEqual(operator.imod(c, 5), "imod")
        self.assertEqual(operator.imul(c, 5), "imul")
        self.assertEqual(operator.ior(c, 5), "ior")
        self.assertEqual(operator.ipow(c, 5), "ipow")
        self.assertEqual(operator.irshift(c, 5), "irshift")
        self.assertEqual(operator.isub(c, 5), "isub")
        self.assertEqual(operator.itruediv(c, 5), "itruediv")
        self.assertEqual(operator.ixor(c, 5), "ixor")
        self.assertEqual(operator.iconcat(c, c), "iadd")
def main():
    a = -1
    b = 5.0
    c = [1, 2, 3]
    d = ["a", "b", "c"]
    print("a = ", a)
    print("b = ", b)
    print("c = ", c)
    print("d = ", d)
    print()

    a = operator.iadd(a, b)
    print("a = iadd(a, b) =>", a)
    print()

    c = operator.iconcat(c, d)
    print("c = iconcat(c, d) =>", c)
예제 #6
0
    def to_dict(self, parsed_results):
        """This function standandlize the parsed results. It first reduces the
        collected parsed results into lists of tuples; then loads them as
        pandas.DataFrames whose columns represent p_keys.

        Parameters
        ----------
        parsed_results : iterable
            An iterable that contains parsed results generated by Parser.

        Returns
        ----------
        A dict, the keys of which are consistent with database tables; and
        the values of which are pandas.DataFrame.
        """
        tkeys = PMETA.keys()
        reduced_results = reduce(
            lambda x, y: {k: iconcat(x[k], y[k])
                          for k in tkeys}, parsed_results)
        dfs = {
            k: pd.DataFrame(reduced_results[k], columns=PMETA[k]['p_keys'])
            for k in tkeys
        }
        # drop duplicates mainly based on unique keys
        for k in tkeys:
            if k == 'full_user' or k == 'mentioned_user':
                dfs[k] = dfs[k].sort_values('updated_at', ascending=False)
            #
            # !IMPORTANT (ESPECIALLY FOR `ass_tweet` table)
            # Causion:
            # (1) The default missing values for pandas.DataFrame is
            # np.NAN, which is not compatible with SQL insertion in SQLAlchemy.
            # Thus a replace operation need to take.
            # (2) When missing values occurs, the dtype of a DataFrame would
            # be 'float' (either float32 or float64), which could truncate
            # the large numbers. Since version 24, pandas provide new data type
            # Int64 (CAPITAL I). Thus we need to convert it to this data type.
            #
            if k == 'ass_tweet':
                # replace np.NAN as None
                dfs[k] = dfs[k].astype('Int64')
                dfs[k].replace({pd.np.nan: None}, inplace=True)
            dfs[k] = dfs[k].drop_duplicates(PMETA[k]['pu_keys'], keep='first')
        return dfs
예제 #7
0
def operator_inplace():
    """
    we have inplace operators on operants.
    i += 1
    i -= 1
    i *= 1
    i /= 2
    i //= 2
    i %= 2
    i **= 2
    """
    a, b, c, d = -1, 5.0, [1, 2, 3], list('abc')
    print('a =', a)
    print('b =', b)
    print('c =', c)
    print('d =', d)
    # simple exampls
    print('a += b =>', operator.iadd(a, b))
    print('c += d =>', operator.iconcat(c, d))

    return
예제 #8
0
def run301_05():
    """
    inplace ops
    :return:
    """
    a = -1
    b = 5.0
    c = [1, 2, 3]
    d = ['a', 'b', 'c']

    print('a=', a)
    print('b=', b)
    print('c=', c)
    print('d=', d)
    print()

    a = iadd(a, b)
    print('iadd(a,b):', a)
    print()

    c = iconcat(c, d)
    print('iconcat(c,d)', c)
예제 #9
0
@create_time = 2018/6/5 0005 下午 19:51
"""
import operator as op

# 原地操作符 即in-place操作,x += y 等同于x=iadd(x, y),
# 如果复制给其他变量比如z = iadd(x, y)等同与z = x; z += y
a, b = 3, 4
c = [1, 2]
d = ['a', 'b']
print('a =', a)
print('b =', b)
print('c =', c)
print('d =', d)
a = op.iadd(a, b)
print('a = operator.iadd(a, b) =>', a)
c = op.iconcat(c, d)
print('c = operator.iconcat(c, d) =>', c)
print()

# operator模块最特别的特性之一就是获取方法的概念,获取方法是运行时构造的一些可回调对象
# 用来获取对象的属性或序列的内容,获取方法在处理迭代器或生成器序列的时候特别有用
# 它们引入的开销会大大降低lambda或Python函数的开销


# 获取属性
class MyObj(object):
    def __init__(self, arg):
        super(MyObj, self).__init__()
        self.arg = arg

    def __repr__(self):
예제 #10
0
##判断是否是序列类型
print operator.isSequenceType([1, 2, 3])
print operator.isSequenceType((1, 2, 3))

#将与自身的值相加之和的值赋给自身 同 +=
#但是不改变自身的值,返回值返回相加的结果
a = 0
b = operator.iadd(a, 2)
print a
print b

#将与自身序列相加的结果赋给自身 同 +=
#但是不改变自身的值,返回值返回相加的结果
a = [1, 2]
b = [3, 4]
c = operator.iconcat(a, b)
print c

#将与自身的值相减之和的值赋给自身 同 -=
#但是不改变自身的值,返回值返回相减的结果
a = 2
b = operator.isub(a, 1)
print a
print b

#将与自身的值相乘之和的值赋给自身 同 *=
#但是不改变自身的值,返回值返回相乘的结果
a = 4
b = operator.imul(a, 5)
print a
print b
예제 #11
0
 def storage_area(self):
     return [
         iconcat([str(s)
                  for s in i.storage.get_ancestors()], [str(i.storage)])
         for i in self.item_set.filter(area='se')
     ]
print(li)
operator.delitem(li, slice(1, 4))
print(li)
print(operator.getitem(li, slice(0, 2)))
s1 = "testing "
s2 = "operator"
print(operator.concat(s1, s2))
if (operator.contains(s1, s2)):
    print("Contains")
else:
    print("It doesn't")
a = 1
b = 0
print(operator.and_(a, b))
print(operator.or_(a, b))
print(operator.invert(a))

x = 10
y = 5
print(operator.iadd(x, y))
print(operator.isub(x, y))
print(operator.iconcat(s1, s2))
print(operator.imul(x, y))
print(operator.itruediv(x, y))
print(operator.imod(x, y))
print(operator.ixor(x, y))
print(operator.ipow(x, y))
print(operator.iand(x, y))
print(operator.ior(x, y))
print(operator.ilshift(x, y))
print(operator.irshift(x, y))
if math.isnan(math.nan):
    print("True : Not a number")
else:
    print("its a number")

if math.isinf(math.inf):
    print("True: infinite number")
else:
    print("not infinite number")
#------- Random related functions

mylist = ['purushotham', 'chandra', 'ravi']
print(random.randint(1, 5))
print(random.random())
print(random.choice(mylist))
random.shuffle(mylist)

#--- Number of seconds from EPOCH time i.e from Jan1st 1970
print(time.time())

print(date.fromtimestamp(1565335861.4913108))

#------------- operator(Inplace) related functions --------------------

print(operator.iadd(2, 3))
print(operator.isub(3, 2))
print(operator.imul(3, 2))
print(operator.itruediv(5, 3))
print(operator.imod(5, 3))
print(operator.iconcat('Purushotham', 'Reddy'))
예제 #14
0
##判断是否是序列类型
print operator.isSequenceType([1,2,3])
print operator.isSequenceType((1,2,3))

#将与自身的值相加之和的值赋给自身 同 += 
#但是不改变自身的值,返回值返回相加的结果
a = 0
b = operator.iadd(a,2)
print a
print b

#将与自身序列相加的结果赋给自身 同 +=
#但是不改变自身的值,返回值返回相加的结果
a = [1,2]
b = [3,4]
c = operator.iconcat(a,b)
print c

#将与自身的值相减之和的值赋给自身 同 -= 
#但是不改变自身的值,返回值返回相减的结果
a = 2
b = operator.isub(a,1)
print a
print b

#将与自身的值相乘之和的值赋给自身 同 *= 
#但是不改变自身的值,返回值返回相乘的结果
a = 4
b = operator.imul(a,5)
print a
print b
예제 #15
0
# Python in its definition provides methods to perform inplace operations,
# i.e doing assignment and computation in a single statement using “operator” module.
# x+=y is equivalent to x = operator.iadd(x,y)

import operator

x = 10
y = 20
x = operator.iadd(x, y)
print("The value after adding and assigning : ", end="")
print(x)

x = "Geeks"
y = "ForGeeks"

x = operator.iconcat(x, y)
print("The string after concatenation : ", end="")
print(x)

x = operator.isub(2, 3)
print("The value after subtracting and assigning : ", end="")
print(x)

x = operator.imul(10, 100)
print("The value after multiplying and assigning : ", end="")
print(x)

x = operator.itruediv(100, 20)
print("The value after dividing and assigning : ", end="")
print(x)
예제 #16
0
#Below are some examples for performing inplace operations.

"""1.iadd()- This function is used to assign and add the current value. This operation does “a+=b” operation. Assigning is not performed in case of immutable containers,
such as strings, numbers and tuples."""

import operator
a = 5
b = 3
print(operator.iadd(a, b))

"""2.iconcat()- This function is used to concat first string at the end of second"""

a = 'Virat'
b = 'Kohli'
print(operator.iconcat(a, b))

"""3. isub() :- This function is used to assign and subtract the current value. This operation does “a-=b” operation. Assigning is not performed in case of immutable
containers, such as strings, numbers and tuples."""

a = 19
b = 7
print(operator.isub(a, b))

"""4.imul() :- This function is used to assign and multiply the current value. This operation does “a*=b” operation. Assigning is not performed in case of immutable
containers, such as strings, numbers and tuples."""

a = 16
b = 6
print(operator.imul(a, b))
예제 #17
0
import operator

x = operator.iadd(2, 3)
print(" The value after adding and assigning : ", end=" ")
print(x)

y = "yashika"
z = " jotwani"

y = operator.iconcat(y, z)
print(" my name is : ", end="")
print(y)

##loops

for key, value in enumerate(['the ', 'big', 'bang', 'theory']):
    print(key, value)
    print(value, end=" ")

questions = ['name', 'color', 'shape']
answere = ['apple', 'red', 'a circle']

for questions, answere in zip(questions, answere):
    print("What is your {0}? I am {1}.".format(questions, answere))

lis = [1, 2, 3, 33, 4, 45, 55, 56, 666, 7, 2, 11, 2, 2, 3333, 33, 0]
print(" The list is reversed in the order :")

for i in reversed(lis):
    print(i, end=" ")
print("\n")
예제 #18
0
 def update_event(self, inp=-1):
     self.set_output_val(0, operator.iconcat(self.input(0), self.input(1)))