Commit 3fe25dc1 authored by Aflitos, Saulo Alves's avatar Aflitos, Saulo Alves
Browse files

allow change login of admin; local stats on vcf merger multicolumn; csv...

allow change login of admin; local stats on vcf merger multicolumn; csv renamer allows to not set name
parent e1c543f7
......@@ -11,6 +11,7 @@ data/
data2/
data3/
data4/
data5/
introgression_viewer.tgz
introgression_viewer.xz
static/FileSaver.js/demo/
......
......@@ -105,7 +105,7 @@ class encryption(object):
os.remove(self.rsa_private_key_file_name)
if ( os.path.exists( self.rsa_public_key_file_name2 ) ):
print "ssl key % exists. deleting" % self.rsa_public_key_file_name2
print "ssl key %s exists. deleting" % self.rsa_public_key_file_name2
os.remove(self.rsa_public_key_file_name2)
print "PUBLIC KEY %s OR PRIVATE KEY %s DOES NOT EXISTS. CREATING" % (self.rsa_private_key_file_name, self.rsa_public_key_file_name2)
......@@ -123,7 +123,7 @@ class encryption(object):
if ( os.path.exists( self.rsa_public_key_file_name3 ) ):
print "ssl key % exists. deleting" % self.rsa_public_key_file_name3
print "ssl key %s exists. deleting" % self.rsa_public_key_file_name3
os.remove(self.rsa_public_key_file_name3)
......
......@@ -149,7 +149,8 @@ def admin():
print "admin: has config - POST - action %s username %s password %s noonce %s security %s" % tuple([ str(x) for x in ( action, username, password, noonce, security ) ])
if username is not None and action is not None and noonce is not None and username != "admin" and "noonce" in session and noonce == session["noonce"]:
#if username is not None and action is not None and noonce is not None and username != "admin" and "noonce" in session and noonce == session["noonce"]:
if username is not None and action is not None and noonce is not None and "noonce" in session and noonce == session["noonce"]:
if action == "add":
print "admin: has config - POST. ADDING USER"
if password is None or generate_password_hash(username+noonce) == password:
......@@ -192,7 +193,8 @@ def admin():
session["noonce"] = gen_noonce()
print "new noonce", session["noonce"]
return render_template('admin.html', users=[x for x in sorted(get_users()) if x != "admin"], message=message, noonce=session["noonce"], app=app)
#return render_template('admin.html', users=[x for x in sorted(get_users()) if x != "admin"], message=message, noonce=session["noonce"], app=app)
return render_template('admin.html', users=[x for x in sorted(get_users())], message=message, noonce=session["noonce"], app=app)
#return app.send_static_file('login.html')
else:
......
......@@ -18,11 +18,18 @@ ${EX2} ${VCF}.list.csv ${LST} tg_ecotypeid name,othername,CS_number
"""
def get_translation(intbl, tbl_k, tbl_vs):
data = {}
atad = {}
col_names = None
tbl_k_id = None
tbl_v_ids = None
data = {}
atad = {}
no_name = False
if tbl_k is None or tbl_vs is None:
tbl_k = 0
tbl_vs = 1
no_name = True
col_names = None
tbl_k_id = None
tbl_v_ids = None
with open(intbl, 'rb') as fhd:
reader = csv.reader(fhd, delimiter=',', quotechar='"')
......@@ -34,13 +41,20 @@ def get_translation(intbl, tbl_k, tbl_vs):
if ln == 0: #header
print cols
assert tbl_k in cols, "key %s not in header %s" % (tbl_k, ", ".join(cols))
tbl_k_id = cols.index(tbl_k)
tbl_v_ids = []
for tbl_v in tbl_vs:
assert tbl_v in cols, "value %s not in header %s" % (tbl_v, ", ".join(cols))
tbl_v_ids.append( cols.index(tbl_v) )
if no_name:
tbl_k_id = tbl_k
tbl_v_ids = [ tbl_vs ]
else:
assert tbl_k in cols, "key %s not in header %s" % (tbl_k, ", ".join(cols))
tbl_k_id = cols.index(tbl_k)
tbl_v_ids = []
for tbl_v in tbl_vs:
assert tbl_v in cols, "value %s not in header %s" % (tbl_v, ", ".join(cols))
tbl_v_ids.append( cols.index(tbl_v) )
else:
k = cols[tbl_k_id]
......
......@@ -32,6 +32,7 @@ class vcf(object):
self.numRegs = 0
self.numRegsChrom = 0
self.stats = {}
self.statsC = {}
def setFhd(self, fhd):
self.fhd = fhd
......@@ -44,8 +45,9 @@ class vcf(object):
if register['chrom'] != self.lastChrom:
self.numRegsChrom -= 1
if self.lastChrom is not None:
sys.stdout.write(' Chrom {:14,d} Total {:14,d}\n'.format(self.numRegsChrom, self.numRegs))
print self.stats
sys.stdout.write('\nChrom {:14,d} Total {:14,d}\n'.format(self.numRegsChrom, self.numRegs))
print 'Chromosome Stats:', " ".join([ "{:s}: {:10,d}".format(*i) for i in sorted(self.statsC[self.lastChrom].items()) ])
print 'Global Stats :', " ".join([ "{:s}: {:10,d}".format(*i) for i in sorted(self.stats.items()) ])
self.fhd.flush()
sys.stdout.write('\nChromosome {0}\n'.format(register['chrom']))
......@@ -60,6 +62,13 @@ class vcf(object):
sys.stdout.write(' Chrom {:14,d} Total {:14,d}\n'.format(self.numRegsChrom, self.numRegs))
sys.stdout.flush()
def add_stat(self, chrom, k, v):
if chrom not in self.statsC:
self.statsC[chrom] = {}
self.stats [k] = self.stats .get(k, 0) + v
self.statsC[chrom][k] = self.statsC[chrom].get(k, 0) + v
def parseRegister(self, register):
#print register
......@@ -74,14 +83,15 @@ class vcf(object):
'NU': len(register['desc' ].split('|')),
'UP': stats['unphased'],
'PH': stats['phased' ],
'UN': stats['uncalled'],
'UN': stats['gap' ],
'HO': stats['homo' ],
'HE': stats['het' ]
}
for k in stats:
self.stats[k] = self.stats.get(k, 0) + stats[k]
for k,v in stats.items():
self.add_stat(register['chrom'], k, v)
info_str = ";".join( [ "%s=%d" % ( x, ks[x] ) for x in sorted(ks) ] )
restr = "\t".join([ register['chrom'], str(register['pos' ]), '.', register['src' ], register['dst' ], '.', 'PASS', info_str, 'FI', register['desc' ]])
......@@ -169,9 +179,6 @@ def main(args):
outFile = outbn + '.list.csv.vcf.gz.simplified.vcf.gz'
outFileTmp = outbn + '.list.csv.vcf.gz.simplified.tmp.vcf.gz'
if not os.path.exists(vcfFile):
os.symlink(invcf, vcfFile)
if os.path.exists( outFile ):
print "Out File (%s) EXISTS. quitting" % outFile
sys.exit(1)
......@@ -268,7 +275,7 @@ def main(args):
cols = ["1", "%s|%d" % (invcf, ln+1), name]
if data is not None:
assert name in data, "name %s not in db" % name
assert name in data, "name %s not in db %s" % (name, str(data))
#print "converting %s to %s" % (name, data[name])
cols[2] = data[name]
......@@ -299,9 +306,6 @@ def main(args):
gtpos = info.index('GT')
#print " GT pos", gtpos
if len(cols[3]) > 1:
continue
register = {
'chrom': cols[0] ,
'pos' : int(cols[1]),
......@@ -311,13 +315,30 @@ def main(args):
'stats': {
'unphased' : 0,
'phased' : 0,
'uncalled' : 0,
'gap' : 0,
'ref' : 0,
'homo' : 0,
'het' : 0
'het' : 0,
'x_mnp_ref': 0,
'x_mnp_alt': 0,
'x_gap' : 0,
'x_het' : 0
}
}
descs = cols[9:]
if len(cols[3]) > 1:
print "MNP ref", cols[3]
vcf_holder.add_stat(cols[0], 'x_mnp_ref', 1)
continue
if any([len(x) != 1 for x in cols[4].split(',')]):
print "MNP alt", cols[4]
vcf_holder.add_stat(cols[0], 'x_mnp_alt', 1)
continue
#descs = cols[9:]
has_gap = False
is_het = False
......@@ -328,12 +349,14 @@ def main(args):
if colname not in columns:
continue
if (desc == './.'):
register['stats']['uncalled'] += 1
if (desc == './.') or (desc == '.'):
if not options.keep_no_coverage:
vcf_holder.add_stat(cols[0], 'x_gap', 1)
has_gap = True
break
else:
register['stats']['gap'] += 1
continue
assert ':' in desc, desc + " " + str(cols[9:])
......@@ -345,11 +368,13 @@ def main(args):
#assert len(infoC) == len(descC), str(infoC) + " " + str(descC) + " " + str(cols[9:])
if len(infoC) != len(descC):
register['stats']['uncalled'] += 1
if not options.keep_no_coverage:
vcf_holder.add_stat(cols[0], 'x_gap', 1)
has_gap = True
break
else:
register['stats']['gap'] += 1
continue
#print " len infoC == len descC", infoC, descC
......@@ -372,10 +397,13 @@ def main(args):
if gt0 == '.' or gt1 == '.': # skip no coverage
#sys.stdout.write('.')
register['stats']['uncalled'] += 1
if not options.keep_no_coverage:
register['stats']['uncalled'] += 1
has_gap = True
break
else:
vcf_holder.add_stat(cols[0], 'x_gap', 1)
continue
else:
if len(set([gt0, gt1])) == 1:
......@@ -389,11 +417,12 @@ def main(args):
else:
#sys.stdout.write('e')
register['stats']['het'] += 1
if not options.keep_heterozygous:
vcf_holder.add_stat(cols[0], 'x_het', 1)
is_het = True
break
else:
register['stats']['het'] += 1
continue
dstC = register['dst'].split(',')
......@@ -446,10 +475,19 @@ def main(args):
fhdv.flush()
print "GLOBAL STATS"
print vcf_holder.stats
print "\nGLOBAL STATS"
print 'Global Stats :', " ".join([ "{:s}: {:10,d}".format(*i) for i in sorted(vcf_holder.stats.items()) ])
os.rename(outFileTmp, outFile)
os.utime(listFile, None)
if not os.path.exists(vcfFile):
os.symlink(invcf, vcfFile)
os.utime(vcfFile , None)
os.utime(outFile , None)
if __name__ == '__main__':
main(sys.argv[1:])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment