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