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 #define preARCBLOCKSIZE 100000
31 void createPreArcMemManager ()
33 prearc_mem_manager
= createMem_manager ( preARCBLOCKSIZE
, sizeof ( preARC
) );
36 void prlDestroyPreArcMem ()
38 if ( !preArc_mem_managers
)
45 for ( i
= 0; i
< thrd_num
; i
++ )
47 freeMem_manager ( preArc_mem_managers
[i
] );
50 free ( ( void * ) preArc_mem_managers
);
51 preArc_mem_managers
= NULL
;
54 void destroyPreArcMem ()
56 freeMem_manager ( prearc_mem_manager
);
57 prearc_mem_manager
= NULL
;
60 preARC
* prlAllocatePreArc ( unsigned int edgeid
, MEM_MANAGER
* manager
)
63 newArc
= ( preARC
* ) getItem ( manager
);
64 newArc
->to_ed
= edgeid
;
65 newArc
->multiplicity
= 1;
70 preARC
* allocatePreArc ( unsigned int edgeid
)
74 newArc
= ( preARC
* ) getItem ( prearc_mem_manager
);
75 newArc
->to_ed
= edgeid
;
76 newArc
->multiplicity
= 1;
81 void output_arcGVZ ( char * outfile
, boolean IsContig
)
88 sprintf ( name
, "%s.arc.gvz", outfile
);
89 fp
= ckopen ( name
, "w" );
90 fprintf ( fp
, "digraph G{\n" );
91 fprintf ( fp
, "\tsize=\"512,512\";\n" );
93 for ( i
= 1; i
<= num_ed
; i
++ )
97 pPreArc
= contig_array
[i
].arcs
;
101 fprintf ( fp
, "\tC%d -> C%d[label =\"%d\"];\n", i
, pPreArc
->to_ed
, pPreArc
->multiplicity
);
102 pPreArc
= pPreArc
->next
;
107 pArc
= edge_array
[i
].arcs
;
111 fprintf ( fp
, "\tC%d -> C%d[label =\"%d\"];\n", i
, pArc
->to_ed
, pArc
->multiplicity
);
117 fprintf ( fp
, "}\n" );
121 /**************** below this line all codes are about ARC ****************/
122 #define ARCBLOCKSIZE 100000
123 void createArcMemo ()
125 if ( !arc_mem_manager
)
127 arc_mem_manager
= createMem_manager ( ARCBLOCKSIZE
, sizeof ( ARC
) );
131 fprintf ( stderr
, "Warning from createArcMemo: arc_mem_manager is a active pointer.\n" );
135 void destroyArcMem ()
137 freeMem_manager ( arc_mem_manager
);
138 arc_mem_manager
= NULL
;
141 ARC
* allocateArc ( unsigned int edgeid
)
145 newArc
= ( ARC
* ) getItem ( arc_mem_manager
);
146 newArc
->to_ed
= edgeid
;
147 newArc
->multiplicity
= 1;
153 void dismissArc ( ARC
* arc
)
155 returnItem ( arc_mem_manager
, arc
);
158 /***************** below this line all codes are about lookup table *****************/
160 void createArcLookupTable ()
162 if ( !arcLookupTable
)
164 arcLookupTable
= ( ARC
** ) ckalloc ( ( 3 * num_ed
+ 1 ) * sizeof ( ARC
* ) );
168 void deleteArcLookupTable ()
170 if ( arcLookupTable
)
172 free ( ( void * ) arcLookupTable
);
173 arcLookupTable
= NULL
;
177 void putArc2LookupTable ( unsigned int from_ed
, ARC
* arc
)
179 if ( !arc
|| !arcLookupTable
)
184 unsigned int index
= 2 * from_ed
+ arc
->to_ed
;
185 arc
->nextInLookupTable
= arcLookupTable
[index
];
186 arcLookupTable
[index
] = arc
;
189 static ARC
* getArcInLookupTable ( unsigned int from_ed
, unsigned int to_ed
)
191 unsigned int index
= 2 * from_ed
+ to_ed
;
192 ARC
* ite_arc
= arcLookupTable
[index
];
196 if ( ite_arc
->to_ed
== to_ed
)
201 ite_arc
= ite_arc
->nextInLookupTable
;
207 void removeArcInLookupTable ( unsigned int from_ed
, unsigned int to_ed
)
209 unsigned int index
= 2 * from_ed
+ to_ed
;
210 ARC
* ite_arc
= arcLookupTable
[index
];
215 fprintf ( stderr
, "RemoveArcInLookupTable: not found A.\n" );
219 if ( ite_arc
->to_ed
== to_ed
)
221 arcLookupTable
[index
] = ite_arc
->nextInLookupTable
;
225 while ( ite_arc
->nextInLookupTable
&& ite_arc
->nextInLookupTable
->to_ed
!= to_ed
)
227 ite_arc
= ite_arc
->nextInLookupTable
;
230 if ( ite_arc
->nextInLookupTable
)
232 arc
= ite_arc
->nextInLookupTable
;
233 ite_arc
->nextInLookupTable
= arc
->nextInLookupTable
;
237 fprintf ( stderr
, "RemoveArcInLookupTable: not found B.\n" );
241 void recordArcsInLookupTable ()
246 for ( i
= 1; i
<= num_ed
; i
++ )
248 ite_arc
= edge_array
[i
].arcs
;
252 putArc2LookupTable ( i
, ite_arc
);
253 ite_arc
= ite_arc
->next
;
258 /*************************************************
262 Gets the arc between the edge "from_ed" and the edge "to_ed", then return it.
264 1. from_ed: the origin edge
265 2. to_ed: the destination edge
269 The arc between the edge "from_ed" and the edge "to_ed".
270 *************************************************/
271 ARC
* getArcBetween ( unsigned int from_ed
, unsigned int to_ed
)
275 if ( arcLookupTable
)
277 parc
= getArcInLookupTable ( from_ed
, to_ed
);
281 parc
= edge_array
[from_ed
].arcs
;
285 if ( parc
->to_ed
== to_ed
)
296 /*************************************************
300 Compute the count of the valid arc, whose weight is larger than "cutoff", then return it.
302 1. arc: the head of the "preARC" linked list
303 2. cutoff: the minimum requirement for the weight of the valid arc
307 The number of the valid arc.
308 *************************************************/
309 int validArcCount ( preARC
* arc
, int cutoff
)
315 if ( arc
->multiplicity
>= cutoff
)
324 /*************************************************
328 Gets the maximum weight in all arcs, then return it.
330 1. arc: the head of the "preARC" linked list
335 *************************************************/
336 unsigned int maxArcWeight ( preARC
* arc
)
338 unsigned int max
= 0;
342 if ( arc
->multiplicity
> max
)
343 { max
= arc
->multiplicity
; }