ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/tophat_cpp/bam2fastx.cpp
(Generate patch)
# Line 7 | Line 7
7   #include "bam/sam.h"
8  
9   static bool is_fastq=true; //default is fastq
10 + static bool sam_input=false; //default is BAM
11 +
12   static char qseq[2048];
13  
14   const char *short_options = "aq";
15  
16   enum {
17     OPT_FASTA = 127,
18 <   OPT_FASTQ
18 >   OPT_FASTQ,
19 >   OPT_SAM
20     };
21    
22   static struct option long_options[] = {
23    {"fasta", no_argument, 0, OPT_FASTA},
24    {"fastq", no_argument, 0, OPT_FASTQ},
25 +  {"sam", no_argument, 0, OPT_SAM},
26    {0, 0, 0, 0} // terminator
27    };
28  
# Line 39 | Line 43
43         case OPT_FASTQ:
44           is_fastq = true;
45           break;
46 +       case 's':
47 +       case 't':
48 +       case OPT_SAM: //sam (text) input
49 +         sam_input = true;
50 +         break;
51         default:
52           return 1;
53         }
# Line 90 | Line 99
99   }
100  
101  
102 < #define USAGE "Usage: bam2fastx [--fasta|-a|--fastq|-q] <in.bam>\n"
102 > #define USAGE "Usage: bam2fastx [--fasta|-a|--fastq|-q] [--sam|-s|-t] <in.bam>|<in.sam> \n"
103  
104   int main(int argc, char *argv[])
105   {
106      samfile_t *fp;
107      char* fname=NULL;
108 <    
108 >
109      if (parse_options(argc, argv) || optind>=argc) {
110         fprintf(stderr, USAGE);
111         return -1;
# Line 107 | Line 116
116          fprintf(stderr, USAGE);
117          return 1;
118          }
119 <    
120 <    if ((fp = samopen(fname, "rb", 0)) == 0) {
119 >    if (sam_input)
120 >        fp = samopen(fname, "r", 0);
121 >      else
122 >        fp = samopen(fname, "rb", 0);
123 >    if (fp == 0) {
124          fprintf(stderr, "Error: bam2fastx failed to open BAM file %s\n", fname);
125          return 1;
126          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines