=========================================================================
 回転行列（x 軸中心）

 @param:  phi  (回転量(rad))
 @param:  r    (回転行列)
 @return: r_a  (回転後)
=========================================================================
508637
def r_x(phi, r = Const::R_UNIT)
      r_a = Array.new

      begin
        s, c = Math.sin(phi), Math.cos(phi)
        a10 =   c * r[1][0] + s * r[2][0]
        a11 =   c * r[1][1] + s * r[2][1]
        a12 =   c * r[1][2] + s * r[2][2]
        a20 = - s * r[1][0] + c * r[2][0]
        a21 = - s * r[1][1] + c * r[2][1]
        a22 = - s * r[1][2] + c * r[2][2]
        r_a << r[0]
        r_a << [a10, a11, a12]
        r_a << [a20, a21, a22]
        return r_a
      rescue => e
        raise
      end
    end
483035
def LDRH(self, params):
        
        try:
            Ra, Rb, Rc = self.get_three_parameters(self.THREE_PARAMETER_WITH_BRACKETS, params)
        except iarm.exceptions.ParsingError:
            # LDRB Rn, [Rk] translates to an offset of zero
            Ra, Rb = self.get_two_parameters(r'\s*([^\s,]*),\s*\[([^\s,]*)\](,\s*[^\s,]*)*\s*', params)
            Rc = '#0'

        if self.is_immediate(Rc):
            self.check_arguments(low_registers=(Ra, Rb), imm6_2=(Rc,))

            def LDRH_func():
                # TODO does memory read up?
                if (self.register[Rb]) % 2 != 0:
                    raise iarm.exceptions.HardFault(
                        "Memory access not half word aligned; Register: {}  Immediate: {}".format(self.register[Rb],
                                                                                                  self.convert_to_integer(
                                                                                                      Rc[1:])))
                self.register[Ra] = 0
                for i in range(2):
                    self.register[Ra] |= (self.memory[self.register[Rb] + self.convert_to_integer(Rc[1:]) + i] << (8 * i))
        else:
            self.check_arguments(low_registers=(Ra, Rb, Rc))

            def LDRH_func():
                # TODO does memory read up?
                if (self.register[Rb] + self.register[Rc]) % 2 != 0:
                    raise iarm.exceptions.HardFault(
                        "Memory access not half word aligned; Register: {}  Immediate: {}".format(self.register[Rb],
                                                                                                  self.register[Rc]))
                self.register[Ra] = 0
                for i in range(2):
                    self.register[Ra] |= (self.memory[self.register[Rb] + self.register[Rc] + i] << (8 * i))

        return LDRH_func
1161060
def ccor(alt, r, h1, zh):
    
    e = (alt - zh) / h1
    if(e>70.0):
        return 1.0 # exp(0) # pragma: no cover
    elif (e < -70.0):
        return exp(r)
    ex = exp(e)
    e = r / (1.0 + ex)
    return exp(e)
1089833
def STR(self, params):
        
        Ra, Rb, Rc = self.get_three_parameters(self.THREE_PARAMETER_WITH_BRACKETS, params)

        if self.is_immediate(Rc):
            if Rb == 'SP' or Rb == 'FP':
                self.check_arguments(low_registers=(Ra,), imm10_4=(Rc,))
            else:
                self.check_arguments(low_registers=(Ra, Rb), imm7_4=(Rc,))

            def STR_func():
                for i in range(4):
                    self.memory[self.register[Rb] + self.convert_to_integer(Rc[1:]) + i] = ((self.register[Ra] >> (8 * i)) & 0xFF)
        else:
            self.check_arguments(low_registers=(Ra, Rb, Rc))

            def STR_func():
                for i in range(4):
                    self.memory[self.register[Rb] + self.register[Rc] + i] = ((self.register[Ra] >> (8 * i)) & 0xFF)

        return STR_func
