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 CNBLOCKSIZE 100000
31 void createCntMemManager ()
33 if ( !cn_mem_manager
)
35 cn_mem_manager
= createMem_manager ( CNBLOCKSIZE
, sizeof ( CONNECT
) );
39 fprintf ( stderr
, "The cn_mem_manger created.\n" );
43 void destroyConnectMem ()
45 freeMem_manager ( cn_mem_manager
);
46 cn_mem_manager
= NULL
;
49 CONNECT
* allocateCN ( unsigned int contigId
, int gap
)
52 newCN
= ( CONNECT
* ) getItem ( cn_mem_manager
);
53 newCN
->contigID
= contigId
;
61 newCN
->weightNotInherit
= 0;
66 newCN
->prevInScaf
= 0;
68 newCN
->singleInScaf
= 0;
69 newCN
->nextInScaf
= NULL
;
73 void output_cntGVZ ( char * outfile
)
80 sprintf ( name
, "%s.scaffold.gvz", outfile
);
81 fp
= ckopen ( name
, "w" );
82 fprintf ( fp
, "digraph G{\n" );
83 fprintf ( fp
, "\tsize=\"512,512\";\n" );
85 for ( i
= num_ctg
; i
> 0; i
-- )
87 if ( !contig_array
[i
].downwardConnect
)
92 connect
= contig_array
[i
].downwardConnect
;
96 if ( connect
->deleted
)
98 connect
= connect
->next
;
102 if ( connect
->prevInScaf
|| connect
->nextInScaf
)
111 if ( !connect
->mask
)
112 fprintf ( fp
, "\tC%d_%d -> C%d_%d [label = \"%d(%d_%d)\"];\n", i
, contig_array
[i
].length
, connect
->contigID
, contig_array
[connect
->contigID
].length
,
113 connect
->gapLen
, flag
, connect
->weight
);
115 fprintf ( fp
, "\tC%d_%d -> C%d_%d [label = \"%d(%d_%d)\", color = red];\n", i
, contig_array
[i
].length
, connect
->contigID
, contig_array
[connect
->contigID
].length
,
116 connect
->gapLen
, flag
, connect
->weight
);
118 connect
= connect
->next
;
122 fprintf ( fp
, "}\n" );
126 /***************** below this line all codes are about lookup table *****************/
128 void createCntLookupTable ()
130 if ( !cntLookupTable
)
132 cntLookupTable
= ( CONNECT
** ) ckalloc ( ( 3 * num_ctg
+ 1 ) * sizeof ( CONNECT
* ) );
136 void deleteCntLookupTable ()
138 if ( cntLookupTable
)
140 free ( ( void * ) cntLookupTable
);
141 cntLookupTable
= NULL
;
145 void putCnt2LookupTable ( unsigned int from_c
, CONNECT
* cnt
)
147 if ( !cnt
|| !cntLookupTable
)
152 unsigned int index
= 2 * from_c
+ cnt
->contigID
;
153 cnt
->nextInLookupTable
= cntLookupTable
[index
];
154 cntLookupTable
[index
] = cnt
;
157 static CONNECT
* getCntInLookupTable ( unsigned int from_c
, unsigned int to_c
)
159 unsigned int index
= 2 * from_c
+ to_c
;
160 CONNECT
* ite_cnt
= cntLookupTable
[index
];
164 if ( ite_cnt
->contigID
== to_c
)
169 ite_cnt
= ite_cnt
->nextInLookupTable
;
175 CONNECT
* getCntBetween ( unsigned int from_c
, unsigned int to_c
)
179 if ( cntLookupTable
)
181 pcnt
= getCntInLookupTable ( from_c
, to_c
);
185 pcnt
= contig_array
[from_c
].downwardConnect
;
189 if ( pcnt
->contigID
== to_c
)
201 void removeCntInLookupTable(unsigned int from_c,unsigned int to_c)
203 unsigned int index = 2*from_c + to_c;
204 CONNECT *ite_cnt = cntLookupTable[index];
208 printf("removeCntInLookupTable: not found A\n");
211 if(ite_cnt->contigID==to_c){
212 cntLookupTable[index] = ite_cnt->nextInLookupTable;
216 while(ite_cnt->nextInLookupTable&&ite_cnt->nextInLookupTable->contigID!=to_c)
217 ite_cnt = ite_cnt->nextInLookupTable;
219 if(ite_cnt->nextInLookupTable){
220 cnt = ite_cnt->nextInLookupTable;
221 ite_cnt->nextInLookupTable = cnt->nextInLookupTable;
224 printf("removeCntInLookupTable: not found B\n");