annotate gene_fraction/src/Fasta.cpp @ 0:f95150c37d38 draft default tip

planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
author chrisd
date Sun, 21 Feb 2016 23:31:55 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
1 #include "Fasta.h"
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
2 #include "args.h"
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
3
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
4 #include <iostream>
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
5 #include <fstream>
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
6 #include <vector>
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
7 #include <string>
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
8
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
9 Fasta::Fasta(std::string amr_fp) : _amr_fp(amr_fp) {}
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
10
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
11 void Fasta::read_fasta(const std::string &amr_fp) {
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
12 std::ifstream in(amr_fp.c_str());
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
13 if(!in) {
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
14 usage();
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
15 exit(EXIT_FAILURE);
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
16 }
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
17
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
18 std::string gene_id, gene, line;
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
19 while(std::getline(in, line)) {
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
20 std::size_t gene_idx = line.find(" ");
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
21
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
22 if(gene_idx != std::string::npos)
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
23 gene_id = line.substr(1, gene_idx-1);
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
24 else
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
25 gene_id = line.substr(1, line.length());
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
26
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
27 std::getline(in, gene);
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
28 records.push_back(FastaRecord(gene_id, gene));
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
29 }
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
30 in.close();
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
31
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
32 FastaRecord::sort_by_gene_id(records);
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
33 }
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
34
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
35
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
36
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
37
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
38
f95150c37d38 planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
chrisd
parents:
diff changeset
39