Skip to content

Instantly share code, notes, and snippets.

@pb-jchin
Last active September 26, 2016 04:50
Show Gist options
  • Save pb-jchin/031af0dfc8b0b33ef1c5e039c142c194 to your computer and use it in GitHub Desktop.
Save pb-jchin/031af0dfc8b0b33ef1c5e039c142c194 to your computer and use it in GitHub Desktop.
Prototype script converting FALCON first string graph to GFA2 format
read_length = {}
edges = {}
print "H\tVN:Z:2.0"
with open("sg_edges_list") as f:
for row in f:
row = row.strip().split()
""" 000264577:E 000291380:B 000291380 4496 0 23388 99.53 G """
v, w, sid2, x2, y2, ovlp, idt, t = row
ovlp = int(ovlp)
x2 = int(x2)
y2 = int(y2)
if sid2 not in read_length:
# sg_edges_list was not designed to keep the read length
# this read length is an estimation (for now)
l = int(ovlp) + abs( x2 - y2)
read_length[sid2] = l
rec = ("S", sid2, str(l), "*")
print "\t".join(rec)
edges[ (v, w) ] = ( sid2, x2, y2, ovlp, idt, t )
for v, w in edges:
#if v > w: continue #dedup
e = edges[ (v, w) ]
v = v.split(":")
w = w.split(":")
vv = v[0] , "B" if v[1] == "E" else "E"
ww = w[0] , "B" if w[1] == "E" else "E"
ee = edges[ (":".join(ww), ":".join(vv)) ]
tag = "T:Z:"+e[-1]
if v[1] == "B" and w[1] == "B":
sid1, sid2 = v[0], w[0]
orientation = "+"
b1 = "0" # another representation
e1 = "$"+ str(ee[1])
b2 = str(e[1])
e2 = "$0"
print "\t".join( ("E", "*", sid1, orientation, sid2, b1, e1, b2, e2, tag) )
continue
if v[1] == "E" and w[1] == "E":
sid1, sid2 = v[0], w[0]
orientation = "+"
#b1 = "$" + str(read_length[sid1] - ee[1])
b1 = str(ee[1]) # another representation
e1 = "$0"
b2 = "0"
e2 = "$"+str(e[1])
print "\t".join( ("E", "*", sid1, orientation, sid2, b1, e1, b2, e2, tag) )
continue
if v[1] == "E" and w[1] == "B":
sid1, sid2 = v[0], w[0]
orientation = "-"
b1 = str(ee[1])
e1 = "$0"
b2 = str(e[1])
e2 = "$0"
print "\t".join( ("E", "*", sid1, orientation, sid2, b1, e1, b2, e2, tag) )
continue
if v[1] == "B" and w[1] == "E":
sid1, sid2 = w[0], v[0]
orientation = "-"
b1 = "0"
e1 = "$"+str(e[2]-e[1])
b2 = "0"
e2 = "$"+str(ee[2]-ee[1])
print "\t".join( ("E", "*", sid1, orientation, sid2, b1, e1, b2, e2, tag) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment