File: testvsearchfileparser.cpp

package info (click to toggle)
mothur 1.48.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,692 kB
  • sloc: cpp: 161,866; makefile: 122; sh: 31
file content (117 lines) | stat: -rw-r--r-- 4,454 bytes parent folder | download | duplicates (4)
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
//
//  testvsearchfileparser.cpp
//  Mothur
//
//  Created by Sarah Westcott on 3/24/16.
//  Copyright (c) 2016 Schloss Lab. All rights reserved.
//


#include "testvsearchfileparser.h"

/**************************************************************************************************/
TestVsearchFileParser::TestVsearchFileParser() {  //setup
    m = MothurOut::getInstance();
    TestDataSet data;
    filenames = data.getSubsetFNGFiles();
    ct = data.getCountTable();
}
/**************************************************************************************************/
TestVsearchFileParser::~TestVsearchFileParser() {
    delete ct;
}
/**************************************************************************************************

TEST_CASE("Testing VsearchParser Class") {
    TestVsearchFileParser testVParser;
    VsearchFileParser vsearchParser(testVParser.filenames[0], testVParser.filenames[1], "name");
    
    SECTION("CreateVsearchFasta") {
        INFO("Using First 100 sequences of final.fasta and final.names") // Only appears on a FAIL
        
        CAPTURE(vsearchParser.getVsearchFile()); // Displays this variable on a FAIL
        
        CHECK(vsearchParser.getVsearchFile() == "tempSeqs.txt.sorted.fasta.temp");
        
        ifstream in;
        testVParser.util.openInputFile(vsearchParser.getVsearchFile(), in);
        
        while (!in.eof()) {
            Sequence seq(in); testVParser.util.gobble(in);
            
            vector<string> pieces;
            string name = seq.getName();
            
            testVParser.util.splitAtChar(name, pieces, '=');
            string abundString = pieces[1].substr(0, pieces[1].length()-1);
            int abund = 0;
            testVParser.util.mothurConvert(abundString, abund);
            int totalSeqs = testVParser.ct->getNumSeqs(testVParser.removeAbundances(name));
            
            CHECK(abund == totalSeqs);
        }
        in.close();
        testVParser.util.mothurRemove("tempSeqs.txt.sorted.fasta.temp");
    }
    
    SECTION("Remove Abundances") {
        INFO("Using GQY1XT001C44N8/size=3677/") // Only appears on a FAIL
        string seqName = "GQY1XT001C44N8/size=3677/";
        CAPTURE(testVParser.removeAbundances(seqName)); // Displays this variable on a FAIL
        
        CHECK(testVParser.removeAbundances(seqName) == "GQY1XT001C44N8");
    }
    
    
    SECTION("Create List File") {
        INFO("Using lines like: S	1	275	*	*	*	*	*	GQY1XT001C44N8/ab=3677/	*") // Only appears on a FAIL
        
        vsearchParser.getVsearchFile();
        ifstream in;
        testVParser.util.openInputFile(vsearchParser.getVsearchFile(), in);
        
        vector<string> seqNames;
        while (!in.eof()) {
            Sequence seq(in); testVParser.util.gobble(in);
            string name = seq.getName();
            seqNames.push_back(name);
        }
        in.close();
        testVParser.util.mothurRemove("tempSeqs.txt.sorted.fasta.temp");
        
        ofstream out;
        testVParser.util.openOutputFile("temp.txt", out);
        map<int, string> binNames;
        for (int i = 0; i < seqNames.size(); i++) {
            int bin = (i+1)%10;
            string name = testVParser.removeAbundances(seqNames[i]);
            //name = (testVParser.data.getNameMap())[name]; //dup names
            out << "S\t" + toString(bin) + "\t275\t*\t*\t*\t*\t*\t" + seqNames[i] + "\t*\n";
            
            map<int, string>::iterator it = binNames.find(bin);
            if (it != binNames.end()) { it->second += "," + name; }
            else { binNames[bin] = name; }
        }
        out.close();
        
        int numBins = binNames.size();
        
        testVParser.createListFile("temp.txt", "temp.list", "temp.rabund", "temp.sabund", numBins, "0.03");
        
        ifstream in2;
        testVParser.util.openInputFile("temp.list", in2);
        ListVector list2(in2);
        in2.close();
        testVParser.util.mothurRemove("temp.list"); testVParser.util.mothurRemove("temp.rabund"); testVParser.util.mothurRemove("temp.sabund");
        
        //for each bin
        for (int i = 0; i < list2.getNumBins(); i++) {
            string binnames = list2.get(i);
            
            CAPTURE(binnames);
            
            CHECK(binnames == binNames[i]);
        }
    }
}*/
/**************************************************************************************************/