annotate snp_caller/src/Fasta.cpp @ 0:0fd352f62446 draft default tip

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