836509
function getRxInfo(rxNode,prefix, optStop) {

    if( !rxNode ) return unit(prefix);
    if( optStop && rxNode === n_head(optStop) )  { // if we should match stop node, then pop the stop node 
                                                   // (usually its because we found a loop). Remove the node from the stack {n_tail(optStrop)},
                                                   // and procees with the next element 
      return getRxInfo(rxNode.nextNode,addOpt(rxNode, prefix),n_tail(optStop));
    }
    if(rxNode === DONE ) return unit(prefix);
    if( dot(rxNode) ) { // this is a node that concat of two regexp /AB/ => dot(A,B) - where A and B are regexp themselves
      //console.log("getMaskListOLD-dot");
      return getRxInfo(rxNode.left,prefix, optStop);
    } else if( or(rxNode) ) { //  /A|B/ => or(A,B)
        //console.log("getMaskListOLD - or");
        let LL = getRxInfo(rxNode.left,prefix,optStop);
        let RL = getRxInfo(rxNode.right,prefix,optStop);
        return merge(LL,RL); 
    }
    else if(zero_or_one(rxNode)) { // /A?/  => zero_or_one(A)
        if( optional ) {
          return optional(rxNode, prefix, getRxInfo, optStop );
        }  
        else return getRxInfo(rxNode.nextNode,addElem(prefix,HOLDER_ZERO_OR_ONE), optStop);
    }
    else if(zero_or_more(rxNode)) { //  / A* / => zero_or_more(A)        
        if( optional ){
           return optional(rxNode, prefix, getRxInfo,optStop );
        }
        else return getRxInfo(rxNode.nextNode,addElem(prefix,HOLDER_ZERO_OR_MORE),optStop);;
    }
    else if( matchable(rxNode) ) {
        let res = matchable(rxNode)(undefined);
        let v = res[1] || (mapper?mapper(rxNode,HOLDER_ANY):HOLDER_ANY);
        //console.log("getMaskListOLD", v);
        return getRxInfo(rxNode.nextNode,addElem(prefix,v),optStop);
    } 
    else if( boundary(rxNode) ) {
        return getRxInfo(rxNode.nextNode,prefix, optStop);
    } 
    return unit(prefix);
  }
966974
def p_pvar_expr(self, p):
        ''''''
        if len(p) == 2:
            p[0] = ('pvar_expr', (p[1], None))
        elif len(p) == 5:
            p[0] = ('pvar_expr', (p[1], p[3]))
