@@ -85,6 +85,7 @@ main_xcounts(int argc, const char **argv) {
8585 bool require_coverage = false ;
8686 size_t n_threads = 1 ;
8787 string genome_file;
88+ string header_file;
8889
8990 string outfile{" -" };
9091 const string description =
@@ -99,6 +100,8 @@ main_xcounts(int argc, const char **argv) {
99100 false , genome_file);
100101 opt_parse.add_opt (" reads" , ' r' , " ouput only sites with reads" ,
101102 false , require_coverage);
103+ opt_parse.add_opt (" header" , ' h' , " use this file to generate header" ,
104+ false , header_file);
102105 opt_parse.add_opt (" threads" , ' t' , " threads for compression (use few)" ,
103106 false , n_threads);
104107 std::vector<string> leftover_args;
@@ -150,7 +153,9 @@ main_xcounts(int argc, const char **argv) {
150153 tpool.set_io (out);
151154 }
152155
153- if (!genome_file.empty ())
156+ if (!header_file.empty ())
157+ write_counts_header_from_file (header_file, out);
158+ else if (!genome_file.empty ())
154159 write_counts_header_from_chrom_sizes (chrom_names, chrom_sizes, out);
155160
156161 // use the kstring_t type to more directly use the BGZF file
@@ -163,17 +168,20 @@ main_xcounts(int argc, const char **argv) {
163168 uint32_t offset = 0 ;
164169 string prev_chrom;
165170 bool status_ok = true ;
171+ bool found_header = (!genome_file.empty () || !header_file.empty ());
166172
167173 MSite site;
168174 while (status_ok && getline (in, line)) {
169175 if (is_counts_header_line (line.s )) {
170- if (!genome_file.empty ()) continue ;
176+ if (!genome_file.empty () || !header_file.empty ()) continue ;
177+ found_header = true ;
171178 const string header_line{line.s };
172179 write_counts_header_line (header_line, out);
173180 continue ;
174181 }
182+
175183 status_ok = site.initialize (line.s , line.s + line.l );
176- if (!status_ok) break ;
184+ if (!status_ok || !found_header ) break ;
177185
178186 if (site.chrom != prev_chrom) {
179187 prev_chrom = site.chrom ;
@@ -196,6 +204,10 @@ main_xcounts(int argc, const char **argv) {
196204 << filename << " to " << outfile << endl;
197205 return EXIT_FAILURE;
198206 }
207+ if (!found_header) {
208+ cerr << " no header provided or found" << endl;
209+ return EXIT_FAILURE;
210+ }
199211 }
200212 catch (const std::exception &e) {
201213 cerr << e.what () << endl;
0 commit comments