1 #include "SoloFeature.h"
2 #include "streamFuns.h"
3 #include "TimeFunctions.h"
4 #include "SequenceFuns.h"
5 #include "ErrorWarning.h"
6 
processRecords()7 void SoloFeature::processRecords()
8 {
9     if (pSolo.type==0)
10         return;
11 
12     time_t rawTime;
13     time(&rawTime);
14     P.inOut->logMain << timeMonthDayTime(rawTime) << " ... Starting Solo post-map for " <<SoloFeatureTypes::Names[featureType] <<endl;
15 
16     outputPrefix= P.outFileNamePrefix+pSolo.outFileNames[0];
17     outputPrefix+= SoloFeatureTypes::Names[featureType] +'/';
18     outputPrefixFiltered= outputPrefix + "filtered/";
19 
20     if (mkdir(outputPrefix.c_str(),P.runDirPerm)!=0 && errno!=EEXIST) {//create directory
21         ostringstream errOut;
22         errOut << "EXITING because of fatal OUTPUT FILE error: could not create Solo output directory"<<outputPrefix<<"\n";
23         errOut << "SOLUTION: check the path and permisssions";
24         exitWithError(errOut.str(),std::cerr, P.inOut->logMain, EXIT_CODE_PARAMETER, P);
25     };
26 
27     //prepare for feature-specific counting:
28     if (featureType==SoloFeatureTypes::SJ && P.sjAll[0].empty()) {
29         ifstream &sjIn = ifstrOpen(P.outFileTmp+"SJ.start_gap.tsv",  ERROR_OUT, "SOLUTION: re-run STAR", P);
30         P.sjAll[0].reserve(10000000);
31         P.sjAll[1].reserve(10000000);
32         uint64 start1, gap1;
33         while ( sjIn >> start1 >> gap1 ) {
34             P.sjAll[0].emplace_back(start1);
35             P.sjAll[1].emplace_back(gap1);
36         };
37         sjIn.close();
38         P.inOut->logMain <<"Read splice junctions for Solo SJ feature: "<< P.sjAll[0].size() <<endl;
39     };
40 
41     SoloFeature::sumThreads();
42 
43     //call counting method
44     if (featureType==SoloFeatureTypes::Velocyto) {
45         countVelocyto();
46     } else if (featureType==SoloFeatureTypes::Transcript3p) {
47         quantTranscript();
48         return;
49     } else {//all others, standard processing
50         if (pSolo.type==pSolo.SoloTypes::SmartSeq) {
51             countSmartSeq();
52         } else {
53             countCBgeneUMI();
54         };
55     };
56 
57     if (!(pSolo.multiMap.yes.multi && (featureType==SoloFeatureTypes::Gene || featureType==SoloFeatureTypes::GeneFull)))
58         readFeatSum->stats.V[readFeatSum->stats.nMatch] += readFeatSum->stats.V[readFeatSum->stats.nAmbigFeature];
59 
60     //output
61     ofstream *statsStream = &ofstrOpen(outputPrefix+"Features.stats",ERROR_OUT, P);
62     readFeatSum->statsOut(*statsStream);
63     statsStream->close();
64 
65     time(&rawTime);
66     P.inOut->logMain << timeMonthDayTime(rawTime) << " ... Solo: writing raw matrix" <<endl;
67 
68     //output nU per gene per CB
69     outputResults(false,  outputPrefix + "/raw/"); //unfiltered
70 
71     time(&rawTime);
72     P.inOut->logMain << timeMonthDayTime(rawTime) << " ... Solo: cell filtering" <<endl;
73     cellFiltering();
74 
75     //summary stats output
76     statsOutput();
77 
78     //delete big arrays allocated in the previous functions
79     //delete[] indCB;
80 };
81