-
Notifications
You must be signed in to change notification settings - Fork 0
/
chromium_reads_remove_barcodes.cpp
58 lines (52 loc) · 1.68 KB
/
chromium_reads_remove_barcodes.cpp
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
/*
Program to remove barcodes and linkers from FASTQ files of Chromium reads.
Author: Eerik Aunin. Copyright (C) 2018, 2019 Genome Research Ltd.
This program is distributed under the terms of the GNU General Public License.
Argument1: path to FASTQ file of reads #1 of Chromium paired end reads.
Output: FASTQ file where the first 22 nucleotides (bar code and linker) have been deleted.
Compiling (requires g++ version >= 4.3, has been tested with gcc-8.2.0 on Ubuntu Linux):
g++ -std=c++11 chromium_reads_remove_barcodes.cpp -o chromium_reads_remove_barcodes
*/
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int main(int argc, char **argv) {
if (argc == 2) {
std::string file_path(argv[1]);
std::ifstream file(file_path.c_str());
if (file.good()) {
std::string str;
int counter = 0;
int bar_code_and_linker_length = 22;
while (std::getline(file, str)) {
int size = str.length();
int line_type = counter % 4;
if (line_type == 1 || line_type == 3) {
string str2;
if (size > bar_code_and_linker_length) {
str2 = str.substr(bar_code_and_linker_length + 1, size - bar_code_and_linker_length);
} else {
cout << "Encountered a sequence that is too short" << endl;
break;
exit(EXIT_FAILURE);
}
cout << str2 << endl;
} else {
cout << str << endl;
}
++counter;
}
} else {
cout << file_path << ": file not found" << endl;
exit(EXIT_FAILURE);
}
} else {
cout << argv[0] << ": tool for removing barcodes and linkers from Chromium read FASTQ files" << endl;
cout << "Usage: ";
cout << argv[0] << " [FASTQ file]" << endl;
exit(EXIT_FAILURE);
}
return 0;
}