Convert #RRGGBBAA to an (R, G, B, A) tuple
491508
def string2rgba(cls, colorstring):
        
        colorstring = colorstring.strip()
        if colorstring[0] == '#':
            colorstring = colorstring[1:]
        if len(colorstring) < 6:
            raise ValueError("input #%s is not in #RRGGBB format" % colorstring)
        r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:6]
        a = 'ff'
        if len(colorstring) > 6:
            a = colorstring[6:8]
        r, g, b, a = [int(n, 16) for n in (r, g, b, a)]
        return (r, g, b, a)
1109845
function parse_PtgArea(blob, length, opts) {
	var type = (blob[blob.l++] & 0x60) >> 5;
	var area = parse_RgceArea(blob, opts.biff >= 2 && opts.biff <= 5 ? 6 : 8, opts);
	return [type, area];
}
805465
function (m, u) {
        return [
            m[0][0] * u[0] + m[0][1] * u[1] + m[0][2] * u[2],
            m[1][0] * u[0] + m[1][1] * u[1] + m[1][2] * u[2],
            m[2][0] * u[0] + m[2][1] * u[1] + m[2][2] * u[2]
        ];
    }
1001812
def xrify_tuples(self, tup):
        """"""
        return xr.DataArray(tup,
                            dims=['bands'],
                            coords={'bands': self.data['bands']})
809046
private function rgbToHex(int $r, int $g, int $b): string
    {
        return sprintf('#%02x%02x%02x', $r, $g, $b);
    }
616696
@SuppressWarnings("unchecked")
    public static <T1, T2, T3> Tuple3<T1, T2, T3>[] zip(T1[] arr1, T2[] arr2, T3[] arr3) {
        int resultSize = _max(arr1.length, arr2.length, arr3.length);
        Tuple3[] result = new Tuple3[resultSize];

        for (int i = 0; i < resultSize; i++)
            result[i] = tuple(next(arr1, i), next(arr2, i), next(arr3, i));

        return result;
    }
1332761
def tuple_to_string(prog_tuple):
    """"""
    (roman, acc, suff) = prog_tuple
    if acc > 6:
        acc = 0 - acc % 6
    elif acc < -6:
        acc = acc % 6
    while acc < 0:
        roman = 'b' + roman
        acc += 1
    while acc > 0:
        roman = '#' + roman
        acc -= 1
    return roman + suff
994112
def colorRGB(r, g, b):
        
        return (float(r / 255), float(g / 255), float(b / 255))
1052152
function parse_PtgRefN(blob, length, opts) {
	var type = (blob[blob.l] & 0x60)>>5;
	blob.l += 1;
	var loc = parse_RgceLocRel(blob, 0, opts);
	return [type, loc];
}
242898
def parse_vtrgb(path='/etc/vtrgb'):
    '''  '''
    palette = ()
    table = []
    try:
        with open(path) as infile:
            for i, line in enumerate(infile):
                row = tuple(int(val) for val in line.split(','))
                table.append(row)
                if i == 2:  # failsafe
                    break

        palette = tuple(zip(*table))  # swap rows to columns

    except IOError as err:
        palette = color_tables.vga_palette4

    return palette
940582
def HTMLColorToRGB(colorstring):
    
    colorstring = colorstring.strip()
    if colorstring[0] == '#':
        colorstring = colorstring[1:]
    if len(colorstring) != 6:
        raise ValueError(
            "input #{0} is not in #RRGGBB format".format(colorstring))
    r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:]
    r, g, b = [int(n, 16) for n in (r, g, b)]
    return (r, g, b)
380472
def UV_B(Bg,gw):
    
    UV = []
    p = Bwidth(gw)
    pp = 2**p
    while p:
        pp = pp>>1
        p = p-1
        if Bg&pp:
            uv = B012(p,gw-1)
            UV.append(uv)
    return UV
277183
def rs_generator_poly_all(max_nsym, fcr=0, generator=2):
    ''''''
    g_all = {}
    g_all[0] = g_all[1] = [1]
    for nsym in xrange(max_nsym):
        g_all[nsym] = rs_generator_poly(nsym, fcr, generator)
    return g_all
60460
def makeTrp(segID, N, CA, C, O, geo):
    ''''''
    ##R-Group
    CA_CB_length=geo.CA_CB_length
    C_CA_CB_angle=geo.C_CA_CB_angle
    N_C_CA_CB_diangle=geo.N_C_CA_CB_diangle

    CB_CG_length=geo.CB_CG_length
    CA_CB_CG_angle=geo.CA_CB_CG_angle
    N_CA_CB_CG_diangle=geo.N_CA_CB_CG_diangle

    CG_CD1_length=geo.CG_CD1_length
    CB_CG_CD1_angle=geo.CB_CG_CD1_angle
    CA_CB_CG_CD1_diangle=geo.CA_CB_CG_CD1_diangle

    CG_CD2_length=geo.CG_CD2_length
    CB_CG_CD2_angle=geo.CB_CG_CD2_angle
    CA_CB_CG_CD2_diangle=geo.CA_CB_CG_CD2_diangle
    
    CD1_NE1_length=geo.CD1_NE1_length
    CG_CD1_NE1_angle=geo.CG_CD1_NE1_angle
    CB_CG_CD1_NE1_diangle=geo.CB_CG_CD1_NE1_diangle

    CD2_CE2_length=geo.CD2_CE2_length
    CG_CD2_CE2_angle=geo.CG_CD2_CE2_angle
    CB_CG_CD2_CE2_diangle=geo.CB_CG_CD2_CE2_diangle

    CD2_CE3_length=geo.CD2_CE3_length
    CG_CD2_CE3_angle=geo.CG_CD2_CE3_angle
    CB_CG_CD2_CE3_diangle=geo.CB_CG_CD2_CE3_diangle

    CE2_CZ2_length=geo.CE2_CZ2_length
    CD2_CE2_CZ2_angle=geo.CD2_CE2_CZ2_angle
    CG_CD2_CE2_CZ2_diangle=geo.CG_CD2_CE2_CZ2_diangle

    CE3_CZ3_length=geo.CE3_CZ3_length
    CD2_CE3_CZ3_angle=geo.CD2_CE3_CZ3_angle
    CG_CD2_CE3_CZ3_diangle=geo.CG_CD2_CE3_CZ3_diangle

    CZ2_CH2_length=geo.CZ2_CH2_length
    CE2_CZ2_CH2_angle=geo.CE2_CZ2_CH2_angle
    CD2_CE2_CZ2_CH2_diangle=geo.CD2_CE2_CZ2_CH2_diangle

    carbon_b= calculateCoordinates(N, C, CA, CA_CB_length, C_CA_CB_angle, N_C_CA_CB_diangle)
    CB= Atom("CB", carbon_b, 0.0 , 1.0, " "," CB", 0,"C")
    carbon_g= calculateCoordinates(N, CA, CB, CB_CG_length, CA_CB_CG_angle, N_CA_CB_CG_diangle)
    CG= Atom("CG", carbon_g, 0.0, 1.0, " ", " CG", 0, "C")
    carbon_d1= calculateCoordinates(CA, CB, CG, CG_CD1_length, CB_CG_CD1_angle, CA_CB_CG_CD1_diangle)
    CD1= Atom("CD1", carbon_d1, 0.0, 1.0, " ", " CD1", 0, "C")
    carbon_d2= calculateCoordinates(CA, CB, CG, CG_CD2_length, CB_CG_CD2_angle, CA_CB_CG_CD2_diangle)
    CD2= Atom("CD2", carbon_d2, 0.0, 1.0, " ", " CD2", 0, "C")
    nitrogen_e1= calculateCoordinates(CB, CG, CD1, CD1_NE1_length, CG_CD1_NE1_angle, CB_CG_CD1_NE1_diangle)
    NE1= Atom("NE1", nitrogen_e1, 0.0, 1.0, " ", " NE1", 0, "N")
    carbon_e2= calculateCoordinates(CB, CG, CD2, CD2_CE2_length, CG_CD2_CE2_angle, CB_CG_CD2_CE2_diangle)
    CE2= Atom("CE2", carbon_e2, 0.0, 1.0, " ", " CE2", 0, "C")
    carbon_e3= calculateCoordinates(CB, CG, CD2, CD2_CE3_length, CG_CD2_CE3_angle, CB_CG_CD2_CE3_diangle)
    CE3= Atom("CE3", carbon_e3, 0.0, 1.0, " ", " CE3", 0, "C")

    carbon_z2= calculateCoordinates(CG, CD2, CE2, CE2_CZ2_length, CD2_CE2_CZ2_angle, CG_CD2_CE2_CZ2_diangle)
    CZ2= Atom("CZ2", carbon_z2, 0.0, 1.0, " ", " CZ2", 0, "C")

    carbon_z3= calculateCoordinates(CG, CD2, CE3, CE3_CZ3_length, CD2_CE3_CZ3_angle, CG_CD2_CE3_CZ3_diangle)
    CZ3= Atom("CZ3", carbon_z3, 0.0, 1.0, " ", " CZ3", 0, "C")

    carbon_h2= calculateCoordinates(CD2, CE2, CZ2, CZ2_CH2_length, CE2_CZ2_CH2_angle, CD2_CE2_CZ2_CH2_diangle)
    CH2= Atom("CH2", carbon_h2, 0.0, 1.0, " ", " CH2", 0, "C")
    
    ##Create Residue DS
    res= Residue((' ', segID, ' '), "TRP", '    ')
    res.add(N)
    res.add(CA)
    res.add(C)
    res.add(O)
    res.add(CB)
    res.add(CG)
    res.add(CD1)
    res.add(CD2)

    res.add(NE1)
    res.add(CE2)
    res.add(CE3)

    res.add(CZ2)
    res.add(CZ3)

    res.add(CH2)
    return res
733603
def _broadcast_shapes(s1, s2):
    """"""

    n1 = len(s1)
    n2 = len(s2)
    n = max(n1, n2)
    res = [1] * n

    for i in range(n):
        if i >= n1:
            c1 = 1
        else:
            c1 = s1[n1-1-i]

        if i >= n2:
            c2 = 1
        else:
            c2 = s2[n2-1-i]

        if c1 == 1:
            rc = c2
        elif c2 == 1 or c1 == c2:
            rc = c1
        else:
            raise ValueError('array shapes %r and %r are not compatible' % (s1, s2))

        res[n-1-i] = rc

    return tuple(res)
150270
function tuple4Of(a, b, c, d) {
    var self = getInstance(this, tuple4Of);
    self.types = rest(arguments);
    return self;
}
1001184
public static function rgbToHsl($r, $g, $b)
    {
        $r /= 255;
        $g /= 255;
        $b /= 255;
        $max = max($r, $g, $b);
        $min = min($r, $g, $b);
        $h = 0;
        $l = ($max + $min) / 2;
        $d = $max - $min;

        if ($d == 0) {
            $h = $s = 0; // achromatic
        } else {
            $s = (1 - abs(2 * $l - 1));
            switch ($max) {
                case $r:
                    $h = 60 * fmod((($g - $b) / $d), 6);
                    if ($b > $g) {
                        $h += 360;
                    }
                    break;
                case $g:
                    $h = 60 * (($b - $r) / $d + 2);
                    break;
                case $b:
                    $h = 60 * (($r - $g) / $d + 4);
                    break;
            }
        }

        return array(round($h, 2), round($s, 2), round($l, 2));
    }