884687
def _parse_args(self,freqsAngles=True,_firstFlip=False,*args):
        """"""
        from galpy.orbit import Orbit
        RasOrbit= False
        integrated= True #whether the orbit was already integrated when given
        if len(args) == 5 or len(args) == 3: #pragma: no cover
            raise IOError("Must specify phi for actionAngleIsochroneApprox")
        if len(args) == 6 or len(args) == 4:
            if len(args) == 6:
                R,vR,vT, z, vz, phi= args
            else:
                R,vR,vT, phi= args
                z, vz= 0., 0.
            if isinstance(R,float):
                os= [Orbit([R,vR,vT,z,vz,phi])]
                RasOrbit= True
                integrated= False
            elif len(R.shape) == 1: #not integrated yet
                os= [Orbit([R[ii],vR[ii],vT[ii],z[ii],vz[ii],phi[ii]]) for ii in range(R.shape[0])]
                RasOrbit= True
                integrated= False
        if isinstance(args[0],Orbit) \
                or (isinstance(args[0],list) and isinstance(args[0][0],Orbit)) \
                or RasOrbit:
            if RasOrbit:
                pass
            elif not isinstance(args[0],list):
                os= [args[0]]
                if len(os[0]._orb.vxvv) == 3 or len(os[0]._orb.vxvv) == 5: #pragma: no cover
                    raise IOError("Must specify phi for actionAngleIsochroneApprox")
            else:
                os= args[0]
                if len(os[0]._orb.vxvv) == 3 or len(os[0]._orb.vxvv) == 5: #pragma: no cover
                    raise IOError("Must specify phi for actionAngleIsochroneApprox")
            self._check_consistent_units_orbitInput(os[0])
            if not hasattr(os[0]._orb,'orbit'): #not integrated yet
                if _firstFlip:
                    for o in os:
                        o._orb.vxvv[1]= -o._orb.vxvv[1]
                        o._orb.vxvv[2]= -o._orb.vxvv[2]
                        o._orb.vxvv[4]= -o._orb.vxvv[4]
                [o.integrate(self._tsJ,pot=self._pot,
                             method=self._integrate_method,
                             dt=self._integrate_dt) for o in os]
                if _firstFlip:
                    for o in os:
                        o._orb.vxvv[1]= -o._orb.vxvv[1]
                        o._orb.vxvv[2]= -o._orb.vxvv[2]
                        o._orb.vxvv[4]= -o._orb.vxvv[4]
                        o._orb.orbit[:,1]= -o._orb.orbit[:,1]
                        o._orb.orbit[:,2]= -o._orb.orbit[:,2]
                        o._orb.orbit[:,4]= -o._orb.orbit[:,4]
                integrated= False
            ntJ= os[0].getOrbit().shape[0]
            no= len(os)
            R= nu.empty((no,ntJ))
            vR= nu.empty((no,ntJ))
            vT= nu.empty((no,ntJ))
            z= nu.zeros((no,ntJ))+10.**-7. #To avoid numpy warnings for
            vz= nu.zeros((no,ntJ))+10.**-7. #planarOrbits
            phi= nu.empty((no,ntJ))
            for ii in range(len(os)):
                this_orbit= os[ii].getOrbit()
                R[ii,:]= this_orbit[:,0]
                vR[ii,:]= this_orbit[:,1]
                vT[ii,:]= this_orbit[:,2]
                if this_orbit.shape[1] == 6:
                    z[ii,:]= this_orbit[:,3]
                    vz[ii,:]= this_orbit[:,4]
                    phi[ii,:]= this_orbit[:,5]
                else:
                    phi[ii,:]= this_orbit[:,3]
        if freqsAngles and not integrated: #also integrate backwards in time, such that the requested point is not at the edge
            no= R.shape[0]
            nt= R.shape[1]
            oR= nu.empty((no,2*nt-1))
            ovR= nu.empty((no,2*nt-1))
            ovT= nu.empty((no,2*nt-1))
            oz= nu.zeros((no,2*nt-1))+10.**-7. #To avoid numpy warnings for
            ovz= nu.zeros((no,2*nt-1))+10.**-7. #planarOrbits
            ophi= nu.empty((no,2*nt-1))
            if _firstFlip:
                oR[:,:nt]= R[:,::-1]
                ovR[:,:nt]= vR[:,::-1]
                ovT[:,:nt]= vT[:,::-1]
                oz[:,:nt]= z[:,::-1]
                ovz[:,:nt]= vz[:,::-1]
                ophi[:,:nt]= phi[:,::-1]
            else:
                oR[:,nt-1:]= R
                ovR[:,nt-1:]= vR
                ovT[:,nt-1:]= vT
                oz[:,nt-1:]= z
                ovz[:,nt-1:]= vz
                ophi[:,nt-1:]= phi
            #load orbits
            if _firstFlip:
                os= [Orbit([R[ii,0],vR[ii,0],vT[ii,0],z[ii,0],vz[ii,0],phi[ii,0]]) for ii in range(R.shape[0])]
            else:
                os= [Orbit([R[ii,0],-vR[ii,0],-vT[ii,0],z[ii,0],-vz[ii,0],phi[ii,0]]) for ii in range(R.shape[0])]
            #integrate orbits
            [o.integrate(self._tsJ,pot=self._pot,
                         method=self._integrate_method,
                         dt=self._integrate_dt) for o in os]
            #extract phase-space points along the orbit
            ts= self._tsJ
            if _firstFlip:
                for ii in range(no):
                    oR[ii,nt:]= os[ii].R(ts[1:]) #drop t=0, which we have
                    ovR[ii,nt:]= os[ii].vR(ts[1:]) #already
                    ovT[ii,nt:]= os[ii].vT(ts[1:]) # reverse, such that 
                    if os[ii].getOrbit().shape[1] == 6:
                        oz[ii,nt:]= os[ii].z(ts[1:]) #everything is in the 
                        ovz[ii,nt:]= os[ii].vz(ts[1:]) #right order
                    ophi[ii,nt:]= os[ii].phi(ts[1:]) #!
            else:
                for ii in range(no):
                    oR[ii,:nt-1]= os[ii].R(ts[1:])[::-1] #drop t=0, which we have
                    ovR[ii,:nt-1]= -os[ii].vR(ts[1:])[::-1] #already
                    ovT[ii,:nt-1]= -os[ii].vT(ts[1:])[::-1] # reverse, such that 
                    if os[ii].getOrbit().shape[1] == 6:
                        oz[ii,:nt-1]= os[ii].z(ts[1:])[::-1] #everything is in the 
                        ovz[ii,:nt-1]= -os[ii].vz(ts[1:])[::-1] #right order
                    ophi[ii,:nt-1]= os[ii].phi(ts[1:])[::-1] #!
            return (oR,ovR,ovT,oz,ovz,ophi)
        else:
            return (R,vR,vT,z,vz,phi)
