]> git.donarmstrong.com Git - mothur.git/blob - seqsummarycommand.cpp
pat's edits of screen.seqs and summary.seqs
[mothur.git] / seqsummarycommand.cpp
1 /*
2  *  seqcoordcommand.cpp
3  *  Mothur
4  *
5  *  Created by Pat Schloss on 5/30/09.
6  *  Copyright 2009 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include "seqsummarycommand.h"
11
12 //***************************************************************************************************************
13
14 SeqSummaryCommand::SeqSummaryCommand(){
15         try {
16                 globaldata = GlobalData::getInstance();
17                 if(globaldata->getFastaFile() == "")            {       cout << "you need to at least enter a fasta file name" << endl; }
18         }
19         catch(exception& e) {
20                 cout << "Standard Error: " << e.what() << " has occurred in the SeqCoordCommand class Function SeqCoordCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
21                 exit(1);
22         }
23         catch(...) {
24                 cout << "An unknown error has occurred in the SeqCoordCommand class function SeqCoordCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
25                 exit(1);
26         }       
27 }
28
29 //***************************************************************************************************************
30
31 SeqSummaryCommand::~SeqSummaryCommand(){        /*      do nothing      */      }
32
33 //***************************************************************************************************************
34
35 int SeqSummaryCommand::execute(){
36         try{
37
38                 ifstream inFASTA;
39                 openInputFile(globaldata->getFastaFile(), inFASTA);
40                 int numSeqs = 0;
41
42                 ofstream outSummary;
43                 string summaryFile = globaldata->getFastaFile() + ".summary";
44                 openOutputFile(summaryFile, outSummary);
45                 
46                 vector<int> startPosition;
47                 vector<int> endPosition;
48                 vector<int> seqLength;
49                 vector<int> ambigBases;
50                 vector<int> longHomoPolymer;
51                 
52                 outSummary << "seqname\tstart\tend\tnbases\tambigs\tpolymer" << endl;                   
53
54                 while(!inFASTA.eof()){
55                         Sequence current(inFASTA);
56                         startPosition.push_back(current.getStartPos());
57                         endPosition.push_back(current.getEndPos());
58                         seqLength.push_back(current.getNumBases());
59                         ambigBases.push_back(current.getAmbigBases());
60                         longHomoPolymer.push_back(current.getLongHomoPolymer());
61
62                         outSummary << current.getName() << '\t';
63                         outSummary << current.getStartPos() << '\t' << current.getEndPos() << '\t';
64                         outSummary << current.getNumBases() << '\t' << current.getAmbigBases() << '\t';
65                         outSummary << current.getLongHomoPolymer() << endl;
66                         
67                         numSeqs++;
68                         gobble(inFASTA);
69                 }
70                 inFASTA.close();
71                 
72                 sort(startPosition.begin(), startPosition.end());
73                 sort(endPosition.begin(), endPosition.end());
74                 sort(seqLength.begin(), seqLength.end());
75                 sort(ambigBases.begin(), ambigBases.end());
76                 sort(longHomoPolymer.begin(), longHomoPolymer.end());
77                 
78                 int ptile0_25   = int(numSeqs * 0.025);
79                 int ptile25             = int(numSeqs * 0.250);
80                 int ptile50             = int(numSeqs * 0.500);
81                 int ptile75             = int(numSeqs * 0.750);
82                 int ptile97_5   = int(numSeqs * 0.975);
83                 int ptile100    = numSeqs - 1;
84                 
85                 cout << endl;
86                 cout << "\t\tStart\tEnd\tNBases\tAmbigs\tPolymer" << endl;
87                 cout << "Minimum:\t" << startPosition[0] << '\t' << endPosition[0] << '\t' << seqLength[0] << '\t' << ambigBases[0] << '\t' << longHomoPolymer[0] << endl;
88                 cout << "2.5%-tile:\t" << startPosition[ptile0_25] << '\t' << endPosition[ptile0_25] << '\t' << seqLength[ptile0_25] << '\t' << ambigBases[ptile0_25] << '\t' << longHomoPolymer[ptile0_25] << endl;
89                 cout << "25%-tile:\t" << startPosition[ptile25] << '\t' << endPosition[ptile25] << '\t' << seqLength[ptile25] << '\t' << ambigBases[ptile25] << '\t' << longHomoPolymer[ptile25] << endl;
90                 cout << "Median: \t" << startPosition[ptile50] << '\t' << endPosition[ptile50] << '\t' << seqLength[ptile50] << '\t' << ambigBases[ptile50] << '\t' << longHomoPolymer[ptile50] << endl;
91                 cout << "75%-tile:\t" << startPosition[ptile75] << '\t' << endPosition[ptile75] << '\t' << seqLength[ptile75] << '\t' << ambigBases[ptile75] << '\t' << longHomoPolymer[ptile75] << endl;
92                 cout << "97.5%-tile:\t" << startPosition[ptile97_5] << '\t' << endPosition[ptile97_5] << '\t' << seqLength[ptile97_5] << '\t' << ambigBases[ptile97_5] << '\t' << longHomoPolymer[ptile97_5] << endl;
93                 cout << "Maximum:\t" << startPosition[ptile100] << '\t' << endPosition[ptile100] << '\t' << seqLength[ptile100] << '\t' << ambigBases[ptile100] << '\t' << longHomoPolymer[ptile100] << endl;
94                 cout << "# of Seqs:\t" << numSeqs << endl;
95                 
96                 return 0;
97         }
98         catch(exception& e) {
99                 cout << "Standard Error: " << e.what() << " has occurred in the FilterSeqsCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
100                 exit(1);
101         }
102         catch(...) {
103                 cout << "An unknown error has occurred in the FilterSeqsCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
104                 exit(1);
105         }
106         
107 }
108
109 //***************************************************************************************************************
110
111