Debian Codegraph @

src/asmode.h

raw symbols SCIP
1 #ifndef ASMODE_H
2 #define ASMODE_H
3
4 #include <boost/unordered_map.hpp>
5 #include <boost/date_time/posix_time/posix_time.hpp>
6 #include <boost/date_time/gregorian/gregorian.hpp>
7 #include <boost/program_options/cmdline.hpp>
8 #include <boost/program_options/options_description.hpp>
9 #include <boost/program_options/parsers.hpp>
10 #include <boost/program_options/variables_map.hpp>
11 #include <boost/filesystem.hpp>
12 #include <boost/tokenizer.hpp>
13 #include <iostream>
14 #include <vector>
15 #include <htslib/vcf.h>
16 #include <htslib/sam.h>
17 #include <math.h>
18 #include <stdio.h>
19
20 #include <htslib/sam.h>
21 #include <htslib/vcf.h>
22 #include <htslib/faidx.h>
23
24 #include "edlib.h"
25 #include "delly.h"
26 #include "coverage.h"
27 #include "genotype.h"
28 #include "util.h"
29 #include "junction.h"
30 #include "cluster.h"
31 #include "assemble.h"
32 #include "modvcf.h"
33
34 namespace torali {
35
36
37 struct AsmConfig {
38 bool hasVcfFile;
39 uint16_t minMapQual;
40 uint32_t minClip;
41 uint32_t minCliqueSize;
42 uint32_t graphPruning;
43 uint32_t minRefSep;
44 uint32_t maxReadSep;
45 int32_t minConsWindow;
46 int32_t minimumFlankSize;
47 int32_t indelsize;
48 int32_t nchr;
49 float flankQuality;
50 std::set<int32_t> svtset;
51 boost::filesystem::path outfile;
52 std::vector<boost::filesystem::path> files;
53 boost::filesystem::path genome;
54 std::vector<std::string> sampleName;
55 };
56
57 template<typename TConfig, typename TReadBp>
58 inline void
59 findAsmJunctions(TConfig const& c, TReadBp& readBp) {
60 // Open file handles
61 typedef std::vector<samFile*> TSamFile;
62 typedef std::vector<hts_idx_t*> TIndex;
63 TSamFile samfile(c.files.size());
64 TIndex idx(c.files.size());
65 for(unsigned int file_c = 0; file_c < c.files.size(); ++file_c) {
66 samfile[file_c] = sam_open(c.files[file_c].string().c_str(), "r");
67 hts_set_fai_filename(samfile[file_c], c.genome.string().c_str());
68 idx[file_c] = sam_index_load(samfile[file_c], c.files[file_c].string().c_str());
69 }
70 bam_hdr_t* hdr = sam_hdr_read(samfile[0]);
71
72 // Parse genome chr-by-chr
73 boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
74 std::cerr << '[' << boost::posix_time::to_simple_string(now) << "] " << "Split-read scanning" << std::endl;
75
76 // Iterate chromosomes
77 for(int32_t refIndex=0; refIndex < (int32_t) hdr->n_targets; ++refIndex) {
78
79 // Collect reads from all samples
80 for(unsigned int file_c = 0; file_c < c.files.size(); ++file_c) {
81 // Read alignments
82 hts_itr_t* iter = sam_itr_queryi(idx[file_c], refIndex, 0, hdr->target_len[refIndex]);
83 bam1_t* rec = bam_init1();
84 while (sam_itr_next(samfile[file_c], iter, rec) >= 0) {
85
86 // Keep secondary alignments
87 if (rec->core.flag & (BAM_FQCFAIL | BAM_FDUP | BAM_FUNMAP)) continue;
88 if ((rec->core.qual < c.minMapQual) || (rec->core.tid<0)) continue;
89
90 std::size_t seed = hash_lr(rec);
91 //std::cerr << bam_get_qname(rec) << '\t' << seed << std::endl;
92 uint32_t rp = rec->core.pos; // reference pointer
93 uint32_t sp = 0; // sequence pointer
94
95 // Parse the CIGAR
96 const uint32_t* cigar = bam_get_cigar(rec);
97 for (std::size_t i = 0; i < rec->core.n_cigar; ++i) {
98 if ((bam_cigar_op(cigar[i]) == BAM_CMATCH) || (bam_cigar_op(cigar[i]) == BAM_CEQUAL) || (bam_cigar_op(cigar[i]) == BAM_CDIFF)) {
99 sp += bam_cigar_oplen(cigar[i]);
100 rp += bam_cigar_oplen(cigar[i]);
101 } else if (bam_cigar_op(cigar[i]) == BAM_CDEL) {
102 if (bam_cigar_oplen(cigar[i]) > c.minRefSep) _insertJunction(readBp, seed, rec, rp, sp, false);
103 rp += bam_cigar_oplen(cigar[i]);
104 _insertJunction(readBp, seed, rec, rp, sp, true);
105 } else if (bam_cigar_op(cigar[i]) == BAM_CINS) {
106 if (bam_cigar_oplen(cigar[i]) > c.minRefSep) _insertJunction(readBp, seed, rec, rp, sp, false);
107 sp += bam_cigar_oplen(cigar[i]);
108 _insertJunction(readBp, seed, rec, rp, sp, true);
109 } else if (bam_cigar_op(cigar[i]) == BAM_CREF_SKIP) {
110 rp += bam_cigar_oplen(cigar[i]);
111 } else if ((bam_cigar_op(cigar[i]) == BAM_CSOFT_CLIP) || (bam_cigar_op(cigar[i]) == BAM_CHARD_CLIP)) {
112 int32_t finalsp = sp;
113 bool scleft = false;
114 if (sp == 0) {
115 finalsp += bam_cigar_oplen(cigar[i]); // Leading soft-clip / hard-clip
116 scleft = true;
117 }
118 sp += bam_cigar_oplen(cigar[i]);
119 //std::cerr << bam_get_qname(rec) << ',' << rp << ',' << finalsp << ',' << scleft << std::endl;
120 if (bam_cigar_oplen(cigar[i]) > c.minClip) _insertJunction(readBp, seed, rec, rp, finalsp, scleft);
121 } else {
122 std::cerr << "Unknown Cigar options" << std::endl;
123 }
124 }
125 }
126 bam_destroy1(rec);
127 hts_itr_destroy(iter);
128 }
129 }
130
131 // Sort junctions
132 for(typename TReadBp::iterator it = readBp.begin(); it != readBp.end(); ++it) std::sort(it->second.begin(), it->second.end());
133
134 // Clean-up
135 bam_hdr_destroy(hdr);
136 for(unsigned int file_c = 0; file_c < c.files.size(); ++file_c) {
137 hts_idx_destroy(idx[file_c]);
138 sam_close(samfile[file_c]);
139 }
140 }
141
142
143 template<typename TConfig, typename TSvtSRBamRecord>
144 inline void
145 _findAsmBreakpoints(TConfig const& c, TSvtSRBamRecord& srBR) {
146 // Breakpoints
147 typedef std::vector<Junction> TJunctionVector;
148 typedef boost::unordered_map<std::size_t, TJunctionVector> TReadBp;
149 TReadBp readBp;
150 findAsmJunctions(c, readBp);
151 fetchSVs(c, readBp, srBR);
152 }
153
154
155 template<typename TConfig, typename TSRStore>
156 inline void
157 _findAsmStructuralVariants(TConfig const& c, std::vector<StructuralVariantRecord>& svs, TSRStore& srStore) {
158 // Assembly splits
159 typedef std::vector<SRBamRecord> TSRBamRecord;
160 typedef std::vector<TSRBamRecord> TSvtSRBamRecord;
161 TSvtSRBamRecord srBR(2 * DELLY_SVT_TRANS, TSRBamRecord());
162
163 // Find SR breakpoints
164 _findAsmBreakpoints(c, srBR);
165
166 // Cluster SVs
167 int32_t ci = 10;
168 for(uint32_t svt = 0; svt < srBR.size(); ++svt) {
169 if (srBR[svt].empty()) continue;
170 // Sort
171 std::sort(srBR[svt].begin(), srBR[svt].end());
172 //outputSRBamRecords(c, srBR, true);
173
174 // Cluster
175 cluster(c, srBR[svt], svs, svt);
176 // Add singletons
177 int32_t svid = svs.size();
178 for(uint32_t i = 0; i<srBR[svt].size(); ++i) {
179 if (srBR[svt][i].svid == -1) {
180 srBR[svt][i].svid = svid;
181 svs.push_back(StructuralVariantRecord(srBR[svt][i].chr, srBR[svt][i].pos, srBR[svt][i].chr2, srBR[svt][i].pos2, -ci, ci, -ci, ci, 1,srBR[svt][i].qual, srBR[svt][i].qual, srBR[svt][i].inslen, svt, svid));
182 ++svid;
183 }
184 }
185 //outputStructuralVariants(c, svs, srBR, svt, true);
186
187 // Track split-reads
188 for(uint32_t i = 0; i < srBR[svt].size(); ++i) {
189 if (srBR[svt][i].svid != -1){
190 if (srStore.find(srBR[svt][i].id) == srStore.end()) srStore.insert(std::make_pair(srBR[svt][i].id, std::vector<SeqSlice>()));
191 srStore[srBR[svt][i].id].push_back(SeqSlice(srBR[svt][i].svid, srBR[svt][i].sstart, srBR[svt][i].inslen, srBR[svt][i].qual));
192 }
193 }
194 }
195 }
196
197
198 template<typename TConfig, typename TSRStore>
199 inline void
200 _setAsmConsensus(TConfig const& c, std::vector<StructuralVariantRecord>& svs, TSRStore& srStore) {
201 // Open file handles
202 typedef std::vector<samFile*> TSamFile;
203 typedef std::vector<hts_idx_t*> TIndex;
204 TSamFile samfile(c.files.size());
205 TIndex idx(c.files.size());
206 for(unsigned int file_c = 0; file_c < c.files.size(); ++file_c) {
207 samfile[file_c] = sam_open(c.files[file_c].string().c_str(), "r");
208 hts_set_fai_filename(samfile[file_c], c.genome.string().c_str());
209 idx[file_c] = sam_index_load(samfile[file_c], c.files[file_c].string().c_str());
210 }
211 bam_hdr_t* hdr = sam_hdr_read(samfile[0]);
212
213 // Parse BAM
214 boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
215 std::cerr << '[' << boost::posix_time::to_simple_string(now) << "] " << "Parse assembly alleles" << std::endl;
216
217 // Derive consensus sequences from assemblies
218 for(int32_t refIndex = 0; refIndex < hdr->n_targets; ++refIndex) {
219 for(unsigned int file_c = 0; file_c < c.files.size(); ++file_c) {
220 // Read alignments (full chromosome because primary alignments might be somewhere else)
221 hts_itr_t* iter = sam_itr_queryi(idx[file_c], refIndex, 0, hdr->target_len[refIndex]);
222 bam1_t* rec = bam_init1();
223 while (sam_itr_next(samfile[file_c], iter, rec) >= 0) {
224 // Only primary alignments with the full sequence information
225 if (rec->core.flag & (BAM_FQCFAIL | BAM_FDUP | BAM_FUNMAP | BAM_FSECONDARY | BAM_FSUPPLEMENTARY)) continue;
226
227 std::size_t seed = hash_lr(rec);
228 if (srStore.find(seed) != srStore.end()) {
229 // Get sequence
230 std::string sequence;
231 sequence.resize(rec->core.l_qseq);
232 const uint8_t* seqptr = bam_get_seq(rec);
233 for (int i = 0; i < rec->core.l_qseq; ++i) sequence[i] = "=ACMGRSVTWYHKDBN"[bam_seqi(seqptr, i)];
234 int32_t readlen = sequence.size();
235
236 // Iterate all spanned SVs
237 for(uint32_t ri = 0; ri < srStore[seed].size(); ++ri) {
238 SeqSlice seqsl = srStore[seed][ri];
239 int32_t svid = seqsl.svid;
240
241 // Extract subsequence
242 int32_t window = c.minConsWindow;
243 // Add breakpoint uncertainty
244 window += std::max(svs[svid].ciposhigh - svs[svid].ciposlow, svs[svid].ciendhigh - svs[svid].ciendlow);
245 int32_t sPos = seqsl.sstart - window;
246 int32_t ePos = seqsl.sstart + window + seqsl.inslen;
247 if (rec->core.flag & BAM_FREVERSE) {
248 sPos = (readlen - seqsl.sstart) - window - seqsl.inslen;
249 ePos = (readlen - seqsl.sstart) + window;
250 }
251 if (sPos < 0) sPos = 0;
252 if (ePos > (int32_t) readlen) ePos = readlen;
253 if (((ePos - sPos) > window) && ((ePos - sPos) < 100000)) {
254 if ((ePos - sPos) > (int32_t) svs[svid].consensus.size()) {
255 svs[svid].consensus = sequence.substr(sPos, (ePos - sPos));
256 //std::cerr << svs[svid].svStart << ',' << bam_get_qname(rec) << ',' << sPos << ',' << ePos << ":" << window << "\t" << svs[svid].consensus << std::endl;
257 }
258 }
259 }
260 }
261 }
262 bam_destroy1(rec);
263 hts_itr_destroy(iter);
264 }
265 }
266
267 // Align consensus sequences
268 faidx_t* fai = fai_load(c.genome.string().c_str());
269 for(int32_t refIndex=0; refIndex < (int32_t) hdr->n_targets; ++refIndex) {
270 char* seq = NULL;
271 for(int32_t refIndex2 = 0; refIndex2 <= refIndex; ++refIndex2) {
272 char* sndSeq = NULL;
273 for(uint32_t svid = 0; svid < svs.size(); ++svid) {
274 if (svs[svid].chr == refIndex) {
275 bool computeAlign = false;
276 if (!svs[svid].consensus.empty()) {
277 if (_translocation(svs[svid].svt)) {
278 if ((refIndex2 != refIndex) && (svs[svid].chr2 == refIndex2)) {
279 // Lazy loading of references
280 if (sndSeq == NULL) {
281 int32_t seqlen = -1;
282 std::string tname(hdr->target_name[refIndex2]);
283 sndSeq = faidx_fetch_seq(fai, tname.c_str(), 0, hdr->target_len[refIndex2], &seqlen);
284 }
285 computeAlign = true;
286 }
287 } else {
288 if ((refIndex2 == refIndex) && (svs[svid].chr2 == refIndex2)) computeAlign = true;
289 }
290 if (computeAlign) {
291 // Lazy loading of references
292 if (seq == NULL) {
293 int32_t seqlen = -1;
294 std::string tname(hdr->target_name[refIndex]);
295 seq = faidx_fetch_seq(fai, tname.c_str(), 0, hdr->target_len[refIndex], &seqlen);
296 }
297 // Align consensus
298 bool realign = true;
299 if (svs[svid].svt == 4) realign = false;
300 if (!alignConsensus(c, hdr, seq, sndSeq, svs[svid], realign)) {
301 svs[svid].consensus = "";
302 svs[svid].srSupport = 0;
303 svs[svid].srAlignQuality = 0;
304 }
305 }
306 } else {
307 svs[svid].consensus = "";
308 svs[svid].srSupport = 0;
309 svs[svid].srAlignQuality = 0;
310 }
311 }
312 }
313 if (sndSeq != NULL) free(sndSeq);
314 }
315 // Set tag alleles
316 for(uint32_t svid = 0; svid < svs.size(); ++svid) {
317 if ((svs[svid].chr == refIndex) && (svs[svid].alleles.empty())) {
318 // Lazy loading of references
319 if (seq == NULL) {
320 int32_t seqlen = -1;
321 std::string tname(hdr->target_name[refIndex]);
322 seq = faidx_fetch_seq(fai, tname.c_str(), 0, hdr->target_len[refIndex], &seqlen);
323 }
324 svs[svid].alleles = _addAlleles(boost::to_upper_copy(std::string(seq + svs[svid].svStart - 1, seq + svs[svid].svStart)), std::string(hdr->target_name[svs[svid].chr2]), svs[svid], svs[svid].svt);
325 }
326 }
327 if (seq != NULL) free(seq);
328 }
329
330 // Clean-up
331 fai_destroy(fai);
332 bam_hdr_destroy(hdr);
333 for(unsigned int file_c = 0; file_c < c.files.size(); ++file_c) {
334 hts_idx_destroy(idx[file_c]);
335 sam_close(samfile[file_c]);
336 }
337 }
338
339 template<typename TConfig>
340 inline int32_t
341 runAsm(TConfig& c) {
342
343 #ifdef PROFILE
344 ProfilerStart("delly.prof");
345 #endif
346 // Structural Variants
347 typedef std::vector<StructuralVariantRecord> TVariants;
348 TVariants svs;
349
350 {
351 TVariants svc;
352
353 // Split-read store
354 typedef std::vector<SeqSlice> TSeqSliceVector;
355 typedef boost::unordered_map<std::size_t, TSeqSliceVector> TReadSeqSlices;
356 TReadSeqSlices srStore;
357
358 // Find candidate SVs
359 _findAsmStructuralVariants(c, svc, srStore);
360
361 // Set consensus sequence
362 _setAsmConsensus(c, svc, srStore);
363
364 // Sort SVs
365 sort(svc.begin(), svc.end());
366
367 // Filter SVs
368 uint32_t idCount = 0;
369 for(uint32_t i = 0; i < svc.size(); ++i) {
370 if (svc[i].consensus.empty()) continue;
371 svc[i].srSupport = 10;
372 svc[i].mapq *= 10;
373 svc[i].id = idCount++;
374 svs.push_back(svc[i]);
375 }
376 }
377
378 // Annotate junction reads
379 typedef std::vector<JunctionCount> TSVJunctionMap;
380 typedef std::vector<TSVJunctionMap> TSampleSVJunctionMap;
381 TSampleSVJunctionMap jctMap(c.files.size());
382
383 // Annotate spanning coverage
384 typedef std::vector<SpanningCount> TSVSpanningMap;
385 typedef std::vector<TSVSpanningMap> TSampleSVSpanningMap;
386 TSampleSVSpanningMap spanMap(c.files.size());
387
388 // Annotate coverage
389 typedef std::vector<ReadCount> TSVReadCount;
390 typedef std::vector<TSVReadCount> TSampleSVReadCount;
391 TSampleSVReadCount rcMap(c.files.size());
392
393 // Initialize count maps
394 for(uint32_t file_c = 0; file_c < c.files.size(); ++file_c) {
395 jctMap[file_c].resize(svs.size(), JunctionCount());
396 spanMap[file_c].resize(svs.size(), SpanningCount());
397 rcMap[file_c].resize(svs.size());
398 }
399
400 // VCF Output
401 vcfOutput(c, svs, jctMap, rcMap, spanMap);
402
403 #ifdef PROFILE
404 ProfilerStop();
405 #endif
406
407 // End
408 boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
409 std::cerr << '[' << boost::posix_time::to_simple_string(now) << "] Done." << std::endl;;
410
411 return 0;
412 }
413
414 int asmode(int argc, char **argv) {
415 AsmConfig c;
416 c.hasVcfFile = true;
417 c.minCliqueSize = 2;
418 c.graphPruning = 1000;
419
420 // Parameter
421 std::string svtype;
422 std::string scoring;
423 std::string mode;
424 boost::program_options::options_description generic("Generic options");
425 generic.add_options()
426 ("help,?", "show help message")
427 ("svtype,t", boost::program_options::value<std::string>(&svtype)->default_value("ALL"), "SV type to compute [DEL, INS, DUP, INV, BND, ALL]")
428 ("genome,g", boost::program_options::value<boost::filesystem::path>(&c.genome), "genome fasta file")
429 ("outfile,o", boost::program_options::value<boost::filesystem::path>(&c.outfile), "SV output file")
430 ;
431
432 boost::program_options::options_description disc("Discovery options");
433 disc.add_options()
434 ("map-qual,q", boost::program_options::value<uint16_t>(&c.minMapQual)->default_value(10), "min. mapping quality")
435 ("minclip,c", boost::program_options::value<uint32_t>(&c.minClip)->default_value(25), "min. clipping length")
436 ("minrefsep,m", boost::program_options::value<uint32_t>(&c.minRefSep)->default_value(30), "min. reference separation")
437 ("maxreadsep,n", boost::program_options::value<uint32_t>(&c.maxReadSep)->default_value(100), "max. read separation")
438 ;
439
440 boost::program_options::options_description cons("Consensus options");
441 cons.add_options()
442 ("cons-window,w", boost::program_options::value<int32_t>(&c.minConsWindow)->default_value(1000), "consensus window")
443 ("flank-size,f", boost::program_options::value<int32_t>(&c.minimumFlankSize)->default_value(100), "min. flank size")
444 ("flank-quality,a", boost::program_options::value<float>(&c.flankQuality)->default_value(0.9), "min. flank quality")
445 ("indel-size,i", boost::program_options::value<int32_t>(&c.indelsize)->default_value(10000), "use exact alleles for InDels <10kbp")
446 ;
447
448 boost::program_options::options_description hidden("Hidden options");
449 hidden.add_options()
450 ("input-file", boost::program_options::value< std::vector<boost::filesystem::path> >(&c.files), "input file")
451 ;
452
453 boost::program_options::positional_options_description pos_args;
454 pos_args.add("input-file", -1);
455
456 boost::program_options::options_description cmdline_options;
457 cmdline_options.add(generic).add(disc).add(cons).add(hidden);
458 boost::program_options::options_description visible_options;
459 visible_options.add(generic).add(disc).add(cons);
460 boost::program_options::variables_map vm;
461 boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pos_args).run(), vm);
462 boost::program_options::notify(vm);
463
464 // Check command line arguments
465 if ((vm.count("help")) || (!vm.count("input-file")) || (!vm.count("genome"))) {
466 std::cerr << std::endl;
467 std::cerr << "Usage: delly " << argv[0] << " [OPTIONS] -g <ref.fa> <asm1.bam> <asm2.bam> ..." << std::endl;
468 std::cerr << visible_options << "\n";
469 return 0;
470 }
471
472 // SV types to compute?
473 if (!_svTypesToCompute(c, svtype)) {
474 std::cerr << "Please specify a valid SV type, i.e., -t INV or -t DEL,INV without spaces." << std::endl;
475 return 1;
476 }
477
478 // Check reference
479 if (!(boost::filesystem::exists(c.genome) && boost::filesystem::is_regular_file(c.genome) && boost::filesystem::file_size(c.genome))) {
480 std::cerr << "Reference file is missing: " << c.genome.string() << std::endl;
481 return 1;
482 } else {
483 faidx_t* fai = fai_load(c.genome.string().c_str());
484 if (fai == NULL) {
485 if (fai_build(c.genome.string().c_str()) == -1) {
486 std::cerr << "Fail to open genome fai index for " << c.genome.string() << std::endl;
487 return 1;
488 } else fai = fai_load(c.genome.string().c_str());
489 }
490 fai_destroy(fai);
491 }
492
493 // Check input files
494 c.sampleName.resize(c.files.size());
495 c.nchr = 0;
496 for(unsigned int file_c = 0; file_c < c.files.size(); ++file_c) {
497 if (!(boost::filesystem::exists(c.files[file_c]) && boost::filesystem::is_regular_file(c.files[file_c]) && boost::filesystem::file_size(c.files[file_c]))) {
498 std::cerr << "Alignment file is missing: " << c.files[file_c].string() << std::endl;
499 return 1;
500 }
501 samFile* samfile = sam_open(c.files[file_c].string().c_str(), "r");
502 if (samfile == NULL) {
503 std::cerr << "Fail to open file " << c.files[file_c].string() << std::endl;
504 return 1;
505 }
506 hts_idx_t* idx = sam_index_load(samfile, c.files[file_c].string().c_str());
507 if (idx == NULL) {
508 std::cerr << "Fail to open index for " << c.files[file_c].string() << std::endl;
509 return 1;
510 }
511 bam_hdr_t* hdr = sam_hdr_read(samfile);
512 if (hdr == NULL) {
513 std::cerr << "Fail to open header for " << c.files[file_c].string() << std::endl;
514 return 1;
515 }
516 if (!c.nchr) c.nchr = hdr->n_targets;
517 else {
518 if (c.nchr != hdr->n_targets) {
519 std::cerr << "BAM files have different number of chromosomes!" << std::endl;
520 return 1;
521 }
522 }
523 faidx_t* fai = fai_load(c.genome.string().c_str());
524 for(int32_t refIndex=0; refIndex < hdr->n_targets; ++refIndex) {
525 std::string tname(hdr->target_name[refIndex]);
526 if (!faidx_has_seq(fai, tname.c_str())) {
527 std::cerr << "BAM file chromosome " << hdr->target_name[refIndex] << " is NOT present in your reference file " << c.genome.string() << std::endl;
528 return 1;
529 }
530 }
531 fai_destroy(fai);
532 std::string sampleName = "unknown";
533 getSMTag(std::string(hdr->text), c.files[file_c].stem().string(), sampleName);
534 c.sampleName[file_c] = sampleName;
535 bam_hdr_destroy(hdr);
536 hts_idx_destroy(idx);
537 sam_close(samfile);
538 }
539 checkSampleNames(c);
540
541 // Check outfile
542 if (!vm.count("outfile")) c.outfile = "-";
543 else {
544 if (c.outfile.string() != "-") {
545 if (!_outfileValid(c.outfile)) return 1;
546 }
547 }
548
549 // Show cmd
550 boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
551 std::cerr << '[' << boost::posix_time::to_simple_string(now) << "] ";
552 std::cerr << "delly ";
553 for(int i=0; i<argc; ++i) { std::cerr << argv[i] << ' '; }
554 std::cerr << std::endl;
555
556 // Run assembly mode
557 return runAsm(c);
558 }
559
560 }
561
562 #endif