File: tools.cpp

package info (click to toggle)
hilive 2.0a-5
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 956 kB
  • sloc: cpp: 4,723; python: 241; xml: 188; sh: 35; makefile: 14
file content (72 lines) | stat: -rw-r--r-- 1,866 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "tools.h"

////////////////////////////////////
////////// SAM/BAM output //////////
////////////////////////////////////

seqan2::BamHeader getBamHeader() {
	std::stringstream ss;
	ss.str(std::string());
	ss << HiLive_VERSION_MAJOR << "." << HiLive_VERSION_MINOR;

	seqan2::BamHeader header;
	resize(header, 2);

	// @HD header.
	seqan2::resize(header[0].tags, 2);
	header[0].type = seqan2::BAM_HEADER_FIRST;
	header[0].tags[0].i1 = "VN";
	header[0].tags[0].i2 = "1.5";
	header[0].tags[1].i1 = "GO";
	header[0].tags[1].i2 = "query";

	// @PG header.
	seqan2::resize(header[1].tags, 3);
	header[1].type = seqan2::BAM_HEADER_PROGRAM;
	header[1].tags[0].i1 = "ID";
	header[1].tags[0].i2 = "hilive";
	header[1].tags[1].i1 = "PN";
	header[1].tags[1].i2 = "HiLive";
	header[1].tags[2].i1 = "VN";
	header[1].tags[2].i2 = ss.str();

	return header;
}

std::string reverse_mdz(std::string mdz) {

	std::string reverse = "";
	std::string next_match = "";

	for ( auto string_it = mdz.rbegin(); string_it!=mdz.rend(); ++string_it) {
		if ( seq_chars.find(*string_it) != std::string::npos ) {
			std::reverse(next_match.begin(), next_match.end());
			reverse += next_match;
			next_match = "";
			reverse += comp(*string_it);
		}
		else {
			next_match += *string_it;
		}
	}
	std::reverse(next_match.begin(), next_match.end());
	reverse += next_match;
	return reverse;
}


/////////////////////////////////
////////// Other stuff //////////
/////////////////////////////////

int atomic_rename( const char *oldname, const char *newname ) {

	if ( !file_exists(oldname) )
		throw file_not_exist_error("Can't rename file: " + std::string(oldname) + ". File does not exist.");

	std::lock_guard<std::mutex> old_lock(fileLocks.at(std::string(oldname)));
	std::lock_guard<std::mutex> new_lock(fileLocks.at(std::string(newname)));

	return std::rename(oldname, newname);

}