4 * Copyright (c) 2008-2012 BGI-Shenzhen <soap at genomics dot org dot cn>.
6 * This file is part of SOAPdenovo.
8 * SOAPdenovo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * SOAPdenovo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with SOAPdenovo. If not, see <http://www.gnu.org/licenses/>.
29 void copyEdge ( unsigned int source
, unsigned int target
)
31 edge_array
[target
].from_vt
= edge_array
[source
].from_vt
;
32 edge_array
[target
].to_vt
= edge_array
[source
].to_vt
;
33 edge_array
[target
].length
= edge_array
[source
].length
;
34 edge_array
[target
].cvg
= edge_array
[source
].cvg
;
35 edge_array
[target
].multi
= edge_array
[source
].multi
;
36 edge_array
[target
].flag
= edge_array
[source
].flag
;
38 if ( edge_array
[target
].seq
)
40 free ( ( void * ) edge_array
[target
].seq
);
43 edge_array
[target
].seq
= edge_array
[source
].seq
;
44 edge_array
[source
].seq
= NULL
;
45 edge_array
[target
].arcs
= edge_array
[source
].arcs
;
46 edge_array
[source
].arcs
= NULL
;
47 edge_array
[target
].markers
= edge_array
[source
].markers
;
48 edge_array
[source
].markers
= NULL
;
49 edge_array
[target
].deleted
= edge_array
[source
].deleted
;
52 //move edge from source to target
53 void edgeMove ( unsigned int source
, unsigned int target
)
55 unsigned int bal_source
, bal_target
;
57 copyEdge ( source
, target
);
58 bal_source
= getTwinEdge ( source
);
61 if ( bal_source
!= source
)
63 bal_target
= target
+ 1;
64 copyEdge ( bal_source
, bal_target
);
65 edge_array
[target
].bal_edge
= 2;
66 edge_array
[bal_target
].bal_edge
= 0;
70 edge_array
[target
].bal_edge
= 1;
74 //take care of the arcs
75 arc
= edge_array
[target
].arcs
;
79 arc
->bal_arc
->to_ed
= bal_target
;
83 if ( bal_target
== target
)
88 arc
= edge_array
[bal_target
].arcs
;
92 arc
->bal_arc
->to_ed
= target
;
97 /*************************************************
101 Compacts the edge array by removing deleted edges.
108 *************************************************/
109 void compactEdgeArray ()
112 unsigned int validCounter
= 0;
114 fprintf ( stderr
, "Before compacting, %d edge(s) existed.\n", num_ed
);
116 for ( i
= 1; i
<= num_ed
; i
++ )
118 if ( edge_array
[i
].deleted
)
125 if ( i
== validCounter
)
130 bal_ed
= getTwinEdge ( i
);
131 edgeMove ( i
, validCounter
);
140 num_ed
= validCounter
;
141 fprintf ( stderr
, "After compacting, %d edge(s) left.\n", num_ed
);