diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/snp_caller/src/Fasta.cpp	Sun Feb 21 06:05:24 2016 -0500
@@ -0,0 +1,33 @@
+#include "Fasta.h"
+
+#include <string>
+#include <fstream>
+#include <vector>
+#include <iostream>
+
+
+Fasta::Fasta(std::string amr_fp) : _amr_fp(amr_fp) {}
+
+void Fasta::read_fasta(const std::string &amr_fp) {
+        std::ifstream in(amr_fp.c_str());
+        if(!in) {
+                std::cerr << "Could not open fasta file " << amr_fp << std::endl;
+                exit(EXIT_FAILURE);
+        }
+
+        std::string gene_id, gene, line;
+        while(std::getline(in, line)) {
+                std::size_t gene_idx = line.find(" ");
+
+                if(gene_idx != std::string::npos)
+                        gene_id = line.substr(1, gene_idx-1);
+                else
+                        gene_id = line.substr(1, line.length());
+
+                std::getline(in, gene);
+                records.push_back(FastaRecord(gene_id, gene));
+        }
+        in.close();
+
+        FastaRecord::sort_by_gene_id(records);
+}