1 #ifndef _META_VELVET_G_HH_
2 #define _META_VELVET_G_HH_
3 #include <stdio.h>
4 #include <string.h>
5 #include <string>
6 #include <iostream>
7 #include "../VelvetAPI/VelvetHeaders.hh"
8 #include "../VelvetAPI/VelvetUtils.hh"
9 #include "../Common/FileUtils.hh"
10 #include "../Common/MetaGraph.hh"
11 #include "../Peak/PeakDetectorParameters.hh"
12 #include "../Peak/PeakDetectorFactory.hh"
13 #include "FileNameUtils.hh"
14 #include "AppsDefs.hh"
15 
16 #define META_VELVET_G_PARAMETER_VALUE_NOT_SPECIFIED -1
17 #define META_VELVET_G_SD_RATIO_FOR_GUESS 0.10
18 #define META_VELVET_G_COVERAGE_DELIM_CHAR "_"
19 #define META_VELVET_G_MAX_NUM_COVERAGE_PEAKS PEAK_DETECTOR_MAX_NUM_COVERAGE_PEAKS
20 #define META_VELVET_G_DEFAULT_MIN_PEAK_COVERAGE 0.0
21 #define META_VELVET_G_DEFAULT_MAX_PEAK_COVERAGE 500.0
22 #define META_VELVET_G_DEFAULT_HISTO_BIN_WIDTH 1.0
23 #define META_VELVET_G_DEFAULT_HISTO_SN_RATIO 10.0
24 #define META_VELEVTG_DEFAULT_MAX_CHIMERA_RATE 0.0
25 #define META_VELVETG_DEFAULT_REPEAT_COVERAGE_SD 0.10
26 #define META_VELVETG_DEFAULT_MIN_SPLIT_LENGTH 0
27 #define META_VELVETG_DEFAULT_NUM_VALID_CONNECTIONS 1
28 #define META_VELVETG_DEFAULT_NUM_NOISE_CONNECTIONS 0
29 
30 using namespace std;
31 
32 class MetaVelvetG {
33   string prefix;
34   bool flagEstimateCoverageCutoff;
35   bool flagEstimateExpectedCoverage;
36   bool flagEstimateExpectedCoverages;
37   bool flagReadTracking;
38   bool flagScaffolding;
39   bool flagExportUnusedReads;
40   bool flagExportFilteredNodes;
41   bool flagExportAmos;
42   bool flagExportAlignments;
43   boolean flagMatePair[CATEGORIES];
44   int accelerationBits;
45   long minContigLength;
46   long minContigKmerLength;
47   double coverageMask;
48   double coverageCutoff;
49   double maxCoverageCutoff;
50   double longCoverageCutoff;
51   double expectedCoverage;
52   double insertLength[CATEGORIES];
53   double insertLengthSD[CATEGORIES];
54   double longInsertLength;
55   double longInsertLengthSD;
56   bool flagDiscardChimera;
57   int numCoveragePeaks;
58   double maxChimeraRate;
59   double repeatCoverageSD;
60   double expectedCoverages[META_VELVET_G_MAX_NUM_COVERAGE_PEAKS];
61   double coverageBoundaries[META_VELVET_G_MAX_NUM_COVERAGE_PEAKS];
62   size_t minSplitLength;
63   double minPeakCoverage, maxPeakCoverage, histoBinWidth, histoSnRatio;
64   bool flagUseConnections;
65   size_t numValidConnections, numNoiseConnections;
66   bool flagReportSplitDetail;
67   bool flagReportSubgraph;
68   void setDefaultParameters();
69   bool checkParameters() const;
70   bool checkMetaHistoParameters() const;
71   bool checkParameters( int argc, char* argv[] ) const;
72   bool checkArgc( int argc ) const;
73   bool checkPrefix( int argc, char* argv[] ) const;
74   bool checkMandatoryFiles( string prefix ) const;
75   bool checkCategory( int cat ) const;
76   bool checkCoverageOrder() const;
77   void printUsage() const;
78   bool setParameters( int argc, char* argv[] );
79   bool setParameter( char* name, char* val );
80   bool setCoverageCutoff( char* val );
81   bool setExpectedCoverage( char* val );
82   bool setLongCoverageCutoff( char* val );
83   bool setInsertLength( int cat, char* val );
84   bool setInsertLengthSD( int cat, char* val );
85   bool setLongInsertLength( char* val );
86   bool setLongInsertLengthSD( char* val );
87   bool setFlagReadTracking( char* val );
88   bool setFlagScaffolding( char* val );
89   bool setFlagExportFilteredNodes( char* val );
90   bool setFlagExportAmos( char* val );
91   bool setFlagExportAlignments( char* val );
92   bool setMinContigLength( char* val );
93   bool setCoverageMask( char* val );
94   bool setAccelerationBits( char* val );
95   bool setMaxBranchLength( char* val );
96   bool _setMaxDivergence( char* val );
97   bool setMaxGapCount( char* val );
98   bool setMinPairCount( char* val );
99   bool setMaxCoverage( char* val );
100   bool setLongMultiCutoff( char* val );
101   bool _setPairedExpFraction( char* val );
102   bool setFlagExportUnusedReads( char* val );
103   bool setFlagMatePair( int cat, char* val );
104   bool setFlagDiscardChimera( char* val );
105   bool setMaxChimeraRate( char* val );
106   bool setExpectedCoverages( char* val );
107   bool setRepeatCoverageSD( char* val );
108   bool setMinSplitLength( char* val );
109   bool setMinPeakCoverage( char* val );
110   bool setMaxPeakCoverage( char* val );
111   bool setHistoBinWidth( char* val );
112   bool setHistoSnRatio( char* val );
113   bool setFlagUseConnections( char* val );
114   bool setNumNoiseConnections( char* val );
115   bool setNumValidConnections( char* val );
116   bool setFlagReportSplitDetail( char* val );
117   bool setFlagReportSubgraph( char* val );
118   string getInitialGraphFileName() const;
119   void guessNonMandatoryParameters();
120   void guessInsertLengthSD();
121   static bool isGuessInsertLengthSD( double ave, double sd );
122   static double guessInsertLengthSD( double ave );
123   void guessCoverageFlags();
124 public:
125   MetaVelvetG( int argc, char* argv[] );
126   void constructPregraph() const;
127   MetaGraph* loadGraph() const;
128   void setInsertLengths( MetaGraph* metaGraph ) const;
129   void setSplitJudge( MetaGraph* metaGraph ) const;
130   void setSubgraphOptions( MetaGraph* metaGraph ) const;
131   void estimateCoverage( MetaGraph* metaGraph );
132   void estimateExpectedCoverages( MetaGraph* metaGraph );
133   PeakDetectorParameters* getPeakDetectorParameters() const;
134   void estimateExpectedCoverage( MetaGraph* metaGraph );
135   void estimateCoverageCutoff( MetaGraph* metaGraph );
136   void removeNodes( MetaGraph* metaGraph );
137   void scaffolding( MetaGraph* metaGraph );
138   void finalize( MetaGraph* metaGraph );
139   void output( MetaGraph* metaGraph );
140 };
141 
142 #endif // _META_VELVET_G_HH_
143