Exemplo n.º 1
0
def parse_kmer_file(filename, kmer_col, weight_col, header=True, sep='\t'):
    """Parse a columnar file to build trinucleotide matrix.
import bz2 as _bz2
import gzip as _gzip

    Parameters
    ----------
    filename : str
        Path to the file to parse
    kmer_col : int
        0-based integer column number for the kmer column
    weight_col : int
        0-based integer column number for the weight column
    header : bool
        If True, ignore first line
    sep : str
        Column to split the file on

    Returns
    -------
    trinucleotide_weights : dict
        {trinucleotide1: {trinucleotide2: weight_change}}
        weight_change is trinucleotide2-trinucleotide1, or what the weight
        change would be if going from trinucleotide2 to trinucleotide1
    """
    kmers = []
    with _open_zipped(filename) as fin:
        if header:
            fin.readline()
        for l in fin:
            f = l.strip().split(sep)
            kmers.append((f[kmer_col], flt(f[weight_col])))
    return _scan.get_weights(kmers)
Exemplo n.º 2
0

sys.argv = filter(None, sys.argv)
if len(sys.argv) < 2:
    print "USE: re_config.py CONF DIR_CONF"
    sys.exit(0)
conf1 = sys.argv[1]
dir_cnf = sys.argv[2]

root_dir = sycallo("echo $FIT3DP_PATH") + "/.."
#print root_dir
root_dirn = root_dir.replace(" ", "\ ")
f1 = open(dir_cnf + "/" + conf1, "r")
f1a = open(dir_cnf + "/" + conf1 + "_n", "w")
#print  dir_cnf+"/"+conf1+"_n"
cont = 0
for line in f1:
    cont = cont + 1
    if cont == 4:
        val = flt(line.replace("\n", ""))
    if cont >= 5 and cont <= 5 + val - 1:
        data = line.replace("\n", "").split(" ")
        data = filter(None, data)
        #print line.replace("\n","")
        dir1 = root_dir + "/" + data[3]
        dir2 = root_dir + "/" + data[5]
        f1a.write(data[0] + " " + data[1] + " " + data[2] + " " + dir1 + " " +
                  data[4] + " " + dir2 + " " + data[6] + " " + data[7] + "\n")
    else:
        f1a.write(line)
f1a.close()
Exemplo n.º 3
0
    
def sycall(comand):
    import os
    linp=comand
    print linp+" | PROCESSING"
    flog.write(linp+"\n")
    os.system(comand)
    print "DONE"

sys.argv=filter(None,sys.argv)        
if len(sys.argv) < 1:
    print "USE: ana_dingle.py NAME"
    sys.exit(0)

n_proc=5
vel_light=flt(299792.458)
plot=2 
plot_rss=0

