Mercurial > repos > chrisd > testshed
comparison gene_fraction/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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0fd352f62446 |
---|---|
1 #include "Fasta.h" | |
2 | |
3 #include <iostream> | |
4 #include <fstream> | |
5 #include <vector> | |
6 #include <string> | |
7 | |
8 Fasta::Fasta(std::string amr_fp) : _amr_fp(amr_fp) {} | |
9 | |
10 void Fasta::read_fasta(const std::string &amr_fp) { | |
11 std::ifstream in(amr_fp.c_str()); | |
12 if(!in) { | |
13 std::cerr << "Could not open fasta file " << amr_fp << std::endl; | |
14 exit(EXIT_FAILURE); | |
15 } | |
16 | |
17 std::string gene_id, gene, line; | |
18 while(std::getline(in, line)) { | |
19 std::size_t gene_idx = line.find(" "); | |
20 | |
21 if(gene_idx != std::string::npos) | |
22 gene_id = line.substr(1, gene_idx-1); | |
23 else | |
24 gene_id = line.substr(1, line.length()); | |
25 | |
26 std::getline(in, gene); | |
27 records.push_back(FastaRecord(gene_id, gene)); | |
28 } | |
29 in.close(); | |
30 | |
31 FastaRecord::sort_by_gene_id(records); | |
32 } | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 |