def align_one(ssw, qProfile, rNum, nRLen, nOpen, nExt, nFlag, nMaskLen):
"""
align one pair of sequences
@param qProfile query profile
@param rNum number array for reference
@param nRLen length of reference sequence
@param nFlag alignment flag
@param nMaskLen mask length
"""
res = ssw.ssw_align(qProfile, rNum, ct.c_int32(nRLen), nOpen, nExt, nFlag, 0, 0, nMaskLen)
nScore = res.contents.nScore
nScore2 = res.contents.nScore2
nRefBeg = res.contents.nRefBeg
nRefEnd = res.contents.nRefEnd
nQryBeg = res.contents.nQryBeg
nQryEnd = res.contents.nQryEnd
nRefEnd2 = res.contents.nRefEnd2
lCigar = [res.contents.sCigar[idx] for idx in range(res.contents.nCigarLen)]
nCigarLen = res.contents.nCigarLen
ssw.align_destroy(res)
return (nScore, nScore2, nRefBeg, nRefEnd, nQryBeg, nQryEnd, nRefEnd2, nCigarLen, lCigar)
python类c_int32()的实例源码
def _return_ctype(self):
""" Returns the associated ctype of a given datatype. """
_datatype_ctype = {
DataType.Bool: ctypes.c_uint8,
DataType.I8: ctypes.c_int8,
DataType.U8: ctypes.c_uint8,
DataType.I16: ctypes.c_int16,
DataType.U16: ctypes.c_uint16,
DataType.I32: ctypes.c_int32,
DataType.U32: ctypes.c_uint32,
DataType.I64: ctypes.c_int64,
DataType.U64: ctypes.c_uint64,
DataType.Sgl: ctypes.c_float,
DataType.Dbl: ctypes.c_double,
}
return _datatype_ctype[self]
def align_one(ssw, qProfile, rNum, nRLen, nOpen, nExt, nFlag, nMaskLen):
"""
this function calculate the score and other results from the alignment
"""
res = ssw.ssw_align(qProfile, rNum, ct.c_int32(nRLen), nOpen, nExt, nFlag, 0, 0, int(nMaskLen))
nScore = res.contents.nScore
nScore2 = res.contents.nScore2
nRefBeg = res.contents.nRefBeg
nRefEnd = res.contents.nRefEnd
nQryBeg = res.contents.nQryBeg
nQryEnd = res.contents.nQryEnd
nRefEnd2 = res.contents.nRefEnd2
lCigar = [res.contents.sCigar[idx] for idx in range(res.contents.nCigarLen)]
nCigarLen = res.contents.nCigarLen
ssw.align_destroy(res)
return nScore, nScore2, nRefBeg, nRefEnd, nQryBeg, nQryEnd, nRefEnd2, nCigarLen, lCigar
def GetDeviceIntProperty(dev_ref, key):
"""Reads int property from the HID device."""
cf_key = CFStr(key)
type_ref = iokit.IOHIDDeviceGetProperty(dev_ref, cf_key)
cf.CFRelease(cf_key)
if not type_ref:
return None
if cf.CFGetTypeID(type_ref) != cf.CFNumberGetTypeID():
raise errors.OsHidError('Expected number type, got {}'.format(
cf.CFGetTypeID(type_ref)))
out = ctypes.c_int32()
ret = cf.CFNumberGetValue(type_ref, K_CF_NUMBER_SINT32_TYPE,
ctypes.byref(out))
if not ret:
return None
return out.value
def get_count_rate(self, channel):
""" Get the current count rate for the
@param int channel: which input channel to read (0 or 1):
@return int: count rate in ps.
The hardware rate meters emply a gate time of 100ms. You must allow at
least 100ms after PH_Initialize or PH_SetDyncDivider to get a valid
rate meter reading. Similarly, wait at least 100ms to get a new
reading. The readings are corrected for the snyc devider setting and
deliver the external (undivided) rate. The gate time cannot be changed.
The readings may therefore be inaccurate of fluctuating when the rate
are very low. If accurate rates are needed you must perform a full
blown measurement and sum up the recorded events.
"""
if not ((channel !=0) or (channel != 1)):
self.log.error('PicoHarp: Count Rate could not be read out, '
'Channel does not exist.\nChannel has to be 0 or 1 '
'but {0} was passed.'.format(channel))
return -1
else:
rate = ctypes.c_int32()
self.check(self._dll.PH_GetCountRate(self._deviceID, channel, ctypes.byref(rate)))
return rate.value
def getSum(self, a, b):
"""
:type a: int
:type b: int
:rtype: int
"""
# https://leetcode.com/discuss/111582/java-simple-easy-understand-solution-with-explanation
# in Python this problem is much different because of the negative number
# https://leetcode.com/discuss/111705/one-positive-one-negative-case-successful-for-python-rules
import ctypes
sum = 0
carry = ctypes.c_int32(b)
while carry.value != 0:
sum = a ^ carry.value
carry = ctypes.c_int32(a & carry.value)
carry.value <<= 1
a = sum
return sum
def test_ready_argument_list2():
arg1 = numpy.array([1, 2, 3]).astype(numpy.float32)
arg2 = numpy.int32(7)
arg3 = numpy.float32(6.0)
arguments = [arg1, arg2, arg3]
cfunc = CFunctions()
output = cfunc.ready_argument_list(arguments)
print(output)
output_arg1 = numpy.ctypeslib.as_array(output[0], shape=arg1.shape)
assert output_arg1.dtype == 'float32'
assert isinstance(output[1], C.c_int32)
assert isinstance(output[2], C.c_float)
assert all(output_arg1 == arg1)
assert output[1].value == arg2
assert output[2].value == arg3
def hash(self, timestamp, latitude, longitude, altitude, authticket, sessiondata, requests):
self.location_hash = None
self.location_auth_hash = None
self.request_hashes = []
first_hash = self.hash32(authticket, seed=HASH_SEED)
location_bytes = d2h(latitude) + d2h(longitude) + d2h(altitude)
loc_hash = self.hash32(location_bytes, seed=first_hash)
self.location_auth_hash = ctypes.c_int32(loc_hash).value
loc_hash = self.hash32(location_bytes, seed=HASH_SEED)
self.location_hash = ctypes.c_int32(loc_hash).value
first_hash = self.hash64salt32(authticket, seed=HASH_SEED)
for request in requests:
req_hash = self.hash64salt64(request.SerializeToString(), seed=first_hash)
self.request_hashes.append(ctypes.c_int64(req_hash).value)
def generate_location_hash_by_seed(authticket, lat, lng, acc=5):
first_hash = hash32(authticket, seed=HASH_SEED)
location_bytes = d2h(lat) + d2h(lng) + d2h(acc)
loc_hash = loc_hash = hash32(location_bytes, seed=first_hash)
return ctypes.c_int32(loc_hash).value
def generate_location_hash(lat, lng, acc=5):
location_bytes = d2h(lat) + d2h(lng) + d2h(acc)
loc_hash = loc_hash = hash32(location_bytes, seed=HASH_SEED)
return ctypes.c_int32(loc_hash).value
def keyEvent(self, key, val):
"""
Generate a key or btn event
@param int axis key or btn event (KEY_* or BTN_*)
@param int val event value
"""
self._lib.uinput_key(self._fd,
ctypes.c_uint16(key),
ctypes.c_int32(val))
def axisEvent(self, axis, val):
"""
Generate a abs event (joystick/pad axes)
@param int axis abs event (ABS_*)
@param int val event value
"""
self._lib.uinput_abs(self._fd,
ctypes.c_uint16(axis),
ctypes.c_int32(val))
def relEvent(self, rel, val):
"""
Generate a rel event (move move)
@param int rel rel event (REL_*)
@param int val event value
"""
self._lib.uinput_rel(self._fd,
ctypes.c_uint16(rel),
ctypes.c_int32(val))
def scanEvent(self, val):
"""
Generate a scan event (MSC_SCAN)
@param int val scan event value (scancode)
"""
self._lib.uinput_scan(self._fd,
ctypes.c_int32(val))
def length(self) -> int:
"""Return the number of items in the T_ARRAY, T_MAP, T_FUNCTION and T_OBJECT sciter::value."""
if not self.get_type() in (VALUE_TYPE.T_ARRAY, VALUE_TYPE.T_MAP, VALUE_TYPE.T_FUNCTION, VALUE_TYPE.T_OBJECT):
raise AttributeError("'%s' has no attribute '%s'" % (self.get_type(), 'length'))
n = ctypes.c_int32()
ok = _api.ValueElementsCount(self, byref(n))
self._throw_if(ok)
return n.value
def num_ckt_elements():
"""This parameter will deliver the number of CktElements included in the active circuit."""
return dsslib.CircuitI(ctypes.c_int32(0), ctypes.c_int32(0))
def num_buses():
"""This parameter will deliver the number of buses included in the active circuit."""
return dsslib.CircuitI(ctypes.c_int32(1), ctypes.c_int32(0))
def num_nodes():
"""This parameter will deliver the number of nodes included in the active circuit."""
return dsslib.CircuitI(ctypes.c_int32(2), ctypes.c_int32(0))
def first_pc_element():
"""This parameter sets the first PCElement to be the active PCElement, as a result, this parameter will deliver the index of the active PCElement (ideally 1)."""
return dsslib.CircuitI(ctypes.c_int32(3), ctypes.c_int32(0))
def next_pc_element():
"""This parameter sets the next PCElement to be the active PCElement, as a result, this parameter will deliver the index of the active PCElement (if there is no more it will return a 0)."""
return dsslib.CircuitI(ctypes.c_int32(4), ctypes.c_int32(0))
def next_pd_element():
"""This parameter sets the next PDElement to be the active PDElement, as a result, this parameter will deliver the index of the active PDElement (if there is no more it will return a 0)."""
return dsslib.CircuitI(ctypes.c_int32(6), ctypes.c_int32(0))
def sample():
"""This parameter forces all meters and monitors to take a sample, returns 0."""
return dsslib.CircuitI(ctypes.c_int32(7), ctypes.c_int32(0))
def save_sample():
"""This parameter forces all meters and monitors to save their sample buffers, returns 0."""
return dsslib.CircuitI(ctypes.c_int32(8), ctypes.c_int32(0))
def set_active_nbus(index):
"""This parameter sets active the bus specified by index, which is compatible with the index delivered by AllBusNames, returns 0 it everything ok."""
return dsslib.CircuitI(ctypes.c_int32(9), ctypes.c_int32(index))
def first_element():
"""This parameter sets the first Element of the active class to be the active Element, as a result, this parameter will deliver the index of the active Element (0 if none)."""
return dsslib.CircuitI(ctypes.c_int32(10), ctypes.c_int32(0))
def update_storage():
"""This parameter forces all storage classes to update. Typically done after a solution."""
return dsslib.CircuitI(ctypes.c_int32(12), ctypes.c_int32(0))
def parent_pd_element():
"""This parameter sets parent PD Element, if any, to be the active circuit element and returns index > 0 if it fails or not applicable."""
return dsslib.CircuitI(ctypes.c_int32(13), ctypes.c_int32(0))
def end_of_time_step_update():
"""This parameter calls end of time step cleanup routine in solutionalgs.pas. Returns 0."""
return dsslib.CircuitI(ctypes.c_int32(14), ctypes.c_int32(0))
def capacity(c_start=0.0, c_increment=0.0):
"""This parameter returns the total capacity of the active circuit. Or this parameter it is necessary to specify the start and increment of the capacity in the arguments argument1 and argument2 respectively."""
return dsslib.CircuitF(ctypes.c_int32(0), ctypes.c_double(c_start), ctypes.c_double(c_increment))
def name():
"""This parameter returns the name of the active circuit."""
return dsslib.CircuitS(ctypes.c_int32(0), ''.encode('ascii')).decode('ascii')