~ubuntu-branches/ubuntu/oneiric/libbpp-seq/oneiric

« back to all changes in this revision

Viewing changes to src/Bpp/Seq/Io/PhredPhd.h

  • Committer: Bazaar Package Importer
  • Author(s): Julien Dutheil
  • Date: 2011-06-09 11:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110609110000-hnfrd9it0np58l54
Tags: upstream-2.0.2
Import upstream version 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// File: PhredPhd.h
 
3
// Created by: Sylvain Gaillard
 
4
// Created on: Wed Nov 5 2008
 
5
//
 
6
 
 
7
/*
 
8
Copyright or © or Copr. CNRS, (November 5, 2008)
 
9
 
 
10
This software is a computer program whose purpose is to provide classes
 
11
for sequences analysis.
 
12
 
 
13
This software is governed by the CeCILL  license under French law and
 
14
abiding by the rules of distribution of free software.  You can  use, 
 
15
modify and/ or redistribute the software under the terms of the CeCILL
 
16
license as circulated by CEA, CNRS and INRIA at the following URL
 
17
"http://www.cecill.info". 
 
18
 
 
19
As a counterpart to the access to the source code and  rights to copy,
 
20
modify and redistribute granted by the license, users are provided only
 
21
with a limited warranty  and the software's author,  the holder of the
 
22
economic rights,  and the successive licensors  have only  limited
 
23
liability. 
 
24
 
 
25
In this respect, the user's attention is drawn to the risks associated
 
26
with loading,  using,  modifying and/or developing or reproducing the
 
27
software by the user in light of its specific status of free software,
 
28
that may mean  that it is complicated to manipulate,  and  that  also
 
29
therefore means  that it is reserved for developers  and  experienced
 
30
professionals having in-depth computer knowledge. Users are therefore
 
31
encouraged to load and test the software's suitability as regards their
 
32
requirements in conditions enabling the security of their systems and/or 
 
33
data to be ensured and,  more generally, to use and operate it in the 
 
34
same conditions as regards security. 
 
35
 
 
36
The fact that you are presently reading this means that you have had
 
37
knowledge of the CeCILL license and that you accept its terms.
 
38
*/
 
39
 
 
40
#ifndef _PHREDPHD_H_
 
41
#define _PHREDPHD_H_
 
42
 
 
43
#include "ISequenceStream.h"
 
44
#include "../Sequence.h"
 
45
#include "../SequenceWithQuality.h"
 
46
 
 
47
namespace bpp {
 
48
 
 
49
  /**
 
50
   * @brief The phd sequence file format from phred software.
 
51
   *
 
52
   * This class read DNA SequenceWithQuality from phd files produced by the
 
53
   * phred program from the University of Washington.
 
54
   *
 
55
   * @par Usage
 
56
   *
 
57
   * @code
 
58
   * // Creating a SequenceWithQuality object
 
59
   * DNA alpha;
 
60
   * SequenceWithQuality seq(&alpha);
 
61
   * std::vector<int> pos;
 
62
   *
 
63
   * // Create a PhredPhd parser
 
64
   * PhredPhd pp;
 
65
   *
 
66
   * // Opening the file
 
67
   * std::ifstream in("my_sequence.phd");
 
68
   *
 
69
   * // Read the sequence
 
70
   * pp.nextSequence(in, seq, pos);
 
71
   *
 
72
   * // Close the file
 
73
   * in.close();
 
74
   * @endcode
 
75
   *
 
76
   * @author Sylvain Gaillard
 
77
   */
 
78
  class PhredPhd: public ISequenceStream {
 
79
    public:
 
80
 
 
81
      /**
 
82
       * @brief Build a new PhredPhd object.
 
83
       */
 
84
      PhredPhd() {}
 
85
 
 
86
      virtual ~PhredPhd() {}
 
87
 
 
88
    public:
 
89
      /**
 
90
       * @name The ISequenceStream interface.
 
91
       *
 
92
       * @{
 
93
       */
 
94
      void nextSequence(
 
95
          std::istream& input,
 
96
          Sequence& seq
 
97
          ) const throw (Exception);
 
98
      /** @} */
 
99
 
 
100
      /**
 
101
       * @brief Read a SequenceWithQuality from stream
 
102
       *
 
103
       */
 
104
      void nextSequence(
 
105
          std::istream& input,
 
106
          SequenceWithQuality& seq
 
107
          ) const throw (Exception);
 
108
      
 
109
      /**
 
110
       * @brief Read a SequenceWithQuality from stream and store chromatographic positions
 
111
       *
 
112
       * A more complete parser that read a SequenceWithQuality and store
 
113
       * the position of each base call on the chromatogram in a vector of
 
114
       * int.
 
115
       *
 
116
       * @param input The stram to read.
 
117
       * @param seq The sequence to fill.
 
118
       * @param pos The vector of positions to fill.
 
119
       * @throw Exception IOException and Sequence related exceptions.
 
120
       */
 
121
      void nextSequence(
 
122
          std::istream& input,
 
123
          SequenceWithQuality& seq,
 
124
          std::vector<int>& pos
 
125
          ) const throw (Exception);
 
126
 
 
127
      /**
 
128
       * @name The IOFormat interface.
 
129
       *
 
130
       * @{
 
131
       */
 
132
      const std::string getDataType() const { return "SequenceWithQuality"; };
 
133
      const std::string getFormatName() const { return "phd file"; };
 
134
      const std::string getFormatDescription() const {
 
135
        return "Sequences following the phd format as describe in the phred documentation.";
 
136
      }
 
137
      /** @} */
 
138
 
 
139
    private:
 
140
      /**
 
141
       * @brief Global file parser
 
142
       *
 
143
       * @param input The stream to read
 
144
       * @param name The string to store the sequence name
 
145
       * @param sequence The string to store the sequence
 
146
       * @param qual The vector to store qualities
 
147
       * @param pos The vector to store positions
 
148
       */
 
149
      void parseFile_(std::istream& input, std::string& name, std::string& sequence, std::vector<int>& qual, std::vector<int>& pos) const;
 
150
 
 
151
      /**
 
152
       * @brief Parse the DNA part of the file
 
153
       *
 
154
       * Read the DNA part until `END_DNA' or EOF.
 
155
       *
 
156
       * @param input The stream to read
 
157
       * @param sequence The string to store the sequence
 
158
       * @param qual The vector to store qualities
 
159
       * @param pos The vector to store positions
 
160
       */
 
161
      void parseDNA_(std::istream& input, std::string& sequence, std::vector<int>& qual, std::vector<int>& pos) const;
 
162
  };
 
163
} //end of namespace bpp
 
164
 
 
165
#endif // _PHREDPHD_H_