VER="v1_3_2"
VER="MPL-5"
DIR_DATA="/Users/hjibarram/Dropbox/MaNGA_python/ana_single/disk-d/sanchez/ppak/legacy/DATA/SSP/MaNGA_lin"
DIR_DATA_OUT="/Users/hjibarram/Dropbox/MaNGA_python/ana_single/disk-b/manga/data/"+VER+"/MaNGA_lin_ana"
DIR_PLOTS="/Users/hjibarram/Dropbox/MaNGA_python/ana_single/home/manga/MaNGA_figs"
max_size=10
frac=0.9
#template="home/sanchez/ppak/legacy/gsd61_156.fits"
#temp_2="disk-b/sanchez/ppak/legacy/miles_2.fits"
#temp_3="home/sanchez/ppak/legacy/gsd61_12.fits"
#temp_4="disk-b/sanchez/ppak/legacy/miles_2_gas.fits"
#temp_5="disk-b/sanchez/ppak/legacy/templates/ssp_lib.4.fits"
Exemplo n.º 4
0
def parse_pidata(pifile):
    " parse raspberrypi data file from JHO"
    df = pd.read_csv(pifile, delimiter=";")

    for i, d in enumerate(df[df.columns[2]]):
        if "[" in d:
            istart = i
            break

    data = []
    tmelar = []
    tme = flt(0.0)
    for d, t in zip(df.iloc[istart:, 2], df.iloc[istart:, 0]):
        tmel = tme
        tme += flt(0.2)
        tme = np.round(tme, 1)
        if isinstance(d, float) and np.isnan(d):
            continue
        if "*" in d or "#" in d or "L" in d:
            tme -= flt(0.2)
            tme = np.round(tme, 1)
            continue
        if "start" in d or "Connect" in d:
            continue
        st = d.replace("[", "").replace("]", "").split(",")
        nums = []
        for s in st:
            if "None" not in s:
                nums.append(float(s))
            else:
                nums.append(np.nan)
        if any(nums) == 0.0:
            continue
        dt = datetime.strptime(t, "%Y-%m-%d %H:%M:%S")
        deltat = (dt - data[0][-1]).total_seconds() if data else 0.0
        if int(tmel) != int(deltat):
            tme = deltat

        data.append(nums + [tmel, dt])

    data = np.array(data)

    fs2kts = 0.592484
    ft2m = 0.3048
    ddict = {
        "altitude": {
            "units": "ft",
            "values": ay(-data[:, 0], dtype=flt)
        },
        "heading": {
            "units": "radians",
            "values": ay(data[:, 1], dtype=flt)
        },
        "speed": {
            "units": "kts",
            "values": ay(data[:, 2] * fs2kts, dtype=flt)
        },
        "pitch": {
            "units": "radians",
            "values": ay(data[:, 3], dtype=flt)
        },
        "roll": {
            "units": "radians",
            "values": ay(data[:, 4], dtype=flt)
        },
        "pressure": {
            "units": "bar",
            "values": ay(data[:, 5], dtype=flt)
        },
        "rpm": {
            "units": "RPM",
            "values": ay(data[:, 6], dtype=flt)
        },
        "ecuvoltage": {
            "units": "V",
            "values": ay(data[:, 7], dtype=flt)
        },
        "cht1": {
            "units": "C",
            "values": ay(data[:, 8], dtype=flt)
        },
        "cht2": {
            "units": "C",
            "values": ay(data[:, 9], dtype=flt)
        },
        "fuelflow": {
            "units": "ml/min",
            "values": ay(data[:, 10], dtype=flt)
        },
        "totalfuel": {
            "units": "ml",
            "values": ay(data[:, 11], dtype=flt)
        },
        "gpse": {
            "units": "degrees",
            "values": ay(data[:, 12], dtype=flt)
        },
        "gpsn": {
            "units": "degrees",
            "values": ay(data[:, 13], dtype=flt)
        },
        "voltage": {
            "units": "V",
            "values": ay(data[:, 14], dtype=flt)
        },
        "servovolt": {
            "units": "V",
            "values": ay(data[:, 15], dtype=flt)
        },
        "fuelpresence": {
            "units": "-",
            "values": ay(data[:, 16], dtype=flt)
        },
        "payloadtemp": {
            "units": "C",
            "values": ay(data[:, 17], dtype=flt)
        },
        "mptemp": {
            "units": "C",
            "values": ay(data[:, 18], dtype=flt)
        },
        "zaccel": {
            "units": "m/s^2",
            "values": ay(data[:, 19] * ft2m, dtype=flt)
        },
        "xaccel": {
            "units": "m/s^2",
            "values": ay(data[:, 20] * ft2m, dtype=flt)
        },
        "yaccel": {
            "units": "m/s^2",
            "values": ay(data[:, 21] * ft2m, dtype=flt)
        },
        "timeelapsed": {
            "units": "sec",
            "values": ay(data[:, 22], dtype=flt)
        },
        "time": {
            "units": "-",
            "values": data[:, 23]
        }
    }

    return ddict