724485
def circular(args):
    
    from jcvi.assembly.goldenpath import overlap

    p = OptionParser(circular.__doc__)
    p.add_option("--flip", default=False, action="store_true",
                 help="Reverse complement the sequence")
    p.set_outfile()
    opts, args = p.parse_args(args)

    if len(args) != 2:
        sys.exit(not p.print_help())

    fastafile, startpos = args
    startpos = int(startpos)
    key, seq = next(parse_fasta(fastafile))
    aseq = seq[startpos:]
    bseq = seq[:startpos]
    aseqfile, bseqfile = "a.seq", "b.seq"

    for f, s in zip((aseqfile, bseqfile), (aseq, bseq)):
        fw = must_open(f, "w")
        print(">{0}\n{1}".format(f, s), file=fw)
        fw.close()

    o = overlap([aseqfile, bseqfile])
    seq = aseq[:o.qstop] + bseq[o.sstop:]
    seq = Seq(seq)

    if opts.flip:
        seq = seq.reverse_complement()

    for f in (aseqfile, bseqfile):
        os.remove(f)

    fw = must_open(opts.outfile, "w")
    rec = SeqRecord(seq, id=key, description="")
    SeqIO.write([rec], fw, "fasta")
    fw.close()
385328
def __cutRaw(self, oiraw, maxLength):
        ''''''
        vec = []
        m = re.findall(u".*?[。？！；;!?]", oiraw)
        num, l, last = 0, 0, 0
        for i in range(len(m)):
            if(num + len(m[i]) >= maxLength):
                vec.append("".join(m[last:i]))
                last = i
                num = len(m[i])
            else:
                num += len(m[i])
            l += len(m[i])
        if(len(oiraw)-l + num >= maxLength):
            vec.append("".join(m[last:len(m)]))
            vec.append(oiraw[l:])
        else:
            vec.append(oiraw[l-num:])
        return vec
637786
function getArc(rx, ry, angle, largeArc, sweep, p0, p1) {
            var result = a2c(p0.x, p0.y, p1.x, p1.y, largeArc, sweep, rx, ry, angle);
            var path = [];

            if (result.length) {
                path.push({
                    x: result[0][0],
                    y: result[0][1],
                    onCurve: true
                });

                // 将三次曲线转换成二次曲线
                result.forEach(function (c, index) {
                    var q2Array = bezierCubic2Q2({
                        x: c[0],
                        y: c[1]
                    }, {
                        x: c[2],
                        y: c[3]
                    }, {
                        x: c[4],
                        y: c[5]
                    }, {
                        x: c[6],
                        y: c[7]
                    });

                    q2Array[0][2].onCurve = true;
                    path.push(q2Array[0][1]);
                    path.push(q2Array[0][2]);
                    if (q2Array[1]) {
                        q2Array[1][2].onCurve = true;
                        path.push(q2Array[1][1]);
                        path.push(q2Array[1][2]);
                    }
                });
            }

            return path;
        }
