@@ -49,6 +49,7 @@ THE SOFTWARE. */
49
49
typedef struct _args_t
50
50
{
51
51
char * * argv , * fname , * samples_fname , * header_fname , * output_fname ;
52
+ int samples_is_file ;
52
53
char * fai_fname ;
53
54
htsFile * fp ;
54
55
faidx_t * fai ;
@@ -204,6 +205,14 @@ static void update_from_fai(faidx_t *fai, kstring_t *hdr_txt)
204
205
khash_str2int_destroy_free (chr_seen );
205
206
}
206
207
208
+ static char * * read_samples (char * fname , int is_file , int * nsamples )
209
+ {
210
+ char * * samples = hts_readlist (fname , is_file , nsamples );
211
+ if ( !samples && !* nsamples )
212
+ error ("Error parsing the %s %s \"%s\"\n" , is_file ?"--samples-file" :"--samples-list" ,is_file ?"file" :"list" ,fname );
213
+ return samples ;
214
+ }
215
+
207
216
static void read_header_file (char * fname , kstring_t * hdr )
208
217
{
209
218
kstring_t tmp = {0 ,0 ,0 };
@@ -389,10 +398,7 @@ static void reheader_vcf_gz(args_t *args)
389
398
int nsamples = 0 ;
390
399
char * * samples = NULL ;
391
400
if ( args -> samples_fname )
392
- {
393
- samples = hts_readlines (args -> samples_fname , & nsamples );
394
- if ( !samples || !nsamples ) error ("Error reading the --samples file \"%s\"\n" , args -> samples_fname );
395
- }
401
+ samples = read_samples (args -> samples_fname , args -> samples_is_file , & nsamples );
396
402
if ( args -> header_fname )
397
403
{
398
404
free (hdr .s ); hdr .s = NULL ; hdr .l = hdr .m = 0 ;
@@ -452,10 +458,7 @@ static void reheader_vcf(args_t *args)
452
458
int nsamples = 0 ;
453
459
char * * samples = NULL ;
454
460
if ( args -> samples_fname )
455
- {
456
- samples = hts_readlines (args -> samples_fname , & nsamples );
457
- if ( !samples || !nsamples ) error ("Error reading the --samples file \"%s\"\n" , args -> samples_fname );
458
- }
461
+ samples = read_samples (args -> samples_fname , args -> samples_is_file , & nsamples );
459
462
if ( args -> header_fname )
460
463
{
461
464
free (hdr .s ); hdr .s = NULL ; hdr .l = hdr .m = 0 ;
@@ -563,10 +566,7 @@ static void reheader_bcf(args_t *args, int is_compressed)
563
566
int i , nsamples = 0 ;
564
567
char * * samples = NULL ;
565
568
if ( args -> samples_fname )
566
- {
567
- samples = hts_readlines (args -> samples_fname , & nsamples );
568
- if ( !samples || !nsamples ) error ("Error reading the --samples file \"%s\"\n" , args -> samples_fname );
569
- }
569
+ samples = read_samples (args -> samples_fname , args -> samples_is_file , & nsamples );
570
570
if ( args -> header_fname )
571
571
{
572
572
free (htxt .s ); htxt .s = NULL ; htxt .l = htxt .m = 0 ;
@@ -664,9 +664,10 @@ static void usage(args_t *args)
664
664
fprintf (stderr , " -f, --fai FILE Update sequences and their lengths from the .fai file\n" );
665
665
fprintf (stderr , " -h, --header FILE New header\n" );
666
666
fprintf (stderr , " -o, --output FILE Write output to a file [standard output]\n" );
667
- fprintf (stderr , " -s, --samples FILE New sample names\n" );
667
+ fprintf (stderr , " -n, --samples-list LIST New sample names given as a comma-separated list\n" );
668
+ fprintf (stderr , " -N, --samples-file FILE New sample names in a file, see the man page for details\n" );
668
669
fprintf (stderr , " -T, --temp-prefix PATH Ignored; was template for temporary file name\n" );
669
- fprintf (stderr , " --threads INT Use multithreading with <int> worker threads (BCF only) [0]\n" );
670
+ fprintf (stderr , " --threads INT Use multithreading with INT worker threads (BCF only) [0]\n" );
670
671
fprintf (stderr , " -v, --verbosity INT Verbosity level\n" );
671
672
fprintf (stderr , "\n" );
672
673
fprintf (stderr , "Example:\n" );
@@ -695,11 +696,13 @@ int main_reheader(int argc, char *argv[])
695
696
{"output" ,1 ,0 ,'o' },
696
697
{"header" ,1 ,0 ,'h' },
697
698
{"samples" ,1 ,0 ,'s' },
699
+ {"samples-file" ,1 ,0 ,'N' },
700
+ {"samples-list" ,1 ,0 ,'n' },
698
701
{"threads" ,1 ,NULL ,1 },
699
702
{"verbosity" ,required_argument ,NULL ,'v' },
700
703
{0 ,0 ,0 ,0 }
701
704
};
702
- while ((c = getopt_long (argc , argv , "s:h:o:f:T:v:" ,loptions ,NULL )) >= 0 )
705
+ while ((c = getopt_long (argc , argv , "s:h:o:f:T:v:N:n: " ,loptions ,NULL )) >= 0 )
703
706
{
704
707
switch (c )
705
708
{
@@ -710,7 +713,9 @@ int main_reheader(int argc, char *argv[])
710
713
case 'T' : break ; // unused - was temp file prefix
711
714
case 'f' : args -> fai_fname = optarg ; break ;
712
715
case 'o' : args -> output_fname = optarg ; break ;
713
- case 's' : args -> samples_fname = optarg ; break ;
716
+ case 's' : args -> samples_fname = optarg ; args -> samples_is_file = 1 ; break ;
717
+ case 'N' : args -> samples_fname = optarg ; args -> samples_is_file = 1 ; break ;
718
+ case 'n' : args -> samples_fname = optarg ; args -> samples_is_file = 0 ; break ;
714
719
case 'h' : args -> header_fname = optarg ; break ;
715
720
case '?' : usage (args ); break ;
716
721
default : error ("Unknown argument: %s\n" , optarg );
0 commit comments