File: FastaIO.h

package info (click to toggle)
abyss 2.3.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,284 kB
  • sloc: cpp: 78,182; ansic: 6,512; makefile: 2,252; perl: 672; sh: 509; haskell: 412; python: 4
file content (45 lines) | stat: -rw-r--r-- 955 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef FASTAIO_H
#define FASTAIO_H 1

#include "Graph/Properties.h"
#include <boost/graph/graph_traits.hpp>
#include <cassert>
#include <istream>
#include <sstream>
#include <string>

using boost::graph_traits;

/** Read the vertices from a FASTA file. */
template <typename Graph>
std::istream& read_fasta(std::istream& in, Graph& g)
{
	assert(in);

	typedef typename graph_traits<Graph>::vertex_descriptor V;
	typedef typename vertex_property<Graph>::type VP;

	for (std::string uname;
			in.peek() != EOF && in >> expect(">") >> uname;) {
		std::string comment;
		getline(in, comment);
		assert(in);
		std::istringstream ss(comment);
		VP vp;
		ss >> vp;
		size_t n = 0;
		while (in >> std::ws && in.peek() != '>' && in) {
			in >> Ignore('\n');
			assert(in);
			assert(in.gcount() > 1);
			n += in.gcount() - 1;
		}
		put(vertex_length, vp, n);
		V u = add_vertex(vp, g);
		put(vertex_name, g, u, uname);
	}
	assert(in.eof());
	return in;
}

#endif