@@ -21,6 +21,16 @@ type Edge struct {
2121 weight float64
2222}
2323
24+ // isReverse returns the orientation of an edge
25+ func (r * Edge ) isReverse () bool {
26+ return r .a .end == 1
27+ }
28+
29+ // isSister returns if the edge is internal to a contig
30+ func (r * Edge ) isSister () bool {
31+ return r .weight == 0
32+ }
33+
2434// updateGraph takes input a list of paths and fuse the nodes
2535func (r * Anchorer ) updateGraph (G Graph ) Graph {
2636 return G
@@ -95,37 +105,46 @@ func (r *Anchorer) generatePathAndCycle(G Graph) {
95105 path1 , isCycle = dfs (G , a , path1 , visited , true )
96106 if isCycle {
97107 path1 = breakCycle (path1 )
98- printPath (path1 , nodeToPath )
108+ mergePath (path1 , nodeToPath )
99109 continue
100110 }
101111 delete (visited , a )
102112 path2 , _ = dfs (G , a , path2 , visited , false )
103113
104114 path1 = append (reversePath (path1 ), path2 ... )
105- printPath (path1 , nodeToPath )
115+ mergePath (path1 , nodeToPath )
106116 }
117+ log .Noticef ("A total of %d nodes mapped to new path" , len (nodeToPath ))
107118}
108119
109- // printPath converts a single edge path into a node path
110- func printPath (path []Edge , nodeToPath map [* Node ]* Path ) {
120+ // mergePath converts a single edge path into a node path
121+ func mergePath (path []Edge , nodeToPath map [* Node ]* Path ) {
111122 p := []string {}
112- tag := ""
113- // s := Path{}
114- // orientation := 0
123+ s := & Path {}
115124 for _ , edge := range path {
116- if edge .weight == 0 { // Sister edge
117- if edge .a .end == 1 {
118- tag = "-"
119- } else {
120- tag = ""
121- }
122- // Special care needed for reverse orientation
123- for _ , contig := range edge .a .path .contigs {
124- p = append (p , tag + contig .name )
125- }
125+ if ! edge .isSister () {
126+ continue
127+ }
128+ ep := edge .a .path
129+ tag := ""
130+ if edge .isReverse () {
131+ tag = "-"
132+ ep .reverse ()
133+ }
134+ // TODO: take orientations into account
135+ s .contigs = append (s .contigs , ep .contigs ... )
136+ s .orientations = append (s .orientations , ep .orientations ... )
137+ nodeToPath [edge .a ] = s
138+ nodeToPath [edge .b ] = s
139+
140+ // Special care needed for reverse orientation
141+ for _ , contig := range edge .a .path .contigs {
142+ p = append (p , tag + contig .name )
126143 }
127144 }
145+ s .Length ()
128146 fmt .Println (path )
147+ fmt .Println (s )
129148 fmt .Println (p )
130149}
131150
0 commit comments