50401
function parse_RgceArea(blob, length, opts) {
	var w = 2;
	if(opts) {
		if(opts.biff >= 2 && opts.biff <= 5) return parse_RgceArea_BIFF2(blob, length, opts);
		else if(opts.biff == 12) w = 4;
	}
	var r=blob.read_shift(w), R=blob.read_shift(w);
	var c=parse_ColRelU(blob, 2);
	var C=parse_ColRelU(blob, 2);
	return { s:{r:r, c:c[0], cRel:c[1], rRel:c[2]}, e:{r:R, c:C[0], cRel:C[1], rRel:C[2]} };
}
648338
public static String replace(String str, int start, int end, String rp) {
        if (str == null || start < 0 || start > end || end >= str.length()) {
            throw new IllegalArgumentException("参数非法");
        }

        return str.substring(0, start) + rp + str.substring(end + 1);
    }
861199
function parse_RgceLocRel(blob, length, opts) {
	var biff = opts && opts.biff ? opts.biff : 8;
	if(biff >= 2 && biff <= 5) return parse_RgceLocRel_BIFF2(blob, length, opts);
	var r = blob.read_shift(biff >= 12 ? 4 : 2);
	var cl = blob.read_shift(2);
	var cRel = (cl & 0x8000) >> 15, rRel = (cl & 0x4000) >> 14;
	cl &= 0x3FFF;
	if(rRel == 1) while(r > 0x7FFFF) r -= 0x100000;
	if(cRel == 1) while(cl > 0x1FFF) cl = cl - 0x4000;
	return {r:r,c:cl,cRel:cRel,rRel:rRel};
}
531473
function vNumber(func, type, str, range) {
    let success   = true;
    let checkType = true;
    let errmsg;
    // 先验证类型
    if (!func(str)) {
      errmsg = localData.em_type({
        desc,
        str,
        type,
      });
      checkType = false;
      success = false;
    }
    // 再验证类型范围
    // if (range && range.min === undefined) {
    //   range.min = 0;
    // }
    if (range && (range.min === undefined || range.min < -NUMBER_MAX)) {
      range.min = -NUMBER_MAX;
    }
    if (range && (range.max === undefined || range.max > NUMBER_MAX)) {
      range.max = NUMBER_MAX;
    }
    if (success && checkType && range && (range.min !== undefined || range.max !== undefined)) {
      if (range && range.min !== undefined && range.min > Number(str)) {
        success = false;
      }
      if (success && range && range.max !== undefined && range.max < Number(str)) {
        success = false;
      }
      if (!success) {
        errmsg = localData.em_minmax({
          desc,
          type,
          opDesc: 'value',
          minOp : '>=',
          min   : range.min,
          maxOp : '<=',
          max   : range.max,
        });
      }
    }
    return { success, errmsg };
  }
1058377
function fromAlphabet(str, alphabet) {
				var base = alphabet.length;
				var pos = 0;
				var num = 0;

				for (let chr of str) {
					let at = alphabet.indexOf(chr);
					if (at === -1) return NaN; // 因为返回的类型都是数字，所以这里直接返回 NaN
					num += Math.pow(base, pos) * at;
					pos++;
				}

				return num;
			}
609741
function promiseGenerator(arr) {
  const data = [];
  const last = Symbol('last');
  
  // 添加迭代队列，以获取最后一次的promise执行结果
  arr.push(last);

  return arr.reduce((sum, value, index) => {
    return sum.then((result) => {
      // 忽略初始数据，即Promise.resolve()的返回数据
      if (index !== 0) data.push(result);

      // 如果到最后一个节点，则完成迭代，返回总体数据
      if (value === last) return data;

      return value();
    })
  }, Promise.resolve())
}
1293581
def _func(a, p, r, v):
    
    # eq. 2.3
    f = a[0]*math.log(r-1.) + \
        a[1]*math.log(r-1.)**2 + \
        a[2]*math.log(r-1.)**3 + \
        a[3]*math.log(r-1.)**4

    # eq. 2.7 and 2.8 corrections
    if r == 3:
        f += -0.002 / (1. + 12. * _phi(p)**2)

        if v <= 4.364:
            f += 1./517. - 1./(312.*(v,1e38)[np.isinf(v)])
        else:
            f += 1./(191.*(v,1e38)[np.isinf(v)])

    return -f