예제 #1
0
def select_by(population, infile, outfile, nval, val):
    print(infile)
    rows = qlibs.get_rows(infile)
    header = 1000
    text = ""
    posgs = -1
    for i in range(len(rows)):
        cols = rows[i].split(";")
        if len(cols) > 1:
            if header == 1000:
                text = rows[i] + ("\n")
                header = i
                hcols = rows[i].split(";")
                posgs = qlibs.find(nval, hcols)
                if posgs == -1:
                    posgs = qlibs.find(nval.replace('"', ''), hcols)
                    if posgs == -1:
                        qlibs.trace("selectBy", infile, population)
                        return
            if i > header:
                if cols[posgs] == val: text = text + rows[i] + "\n"
    fout = open(outfile, "w")
    fout.write(text)
    fout.close()
    return
예제 #2
0
def get_genes(population, datafile, xname, yname):
    rows = qlibs.get_rows(datafile)
    header = False
    x = []
    y = []
    xcol = -1
    ycol = -1
    prev = ""
    id = 0
    for row in rows:
        cols = row.split(";")
        if len(cols) > 1: 
            if header == False:
                xcol = qlibs.find(xname, cols)
                if  xcol >= 0: header = True
                ycol = qlibs.find(yname, cols)
                if  ycol >= 0: header = True
            else:
                if cols[xcol] != prev: 
                    id = id + 1
                    prev = cols[xcol]                    
                x.append(id)
                if cols[ycol].replace(",","").replace("-","").isdecimal() == True: y.append(float(cols[ycol].replace(",",".")))
                else:
                    y.append(0)
                    qlibs.trace("graph_fields" + yname, datafile + "\n" + str(cols), population)
    return [x, y]
예제 #3
0
def select_score(population, infile, outfile, nval, rel, threshold):
    print(infile)
    rows = qlibs.get_rows(infile)
    header = 1000
    text = ""
    posgs = -1
    for i in range(len(rows)):
        cols = rows[i].split(";")
        if len(cols) > 1:
            if header == 1000:
                text = rows[i] + ("\n")
                header = i
                hcols = rows[i].split(";")
                posgs = qlibs.find(nval, hcols)
                if posgs == -1:
                    posgs = qlibs.find(nval.replace('"', ''), hcols)
                    if posgs == -1:
                        qlibs.trace("selectS", infile, population)
                        return
            if i > header:
                if rel == "greater_than":
                    if int(cols[posgs]) >= threshold:
                        text = text + rows[i] + "\n"
                if rel == "less_than":
                    if int(cols[posgs]) <= threshold:
                        text = text + rows[i] + "\n"
                if rel == "equal_to":
                    if int(cols[posgs]) == threshold:
                        text = text + rows[i] + "\n"
    fout = open(outfile, "w")
    fout.write(text)
    fout.close()
    return
예제 #4
0
def get_scores(population, datafile, nscore):
    rows = qlibs.get_rows(datafile)
    header = False
    result = []
    ncol = -1
    for row in rows:
        cols = row.split(";")
        if len(cols) > 1: 
            if header == False:
                ncol = qlibs.find(nscore, cols)
                if  ncol >= 0: header = True
                else:
                    ncol = qlibs.find(nscore.replace('"',''), cols)
                    if  ncol >= 0: header = True
            else:
                if cols[ncol].isnumeric() == True: result.append(int(cols[ncol]))
                else: qlibs.trace("graph_freq", datafile + "\n" + str(cols), population)
    return result
예제 #5
0
def getlost_fromerrors(infile, population, set):
    datadir = qlibs.get_datadir()
    outdir = datadir + "Lost/" + set + "/"
    outfile = outdir + "/declost_" + set + ".csv"
    qlibs.create_path(outdir)
    rows = qlibs.get_rows(infile)
    text = ""
    for row in rows:
        cols = row.split("\t")
        if len(cols) > 1:
            codebuf = cols[1]
            gene = cols[0]
            buf = codebuf.split(".")
            if int(buf[1]) > 1: 
                code = buf[0] + "." + str(int(buf[1]) - 1)
                text += code + ";" + gene + ";\n"
    ft = open(outfile, "a")
    ft.write(text)
    ft.close()
    return 
예제 #6
0
def getlost(infile, population, set):
    datadir = qlibs.get_datadir()
    outdir = datadir + "Lost/" + set + "/"
    outfile = outdir + "/lost_" + set + ".csv"
    qlibs.create_path(outdir)
    rows = qlibs.get_rows(infile)
    text = ""
    for row in rows:
        cols = row.split(";")
        if len(cols) > 1:
            code = cols[0]
            gene = cols[1]
            found = False
            indir = qlibs.get_datadir() + population + "/" + set + "/Text/"
            for region in os.listdir(indir):
                if os.path.isdir(indir + region):
                    datadir = indir + region + "/" + gene + "__" + code
                    if os.path.isdir(datadir):
                        found = True
            if found == False: text += code + ";" + gene + ";\n"
    ft = open(outfile, "w")
    ft.write(text)
    ft.close()
    return