~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to sand/src/sand_uncompress_reads.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2009- The University of Notre Dame
 
3
This software is distributed under the GNU General Public License.
 
4
See the file COPYING for details.
 
5
*/
 
6
 
 
7
#include <stdio.h>
 
8
#include <stdlib.h>
 
9
#include <string.h>
 
10
#include <errno.h>
 
11
 
 
12
#include "compressed_sequence.h"
 
13
 
 
14
#include "debug.h"
 
15
 
 
16
static void show_version(const char *cmd)
 
17
{
 
18
        printf("%s version %d.%d.%d built by %s@%s on %s at %s\n", cmd, CCTOOLS_VERSION_MAJOR, CCTOOLS_VERSION_MINOR, CCTOOLS_VERSION_MICRO, BUILD_USER, BUILD_HOST, __DATE__, __TIME__);
 
19
}
 
20
 
 
21
static void show_help(const char *cmd)
 
22
{
 
23
        printf("Use: %s [options]  compressed_reads > fasta_reads\n", cmd);
 
24
        printf("where options are:\n");
 
25
        printf(" -q  Quiet mode: suppress summary line.\n");
 
26
        printf(" -v  Show version string.\n");
 
27
        printf(" -h  Show this help screen\n");
 
28
}
 
29
 
 
30
int main(int argc, char ** argv)
 
31
{
 
32
        const char *progname = "sand_uncompress_reads";
 
33
        FILE * infile;
 
34
        FILE * outfile;
 
35
        struct cseq *c;
 
36
        char d;
 
37
        int quiet_mode = 0;
 
38
        int count = 0;
 
39
 
 
40
        while((d=getopt(argc,argv,"qhi"))!=(char)-1) {
 
41
                switch(d) {
 
42
                case 'q':
 
43
                        quiet_mode = 1;
 
44
                        break;
 
45
                case 'v':
 
46
                        show_version(progname);
 
47
                        exit(0);
 
48
                        break;
 
49
                case 'h':
 
50
                default:
 
51
                        show_help(progname);
 
52
                        exit(0);
 
53
                        break;
 
54
                }
 
55
        }
 
56
 
 
57
        if( optind<argc ) {
 
58
                infile = fopen(argv[optind], "r");
 
59
                if(!infile) {
 
60
                        fprintf(stderr,"%s: couldn't open %s: %s\n",progname,argv[optind],strerror(errno));
 
61
                        return 1;
 
62
                }
 
63
                optind++;
 
64
        } else {
 
65
                infile = stdin;
 
66
        }
 
67
 
 
68
        if( optind<argc ) {
 
69
                outfile = fopen(argv[optind],"w");
 
70
                if(!outfile) {
 
71
                        fprintf(stderr,"%s: couldn't open %s: %s\n",progname,argv[optind],strerror(errno));
 
72
                        return 1;
 
73
                }
 
74
                optind++;
 
75
        } else {
 
76
                outfile = stdout;
 
77
        }
 
78
 
 
79
        while((c=cseq_read(infile))) {
 
80
                struct seq *s = cseq_uncompress(c);
 
81
                seq_print(outfile,s);
 
82
                seq_free(s);
 
83
                cseq_free(c);
 
84
                count++;
 
85
        }
 
86
 
 
87
        if(!quiet_mode) {
 
88
                fprintf(stderr,"%d sequences uncompressed.\n",count);
 
89
        }
 
90
 
 
91
        fclose(infile);
 
92
        fclose(outfile);
 
93
 
 
94
        return 0;
 
95
}