1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/*
* =====================================================================================
*
* Filename: FASTASequence_gtest.cpp
*
* Description: Test pbdata/FASTASequence.hpp
*
* Version: 1.0
* Created: 10/29/2012 05:19:13 PM
* Revision: none
* Compiler: gcc
*
* Author: Yuan Li (yli), yli@pacificbiosciences.com
* Company: Pacific Biosciences
*
* =====================================================================================
*/
#include <climits>
#include <fstream>
#include <iostream>
#include <gtest/gtest.h>
#include <pbdata/FASTASequence.hpp>
class FASTASequenceTest : public ::testing::Test
{
public:
virtual void SetUp() {}
virtual void TearDown()
{
fastaOne.Free();
fastaTwo.Free();
fastaThree.Free();
}
FASTASequence fastaOne;
FASTASequence fastaTwo;
FASTASequence fastaThree;
std::streambuf* sbuf;
std::ofstream ofs;
};
//Test FASTASequence
TEST_F(FASTASequenceTest, ALLFUNC)
{
// Test constructor
EXPECT_TRUE(fastaOne.title == NULL);
EXPECT_TRUE(fastaOne.titleLength == 0);
EXPECT_TRUE(fastaOne.seq == NULL);
EXPECT_TRUE(fastaOne.length == 0);
EXPECT_FALSE(fastaOne.deleteOnExit);
EXPECT_EQ(fastaOne.GetStorageSize(), 0);
DNASequence dna;
Nucleotide thisNuc[] = "ATGCATGCTC";
dna.seq = thisNuc;
dna.length = 10;
int titleLength = 22;
std::string title("fasta_seq_one comments");
fastaOne.title = new char[titleLength];
memcpy(fastaOne.title, title.c_str(), titleLength);
fastaOne.titleLength = titleLength;
EXPECT_EQ(fastaOne.GetName(), std::string("fasta_seq_one"));
fastaOne.seq = thisNuc;
fastaOne.length = 10;
// use ShallowCopy carefully, since title may double free
// fastaTwo.ShallowCopy(fastaOne);
// EXPECT_EQ(fastaTwo.seq, fastaOne.seq);
// EXPECT_EQ(fastaTwo.title, fastaOne.title);
// Test AppendToTitle
fastaOne.AppendToTitle(std::string("XXX"));
EXPECT_EQ(fastaOne.titleLength, 26);
std::string newTitle = "fasta_seq_one commentsXXX";
EXPECT_STREQ(fastaOne.title, newTitle.c_str());
// Test ReverseComplementSelf()
fastaOne.ReverseComplementSelf();
std::string rcSeq = "GAGCATGCAT";
for (size_t i = 0; i < rcSeq.size(); i++) {
EXPECT_EQ(fastaOne.seq[i], rcSeq[i]);
}
// Test operator =
fastaTwo = fastaOne;
EXPECT_NE(fastaOne.title, fastaTwo.title);
EXPECT_EQ(fastaOne.titleLength, fastaTwo.titleLength);
EXPECT_STREQ(fastaOne.title, fastaTwo.title);
EXPECT_NE(fastaOne.seq, fastaTwo.seq);
for (size_t i = 0; i < fastaOne.length; i++) {
EXPECT_EQ(fastaOne.seq[i], fastaTwo.seq[i]);
}
// Test MakeRC(rhs&)
fastaOne.MakeRC(fastaThree);
// Test PrintSeq
std::stringstream ss;
fastaThree.PrintSeq(ss);
std::string thisTitle, thisComment, thisSeq;
ss >> thisTitle;
ss >> thisComment;
ss >> thisSeq;
EXPECT_EQ(thisTitle, ">fasta_seq_one");
EXPECT_EQ(thisComment, "commentsXXX");
EXPECT_EQ(thisSeq, "ATGCATGCTC");
}
TEST_F(FASTASequenceTest, CopyFromString)
{
std::string name = "read_name";
std::string seq = "ATGGGCGC";
fastaOne.Copy(name, seq);
EXPECT_EQ(fastaOne.title, name);
EXPECT_EQ(fastaOne.length, seq.size());
EXPECT_EQ(fastaOne.deleteOnExit, true);
for (size_t i = 0; i < fastaOne.length; i++) {
EXPECT_EQ(fastaOne.seq[i], seq[i]);
}
// Copy sequence from another string.
std::string seq2 = "GGTTGTG";
fastaOne.Copy(seq2);
// Name not changed.
EXPECT_EQ(fastaOne.title, name);
EXPECT_EQ(fastaOne.length, seq2.size());
EXPECT_EQ(fastaOne.deleteOnExit, true);
for (size_t i = 0; i < fastaOne.length; i++) {
EXPECT_EQ(fastaOne.seq[i], seq2[i]);
}
}
TEST_F(FASTASequenceTest, ReverseComplementSelf)
{
const std::string name = "fasta-seq-name";
const std::string s = "TTAAGG";
const std::string r = "CCTTAA";
fastaOne.Copy(name, s);
EXPECT_EQ(fastaOne.title, name);
EXPECT_EQ(fastaOne.ReverseComplementSelf().ToString(), r);
EXPECT_EQ(fastaOne.title, name);
EXPECT_EQ(fastaOne.ReverseComplementSelf().ToString(), s);
FASTASequence fastaTwo;
fastaTwo.ReferenceSubstring(fastaOne, 1, 3);
fastaTwo.CopyTitle(fastaOne.title);
EXPECT_EQ(fastaTwo.deleteOnExit, false);
EXPECT_EQ(fastaTwo.title, name);
EXPECT_EQ(fastaTwo.ToString(), "TAA");
EXPECT_EQ(fastaTwo.ReverseComplementSelf().ToString(), "TTA");
EXPECT_EQ(fastaTwo.title, name);
EXPECT_EQ(fastaTwo.deleteOnExit, true);
}
|