view 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
line wrap: on
line source

#include "Fasta.h"
#include "args.h"

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

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) {
		usage();
		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);
}