-
Notifications
You must be signed in to change notification settings - Fork 1
/
fsproject.cpp
4606 lines (4222 loc) · 170 KB
/
fsproject.cpp
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <vector>
#include <string>
#include <cstring>
#include <fstream>
#include <sstream>
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdexcept>
#include <exception>
#include <iostream>
#include <limits>
#include <string>
#include <algorithm>
/////////////////////////////
// Not cross platform?
#ifdef _OPENMP
#include <omp.h>
#endif
// Also need to think about mkdir from unistd.h
#include <sys/types.h>
#include <sys/stat.h>
/////////////////////////////
#include "cp/ChromoPainterMutEM.h"
#include "chromocombine/ChromoCombine.h"
#include "finestructure/fines.h"
#include "finestructure/fsxml.h"
#include "fssettings.h"
#include "fsutils.h"
#include "fsproject.h"
#include "fsconstants.h"
#include "fsdonor.h"
#include "alphanum.hpp"
using namespace std;
//////////////////////////////////////
FsProject::FsProject(std::string f,std::string d,bool verbose)
{
exec="fs";
numthreads=0;
nstages=9;
allowdep=true;
indsperproc=0;
stage=0;
outputlogfiles=true;
validatedoutput=vector<int>(nstages,0);
missingfiles=vector<int>(nstages,-1); // missing files from each stage; default: all
s1commandfile=string("");
s2commandfile=string("");
s3commandfile=string("");
s4commandfile=string("");
s6commandfile=string("");
s7commandfile=string("");
s9commandfile=string("");
// data things
nsnps=0;
ninds=0;
nindsUsed=0;
nrecipsDonor=0;
// chromopainter things
ploidy=2;
hpc=0;
linkagemode=string("unlinked");
s12args=string("");
s1args=string("-in -iM --emfilesonly");
s1minsnps=10000;// default: 10K
s1snpfrac=0.1;// fraction of genome we will use for EM
s1indfrac=1.0;// fraction of inds we will use for EM
s1emits=10;// number of EM iterations
s2args=string("");
s2combineargs=string("");
s34args=string("-X -Y");
Neinf=-1; // default: we haven't got estimates
muinf=-1; // default: we haven't got estimates
s2chunksperregion=-1; // default: can be wrong for unlinked data!
s2samples=0; // default: we don't want samples
cval=-1;// inferred "c" (we don't use this except for information, we set from the files)
paintercmd="cp";// chromopainter command. cp is the internal one, everything else must use hpc mode
// finestructure things
s3iters=numitersDefault;
maxretained=500;
s3iterssample=-1;
s3itersburnin=-1;
numskip=-1;
nummcmcruns=2;
fscounter=0;
fsmaxattempts=5;
threshGR=1.3;
// finestructure tree things
s4iters=numitersDefault;
s4args=string("");
// population - based chromopainter things
popNeinf=-1; // default: we haven't got estimates
popmuinf=-1; // default: we haven't got estimates
//
s6minsnps=s1minsnps;// minimum number of SNPs to use
s6snpfrac=s1snpfrac;// fraction of inds to use
s6indfrac=s1indfrac;// fraction of inds to use
s6emits=s1emits;// number of EM iterations
s6args=string("-in -iM --emfilesonly");
s67args=string("");
s7combineargs=string("");
s7chunksperregion=-1; // default: can be wrong for unlinked data!
s7samples=0; // default: we don't want samples
s7args=string("");
//
popcval=-1;// inferred "c" (we don't use this except for information, we set from the files)
gtbootstrapnum="20";
gtpropscutoff="0.001";
gtbinwidth="0.1";
gtnummixingiterations="5";
this->verbose=verbose;
setFileName(f);
setDirectoryName(d);
setupSections();
defineParameters();
defineCommands();
}
FsProject::~FsProject()
{
}
///////////////////////////////
void FsProject::defineParameters()
{
////// Universal properties
sectionnames.clear();
sectioncomments.clear();
pars.clear();
sectionnames.push_back("0");
sectioncomments.push_back("Data preparation and conversion. Not yet implemented");
pars.push_back(FsPar("validatedoutput",-1,"Derived. Whether we have validated output from each stage of the analysis (0-8)",1));
pars.push_back(FsPar("missingfiles",-1,"Derived. Number of output files that we think are incorrect from each stage of the analysis (0-8)",1));
parsize.push_back(pars.size());
sectionnames.push_back("1");
sectioncomments.push_back("Universal Stage1-4 properties of the analysis");
pars.push_back(FsPar("exec",-1,"Finestructure command line. Set this to be able to use a specific version of this software. (default: fs)"));
pars.push_back(FsPar("hpc",-1,"THIS IS IMPORTANT FOR BIG DATASETS! Set hpc mode. 0: Commands are run 'inline' (see 'numthreads' to control how many CPU's to use). 1: Stop computation for an external batch process, creating a file containing commands to generate the results of each stage. 2: Run commands inline, but create the commands for reference. (default: 0.)"));
pars.push_back(FsPar("numthreads",-1,"Maximum parallel threads in 'hpc=0' mode. Default: 0, meaning all available CPUs."));
pars.push_back(FsPar("paintercmd",-1,"Command to use for chromopainter. The default, internal choice is \"cp\" which is special (called by fs cp and has --emfilesonly). Changing it uses an external command, presumably ChromoPainterv2, and forces hpc mode."));
pars.push_back(FsPar("ploidy",-1,"Haplotypes per individual. =1 if haploid, 2 if diploid. (default: 2)"));
pars.push_back(FsPar("linkagemode",-1,"unlinked/linked. Whether we use the linked model. default: unlinked / linked if recombination files provided."));
pars.push_back(FsPar("indsperproc",-1,"Desired number of individuals per process (default: 0, meaning autocalculate: use 1 In HPC mode, ceiling(N/numthreads) otherwise. Try to choose it such that you get a sensible number of commands compared to the number of cores you have available."));
pars.push_back(FsPar("outputlogfiles",-1,"1=Commands are written to file with redirection to log files. 0: no redirection. (default:1)"));
pars.push_back(FsPar("allowdep",-1,"Whether dependency resolution is allowed. 0=no, 1=yes. Main use is for pipelining. (default:1)."));
parsize.push_back(pars.size());
/// Chromopainter Stage1-2 generic properties
sectionnames.push_back("1");
sectioncomments.push_back("ChromoPainter Stage1-2 generic properties");
pars.push_back(FsPar("s12inputtype",1,"What type of data input (currently only \"phase\" supported)"));
pars.push_back(FsPar("idfile",1,"IDfile location, containing the labels of each individual. REQUIRED, no default (unless -createids or -popidfile is used)."));
pars.push_back(FsPar("s12args",1,"arguments to be passed to Chromopainter (default: empty)"));
parsize.push_back(pars.size());
//Quantities observed from data
sectionnames.push_back("1");
sectioncomments.push_back("Quantities observed from data");
pars.push_back(FsPar("ninds",-1,"Derived. number of individuals observed in the idfile",1));
pars.push_back(FsPar("nindsUsed",-1,"Derived. number of individuals retained for processing from the idfile",1));
pars.push_back(FsPar("nrecipsDonor",-1,"Derived. number of individuals retained as recipients from the donor file",1));
pars.push_back(FsPar("nsnps",-1,"Derived. number of SNPs in total, over all files",1));
parsize.push_back(pars.size());
//chromopainter stage1 (EM)
sectionnames.push_back("1");
sectioncomments.push_back("ChromoPainter Stage1 (EM) properties");
pars.push_back(FsPar("s1args",1,"Arguments passed to stage1 (default:-in -iM --emfilesonly)"));
pars.push_back(FsPar("s1emits",1,"Number of EM iterations (chromopainter -i <n>, default: 10)"));
pars.push_back(FsPar("s1minsnps",1,"Minimum number of SNPs for EM estimation (for chromopainter -e, default: 10000)"));
pars.push_back(FsPar("s1snpfrac",1,"fraction of genome to use for EM estimation. (default: 0.1)"));
pars.push_back(FsPar("s1indfrac",1,"fraction of individuals to use for EM estimation. (default: 1.0)"));
pars.push_back(FsPar("s1outputroot",1,"output file for stage 1 (default is autoconstructed from filename)"));
parsize.push_back(pars.size());
//chromopainter inferred properties for stage2 from stage1
sectionnames.push_back("1");
sectioncomments.push_back("ChromoPainter Stage2 properties inferred from Stage1");
pars.push_back(FsPar("Neinf",-1,"Derived. Inferred `Effective population size Ne' (chromopainter -n).",1));
pars.push_back(FsPar("muinf",-1,"Derived. Inferred Mutation rate mu (chromopainter -M)",1));
parsize.push_back(pars.size());
//chromopainter stage2 (painting)
sectionnames.push_back("2");
sectioncomments.push_back("ChromoPainter Stage2 (main run) properties");
pars.push_back(FsPar("s2chunksperregion",2,"number of chunks in a \"region\" (-ve: use default of 100 for linked, nsnps/100 for unlinked)"));
pars.push_back(FsPar("s2samples",2,"number of samples of the painting to obtain per recipient haplotype, for examining the details of the painting. (Populates <root>.samples.out; default 0. Warning: these file can get large)"));
pars.push_back(FsPar("s2args",2,"Additional arguments for stage 2 (default: none, \"\")"));
pars.push_back(FsPar("s2outputroot",2,"Output file name for stage 2 (default: autoconstructed)."));
pars.push_back(FsPar("s2combineargs",2,"Additional arguments for stage 2 combine (fs combine; default: none, \"\")"));
parsize.push_back(pars.size());
// chromocombine inferred properties for stage3 from stage2
sectionnames.push_back("2");
sectioncomments.push_back("FineSTRUCTURE Stage3 properties inferred from Stage2");
pars.push_back(FsPar("cval",-1,"Derived. 'c' as inferred using chromopainter. This is only used for sanity checking. See s34 args for setting it manually.",1));
pars.push_back(FsPar("cproot",3,"The name of the final chromopainter output. (Default: <filename>, the project file name)"));
pars.push_back(FsPar("cpchunkcounts",3,"the finestructure input file, derived name of the chunkcounts file from cproot.",1));
parsize.push_back(pars.size());
// finestructure stage3-4 generic properties
sectionnames.push_back("3");
sectioncomments.push_back("FineSTRUCTURE Stage3-4 generic properties");
pars.push_back(FsPar("fsroot",3,"The name of the finestructure output (Default: <filename>, the project file name)."));
pars.push_back(FsPar("s34args",3,"Additional arguments to both finestructure mcmc and tree steps. Add \"-c <val>\" to manually override 'c'."));
parsize.push_back(pars.size());
// finestructure stage3 MCMC inference
sectionnames.push_back("3");
sectioncomments.push_back("FineSTRUCTURE Stage3 MCMC inference");
pars.push_back(FsPar("s3iters",3,"Number of TOTAL iterations to use for MCMC. By default we assign half to burnin and half to sampling. (default: 100000)"));
pars.push_back(FsPar("s3iterssample",3,"Number of iterations to use for MCMC (default: -ve, meaning derive from s3iters)"));
pars.push_back(FsPar("s3itersburnin",3,"Number of iterations to use for MCMC burnin (default: -ve, meaning derive from s3iters)"));
pars.push_back(FsPar("numskip",3,"Number of mcmc iterations per retained sample; (default: -ve, meaning derive from maxretained)"));
pars.push_back(FsPar("maxretained",3,"Maximum number of samples to retain when numskip -ve. (default: 500)"));
pars.push_back(FsPar("nummcmcruns",3,"Number of *independent* mcmc runs. (default: 2)"));
pars.push_back(FsPar("fsmcmcoutput",3,"Filename to use for mcmc output (default: autogenerated)"));
pars.push_back(FsPar("mcmcGR",3,"Derived. Gelman-Rubin diagnostics obtained from combining MCMC runs, for log-posterior, K,log-beta,delta,f respectively"));
pars.push_back(FsPar("threshGR",3,"Threshold for the Gelman-Rubin statistic to allow moving on to the tree building stage. We always move on if thresGR<0. (Default: 1.3)"));
parsize.push_back(pars.size());
//stage 4 finestructure tree inference
sectionnames.push_back("4");
sectioncomments.push_back("FineSTRUCTURE Stage4 tree inference");
pars.push_back(FsPar("s4args",4,"Extra arguments to the tree building step. (default: none, \"\")"));
pars.push_back(FsPar("s4iters",4,"Number of maximization steps when finding the best state from which the tree is built. (default: 100000)"));
pars.push_back(FsPar("fstreeoutput",4,"Filename to use for finestructure tree output. (default: autogenerated)"));
parsize.push_back(pars.size());
sectionnames.push_back("5");
sectioncomments.push_back("Extraction of suitable populations for admixture analysis");
pars.push_back(FsPar("popidfile",5,"ID file to use for population definition in admixture analysis. Can be autogenerated from stage4, or specified. (Default: autogenerated)"));
pars.push_back(FsPar("donoridfile",5,"Donor file to use for population definition in admixture analysis. Can be autogenerated to use all populations vs all populations, or specified. (Default: autogenerated)"));
pars.push_back(FsPar("refdonorfile",5,"Donor file to use for population definition in admixture analysis when processing samples external to this dataset. (Default: autogenerated)"));
parsize.push_back(pars.size());
sectionnames.push_back("6");
sectioncomments.push_back("ChromoPainter population repainting - parameter estimation");
pars.push_back(FsPar("s6emits",6,"Number of EM iterations (chromopainter -i <n>, default: 10)"));
pars.push_back(FsPar("s6minsnps",6,"Minimum number of SNPs for EM estimation (for chromopainter -e, default: 10000)"));
pars.push_back(FsPar("s6snpfrac",6,"fraction of genome to use for EM estimation. (default: 0.1)"));
pars.push_back(FsPar("s6indfrac",6,"fraction of individuals to use for EM estimation. (default: 1.0)"));
pars.push_back(FsPar("s67args",6,"arguments to be passed to Chromopainter (default: empty)"));
pars.push_back(FsPar("s6args",6,"Arguments passed to stage6 (default:-in -iM --emfilesonly)"));
pars.push_back(FsPar("s6outputroot",6,"Filename to use for stage6 EM estimation. (Default: autogenerated)"));
pars.push_back(FsPar("popNeinf",6,"Ne parameter inferred from population-level processing. (Default: autogenerated)"));
pars.push_back(FsPar("popmuinf",6,"mu parameter inferred from population-level processing. (Default: autogenerated)"));
parsize.push_back(pars.size());
sectionnames.push_back("7");
pars.push_back(FsPar("s7combineargs",7,"Additional arguments for stage 7 combine (fs combine; default: none, \"\")"));
pars.push_back(FsPar("s7chunksperregion",7,"number of chunks in a \"region\" (-ve: use default of 100 for linked, nsnps/100 for unlinked)"));
pars.push_back(FsPar("s7samples",7,"number of samples of the painting to obtain per recipient haplotype, for examining the details of the painting. (Populates <root>.samples.out; default 0. Warning: these file can get large)"));
pars.push_back(FsPar("s7args",7,"Arguments passed to stage7 (default: none, \"\")"));
pars.push_back(FsPar("s7outputroot",7,"Filename to use for stage7 EM estimation. (Default: autogenerated)"));
pars.push_back(FsPar("popcval",-1,"Derived. 'c' as inferred using chromopainter. This is only used for sanity checking. See s34 args for setting it manually."));
pars.push_back(FsPar("popcproot",7,"The name of the final population-based chromopainter output. (Default: <filename>_pop, the project file name)"));
pars.push_back(FsPar("popcpgenomelen",7,"The admixture analysis input file, derived name of the chunklengths file from cproot.",1));
sectioncomments.push_back("ChromoPainter population repainting (main run)");
parsize.push_back(pars.size());
sectionnames.push_back("8");
sectioncomments.push_back("Mixture estimation");
parsize.push_back(pars.size());
sectionnames.push_back("9");
sectioncomments.push_back("GLOBETROTTER");
pars.push_back(FsPar("gtroot",9,"The location of the GLOBETROTTER output and content (Default: <root>/gt/gt)"));
pars.push_back(FsPar("gtbootstrapnum",9,"The number of bootstrap samples in GT (Default: 20)"));
pars.push_back(FsPar("gtpropscutoff",9,"GT cutoff for small values (Default: 0.001)"));
pars.push_back(FsPar("gtnummixingiterations",9,"GT number of iterations of maximization (Default: 5)"));
pars.push_back(FsPar("gtbinwidth",9,"The width of the bins (Default: 0.1)"));
pars.push_back(FsPar("gtsampleslist",9,"A file which will contain the list of samples needed by GT (Default: <gtroot>_sampleslist.txt)"));
pars.push_back(FsPar("gtrecomblist",9,"A file which will contain the list of recombination files needed by GT (Default: <gtroot>_recomblist.txt)"));
parsize.push_back(pars.size());
// Vector quantities
sectionnames.push_back("1");
sectioncomments.push_back("Vector quantities placed at the end for readability");
pars.push_back(FsPar("phasefiles",1,"Comma or space separated list of all 'phase' files containing the (phased) SNP details for each haplotype. Required. Must be sorted alphanumerically to ensure chromosomes are correctly ordered. So don't use *.phase, use file{1..22}.phase. Override this with upper case -PHASEFILES."));
pars.push_back(FsPar("recombfiles",1,"Comma or space separated list of all recombination map files containing the recombination distance between SNPs. If provided, a linked analysis is performed. Otherwise an 'unlinked' analysis is performed. Note that linkage is very important for dense markers!"));
pars.push_back(FsPar("nsnpsvec",-1,"Derived. Comma separated list of the number of SNPs in each phase file.",1));
pars.push_back(FsPar("s1outputrootvec",-1,"Derived. Comma separated list of the stage 1 output files names.",1));
parsize.push_back(pars.size());
sectionnames.push_back("2");
sectioncomments.push_back("");
pars.push_back(FsPar("s2outputrootvec",-1,"Derived. Comma separated list of the stage 2 output files names.",1));
parsize.push_back(pars.size());
sectionnames.push_back("3");
sectioncomments.push_back("");
pars.push_back(FsPar("fsmcmcoutputvec",-1,"Derived. Comma separated list of the stage 3 output files names.",1));
pars.push_back(FsPar("old_fsmcmcoutputvec",-1,"Derived. Comma separated list of the stage 3 output files names, if we need to continue a too-short MCMC run.",1));
parsize.push_back(pars.size());
sectionnames.push_back("4");
sectioncomments.push_back("");
pars.push_back(FsPar("fstreeoutputvec",-1,"Derived. Comma separated list of the stage 4 output files names.",1));
parsize.push_back(pars.size());
sectionnames.push_back("5");
sectioncomments.push_back("");
pars.push_back(FsPar("popcmdargs",5,"Derived. Comma separated list of all individual-specific idfiles created in stage5."));
pars.push_back(FsPar("refidfiles",5,"Derived. Comma separated list of all id files generated for use with external samples. (Default: autogenerated)"));
parsize.push_back(pars.size());
sectionnames.push_back("6");
sectioncomments.push_back("");
pars.push_back(FsPar("s6outputrootvec",-1,"Derived. Comma separated list of the stage 6 output files names.",1));
parsize.push_back(pars.size());
sectionnames.push_back("7");
sectioncomments.push_back("");
pars.push_back(FsPar("s7outputrootvec",-1,"Derived. Comma separated list of the stage 7 output files names.",1));
parsize.push_back(pars.size());
sectionnames.push_back("8");
sectioncomments.push_back("");
parsize.push_back(pars.size());
sectionnames.push_back("9");
sectioncomments.push_back("");
parsize.push_back(pars.size());
pars.push_back(FsPar("gtdonors",9,"The names of the donor populations used in the admixture analysis (Fixed by donoridfile)"));
pars.push_back(FsPar("gtrecips",9,"The names of the recipient populations used in the admixture analysis (Fixed by donoridfile)"));
pars.push_back(FsPar("gtsamplesfiles",9,"A vector of the (combined) per-chromosome samples files. (Fixed by data structure)"));
pars.push_back(FsPar("gtparamfiles",9,"A vector of the GT parameter file names. (Fixed by data structure)"));
pars.push_back(FsPar("stage",-1,"Derived. Don't mess with this! The internal measure of which stage of processing we've reached. Change it via -reset or -duplicate.",1));
}
void FsProject::defineCommands()
{
cmds.clear();
cmds.push_back(FsCmd("go",-1,"","Do the next things that are necessary to get a complete set of finestructure runs."));
cmds.push_back(FsCmd("gt",-1,"","Do the preparation of the input files fora GLOBETROTTER analysis."));
cmds.push_back(FsCmd("import",-1,"<file>","Import some settings from an external file. If you need to set any non-trivial settings, this is the way to do it. See \"fs -hh\" for more details."));
///////////////
cmds.push_back(FsCmd("createid",1,"<filename>","Create an ID file from a PROVIDED phase file. Individuals are labelled IND1-IND<N>."));
cmds.push_back(FsCmd("remakes",-1,"<stage>","For hpc mode. Remake the current commandfile, retaining the results of any completed runs."));
cmds.push_back(FsCmd("duplicate",-1,"<stage> <newfile.cp>","Copy the information from the current settings file, and then -reset it to <stage>."));
cmds.push_back(FsCmd("reset",-1,"<stage>","Reset the processing to an earlier point. Further \"-go\" commands will rerun any activity from this point. Helpful for rerunning with different parameters."));
cmds.push_back(FsCmd("configmcmc",3,"<s3itersburnin> <s3iterssample> <numskip>","Shorthand for setting the parameters of the FineSTRUCTURE MCMC. Takes arguments in the form of finestructure's -x -y -z parameters."));
cmds.push_back(FsCmd("ignoreGR",3,"","Reset the MCMC files to a previously completed but unconverged run, allowing processing to proceed as though it were converged."));
cmds.push_back(FsCmd("hpcs3",3,"","Generates a special HPC command for the MCMC, performing the Gelman-Rubin check and rerunning the MCMC until convergence as part of a single HPC command."));
cmds.push_back(FsCmd("cando",-1,"<command>","Checks whether a command can be executed, without executing it."));
///////////////
cmds.push_back(FsCmd("haploid",1,"","Shorthand for the parameter `ploidy:1'"));
cmds.push_back(FsCmd("countdata",1,"","Ends stage0. Performs checks on the data and confirms that we have valid data."));
cmds.push_back(FsCmd("countdatapop",5,"","Starts stage5. Performs checks on the -popidfile."));
for(int i=1;i<=9;i++) {
stringstream sscmd,sscomment;
sscmd<<"makes"<<i;
sscomment<<"Make the stage"<<i<<" commands.";
cmds.push_back(FsCmd(sscmd.str(),i,"",sscomment.str()));
}
for(int i=1;i<=8;i++) {
stringstream sscmd,sscomment;
sscmd<<"dos"<<i;
sscomment<<"Do the stage"<<i<<" commands. This we should only be doing in single machine mode; we use -writes1 in HPC mode.";
cmds.push_back(FsCmd(sscmd.str(),i,"",sscomment.str()));
}
for(int i=1;i<=9;i++) {
stringstream sscmd,sscomment;
sscmd<<"writes"<<i;
sscomment<<"Write the stage"<<i<<" commands to file, which we only need in HPC mode.";
if(i<9) sscomment<<" In single machine mode we can instead use -dos"<<i<<".";
cmds.push_back(FsCmd(sscmd.str(),i,"",sscomment.str()));
}
cmds.push_back(FsCmd("combines1",1,"","Ends stage1 by combining the output of the stage1 commands. This means estimating the parameters mu and Ne from the output of stage1."));
cmds.push_back(FsCmd("combines2",2,"","Ends stage2 by combining the output of the stage2 commands. This means estimating 'c' and creating the genome-wide chromopainter output for all individuals."));
cmds.push_back(FsCmd("combines3",3,"","Ends stage3 by checking the output of the stage3 commands. This means checking that the MCMC has converged."));
cmds.push_back(FsCmd("combines4",4,"","Ends stage4 by checking the output of the stage4 commands. This means constructing a tree of the best observed state, to form a clustering."));
cmds.push_back(FsCmd("combines5",5,"","Ends stage5 by making the population IDs from the donor file."));
cmds.push_back(FsCmd("combines6",6,"","Ends stage6 by combining the output of the stage6 commands. This means estimating the parameters mu and Ne for the population painting from the output of stage6."));
cmds.push_back(FsCmd("combines7",7,"","Ends stage7 by combining the output of the stage7 commands. This means estimating 'c' and creating the genome-wide chromopainter output for the population painting."));
cmds.push_back(FsCmd("combines8",8,"",""));
cmds.push_back(FsCmd("validates",-1,"<stage>","Validate the output files of the stage specified."));
/* for(int i=1;i<=9;i++) {
stringstream sscmd,sscomment;
sscmd<<"validates"<<i;
sscomment<<"Validate the output files of the stage specified.";
cmds.push_back(FsCmd(sscmd.str(),i,"",sscomment.str()));
} */
///
cmds.push_back(FsCmd("paintercmd",-1,"<cmd>","Set the chromopainter version to an external command, which should be ChromoPainterv2. This enables -hpc 1 mode and makes other changes to the processing."));
//cpname
//fsmcmcname
}
///////////////////////////////
void FsProject::addHistory(std::vector<std::string> args)
{
std::ostringstream hist;
hist<<"CMDLINE: ";
for(unsigned int c1=0;c1<args.size();++c1){
hist<<args[c1]<<" ";
}
hist<<endl;
historytext.append(hist.str());
}
void FsProject::switchStdout(const char *newStream)
{
fflush(stdout);
fgetpos(stdout, &stdout_pos);
stdout_fd = dup(fileno(stdout));
FILE * ftest = freopen(newStream, "w", stdout);
if(ftest==NULL) throw(runtime_error("Could not switch log file!"));
}
void FsProject::revertStdout()
{
fflush(stdout);
dup2(stdout_fd, fileno(stdout));
close(stdout_fd);
clearerr(stdout);
fsetpos(stdout, &stdout_pos);
}
bool FsProject::finishedStage(int teststage)
{
if(stage>teststage) return(true);
return(false);
}
int FsProject::getHpc(){
return(hpc);
}
void FsProject::do_omp_set_num_threads(int numthreads){
#ifdef _OPENMP
omp_set_num_threads(numthreads);
#endif
}
int FsProject::get_omp_get_thread_num(){
#ifdef _OPENMP
return(omp_get_thread_num());
#else
return(0);
#endif
}
int FsProject::get_omp_get_num_threads(){
#ifdef _OPENMP
return(omp_get_num_threads());
#else
return(1);
#endif
}
int FsProject::getIndsPerProc(int forstage){
if(forstage==7) return(1);
if(indsperproc>0) return(indsperproc);
if(hpc) return(1);
int numshere=numRecipients(stage);
if(numthreads>0) {
indsperproc=ceil(((double) numshere)/numthreads);
return(indsperproc);
}
int tnumthreads = 1,th_id;
#pragma omp parallel private(th_id)
{
th_id = get_omp_get_thread_num();
if ( th_id == 0 ) {
tnumthreads = get_omp_get_num_threads();
}
}
indsperproc=ceil(((double) numshere)/tnumthreads);
return(indsperproc);
}
int FsProject::defaultChunksperregion(){
if(linkagemode.compare("linked")==0) return(100);
else if(linkagemode.compare("unlinked")==0) {
if(nsnps<0) throw(logic_error("s2chunksperregion"));
return(max(10,(int)(nsnps/100)));
}else{
throw(logic_error("s2chunksperregion"));
}
}
string FsProject::getCommandFile(int forstage){
if(forstage<0) forstage=stage;
switch(forstage){
case 1: return(s1commandfile);
case 2: return(s2commandfile);
case 3: return(s3commandfile);
case 4: return(s4commandfile);
// case 5: return(s5commandfile);
case 6: return(s6commandfile);
case 7: return(s7commandfile);
// case 8: return(s8commandfile);
case 9: return(s9commandfile);
}
return(string(""));
}
int FsProject::getCommandFileCount(int forstage){
if(forstage<0) forstage=stage;
switch(forstage){
case 1: return(s1commands.size());
case 2: return(s2commands.size());
case 3: return(s3commands.size());
case 4: return(s4commands.size());
case 6: return(s6commands.size());
case 7: return(s7commands.size());
case 9: return(s9commands.size());
}
return(-1);
}
string FsProject::whichLinkagemode()
{
if(recombfiles.size()>0) return("linked");
return("unlinked");
}
//////////////////////////////////
bool FsProject::applyVal(std::vector<std::string> args)
{
/*for(unsigned int c1=0;c1<args.size();c1++){
cout<<"DEBUG2 :\""<<args[c1]<<"\""<<endl;
}*/
FsSettingsValue val(args);
//cout<<"DEBUG2 :\""<<val.getName()<<"\" \""<<val.getVal()<<"\""<<endl;
if(val.success) return(applyVal(val));
else{
cerr<<"ERROR: Tried to set a parameter, but this failed. Is this a malformed command line?"<<endl;
cerr<<"HELP for "<<cmdInfo(args[0],true)<<endl;
throw(runtime_error("Invalid parameter setting"));
}
return(false);
}
bool FsProject::applyVal(FsSettingsValue val)
{
string name=val.getName();
// cout<<"DEBUG :\""<<name<<"\" \""<<val.getVal()<<"\" stage "<<stage<<endl;
bool found=false;
//////////// COMMENT
if(name.compare("CMD")==0){
historytext.append(val.getEndedLine()); found=true;
}else if(name.compare("CMDLINE")==0){
historytext.append(val.getEndedLine()); found=true;
}else if(name.compare("stage")==0){
stage=val.getValAsInt();found=true;
}
if(found){
if(verbose) cout<<"Successfully read "<<val.getName()<<":\""<<val.getVal()<<"\""<<endl;
return(found);
}
//////////// STAGE1
if(name.compare("exec")==0){
exec=val.getVal(); found=true;
}else if(name.compare("fsfile")==0){
fsfile=val.getVal(); found=true;
}else if(name.compare("allowdep")==0){
allowdep=val.getValAsInt(); found=true;
}else if(name.compare("hpc")==0){
hpc=val.getValAsInt(); found=true;
}else if (name.compare("ploidy")==0){
ploidy=val.getValAsInt(); found=true;
}else if (name.compare("paintercmd")==0){
paintercmd=val.getVal(); found=true;
}else if (name.compare("linkagemode")==0){
linkagemode=val.getVal(); found=true;
}else if (name.compare("indsperproc")==0) {
indsperproc=val.getValAsInt(); found=true;
}else if (name.compare("outputlogfiles")==0) {
outputlogfiles=val.getValAsInt(); found=true;
}else if (name.compare("allowdep")==0) {
allowdep=val.getValAsInt(); found=true;
}else if (name.compare("validatedoutput")==0) {
validatedoutput=val.getValAsIntVec(); found=true;
}else if (name.compare("missingfiles")==0) {
missingfiles=val.getValAsIntVec(); found=true;
}
// STAGE1-2 generics
if(name.compare("s12inputtype")==0){
s12inputtype=val.getVal(); found=true;
}else if ((name.compare("phasefiles")==0)||(name.compare("PHASEFILES")==0)) {
vector<string> oldphase=phasefiles;
// if(oldphase.size()>0) {cout<<"WARNING: You have specified -phasefiles already, and have added some more. This is often accidental. Check}
phasefiles=val.getValAsStringVec(); found=true;
s12inputtype=string("phase");
vector<string> tphasefiles=phasefiles;
sort(tphasefiles.begin(),tphasefiles.end());
if(unique(tphasefiles).size()!=tphasefiles.size()){// duplicates
cerr<<"ERROR: duplicated phase files provided! You only need to specify each phase file once, and you should not use -phasefiles in future commands."<<endl;
phasefiles=oldphase;
throw(runtime_error("duplicate phase files"));
}
if(name.compare("PHASEFILES")==0){
name=string("phasefiles");
}else if(stage==0 && !isNumericallySorted(phasefiles)) {
cerr<<"ERROR: Phase files are not lexicographically sorted, so you probably will get confusing assignments of chromosomes to file indices. Rerun with -PHASEFILES instead of -phasefiles to override this check, or rerun with sorted files (e.g. in bash: -phasefiles file{1..22}.phase)."<<endl;
phasefiles=oldphase;
throw(runtime_error("unsorted phase files"));
}
}else if (name.compare("recombfiles")==0) {
vector<string> oldrec=recombfiles;
recombfiles=val.getValAsStringVec(); found=true;
if(recombfiles.size()>0) linkagemode="linked";
if(unique(recombfiles).size()!=recombfiles.size()){// duplicates
recombfiles=oldrec;
cerr<<"ERROR: duplicated recomb files provided! You only need to specify each recombination file once, and you should not use --recombfiles in future commands."<<endl;
throw(runtime_error("duplicate recombination files"));
}
}else if (name.compare("idfile")==0) {
idfile=val.getVal(); found=true;
}else if (name.compare("s12args")==0) {
s12args=val.getVal(); found=true;
}else if (name.compare("ninds")==0) {
ninds=val.getValAsInt(); found=true;
}else if (name.compare("nindsUsed")==0) {
nindsUsed=val.getValAsInt(); found=true;
}else if (name.compare("nrecipsDonor")==0) {
nrecipsDonor=val.getValAsInt(); found=true;
}else if (name.compare("nsnps")==0) {
nsnps=val.getValAsInt(); found=true;
}else if (name.compare("nsnpsvec")==0) {
nsnpsvec=val.getValAsIntVec(); found=true;
}else if (name.compare("numthreads")==0) {
numthreads=val.getValAsInt(); found=true;
}
// STAGE1 properties
if (name.compare("s1args")==0) {
s1args=val.getVal(); found=true;
}else if (name.compare("s1emits")==0) {
s1emits=val.getValAsInt(); found=true;
}else if (name.compare("s1outputroot")==0) {
s1outputroot=val.getVal(); found=true;
}else if (name.compare("s1outputrootvec")==0) {
s1outputrootvec=val.getValAsStringVec(); found=true;
}else if (name.compare("s1minsnps")==0) {
s1minsnps=val.getValAsInt(); found=true;
}else if (name.compare("s1snpfrac")==0) {
s1snpfrac=val.getValAsDouble(); found=true;
}else if (name.compare("s1indfrac")==0) {
s1indfrac=val.getValAsDouble(); found=true;
}
//////////// STAGE1 POST
if (name.compare("Neinf")==0) {
Neinf=val.getValAsDouble(); found=true;
}else if (name.compare("muinf")==0) {
muinf=val.getValAsDouble(); found=true;
}
if(found){
return(checkStage(name,val.getVal()));
}
//////////// STAGE2 PRE
if (name.compare("s2chunksperregion")==0) {
s2chunksperregion=val.getValAsInt(); found=true;
}else if (name.compare("s2samples")==0) {
s2samples=val.getValAsInt(); found=true;
}else if (name.compare("s2args")==0) {
s2args=val.getVal(); found=true;
}else if (name.compare("s2outputroot")==0) {
s2outputroot=val.getVal(); found=true;
}else if (name.compare("s2outputrootvec")==0) {
s2outputrootvec=val.getValAsStringVec(); found=true;
}else if (name.compare("s2combineargs")==0) {
s2combineargs=val.getVal(); found=true;
}
if(found){
return(checkStage(name,val.getVal()));
}
////////////// STAGE 3
//stage3-4 generics
if (name.compare("cval")==0) {
cval=val.getValAsDouble(); found=true;
}else if (name.compare("cproot")==0) {
cproot=val.getVal(); found=true;
/* if(cpchunkcounts.compare("")==0) {
cpchunkcounts=cproot;
cpchunkcounts.append(".chunkcounts.out");
}*/
}else if (name.compare("cpchunkcounts")==0) {
cpchunkcounts=val.getVal(); found=true;
}
//stage 3 parameters
if (name.compare("s34args")==0) {
s34args=val.getVal(); found=true;
}else if (name.compare("fsroot")==0) {
fsroot=val.getVal(); found=true;
}
if (name.compare("s3iters")==0) {
s3iters=val.getValAsInt(); found=true;
}else if (name.compare("s3iterssample")==0) {
s3iterssample=val.getValAsInt(); found=true;
}else if (name.compare("s3itersburnin")==0) {
s3itersburnin=val.getValAsInt(); found=true;
}else if (name.compare("numskip")==0) {
numskip=val.getValAsInt(); found=true;
}else if (name.compare("maxretained")==0) {
maxretained=val.getValAsInt(); found=true;
}else if (name.compare("nummcmcruns")==0) {
nummcmcruns=val.getValAsInt(); found=true;
}else if (name.compare("fsmcmcoutput")==0) {
fsmcmcoutput=val.getVal(); found=true;
}else if (name.compare("fsmcmcoutputvec")==0) {
fsmcmcoutputvec=val.getValAsStringVec(); found=true;
}else if (name.compare("old_fsmcmcoutputvec")==0) {
old_fsmcmcoutputvec=val.getValAsStringVec(); found=true;
}else if (name.compare("mcmcGR")==0) {
mcmcGR=val.getValAsDoubleVec(); found=true;
}else if (name.compare("threshGR")==0) {
threshGR=val.getValAsDouble(); found=true;
}
if(found){
return(checkStage(name,val.getVal()));
}
///////////////// STAGE 4
if (name.compare("s4iters")==0) {
s4iters=val.getValAsInt(); found=true;
}else if (name.compare("s4args")==0) {
s4args=val.getVal(); found=true;
}else if (name.compare("fstreeoutput")==0) {
fstreeoutput=val.getVal(); found=true;
}else if (name.compare("fstreeoutputvec")==0) {
fstreeoutputvec=val.getValAsStringVec(); found=true;
}
if(found){
return(checkStage(name,val.getVal()));
}
///////////////// STAGE 4combine
if (name.compare("s4iters")==0) {
s4iters=val.getValAsInt(); found=true;
}else if (name.compare("fstreeoutput")==0) {
fstreeoutput=val.getVal(); found=true;
}else if (name.compare("fstreeoutputvec")==0) {
fstreeoutputvec=val.getValAsStringVec(); found=true;
}
if(found){
return(checkStage(name,val.getVal()));
}
///////////////// STAGE 5
if (name.compare("popidfile")==0) {
popidfile=val.getVal(); found=true;
}else if (name.compare("donoridfile")==0) {
donoridfile=val.getVal(); found=true;
}else if (name.compare("popcmdargs")==0) {
popcmdargs=val.getValAsStringVec(','); found=true;
}else if (name.compare("refdonorfile")==0) {
refdonorfile=val.getVal(); found=true;
}else if (name.compare("refidfiles")==0) {
refidfiles=val.getValAsStringVec(','); found=true;
}
if(found){
return(checkStage(name,val.getVal()));
}
///////////////// STAGE 6
if (name.compare("s6args")==0) {
s6args=val.getVal(); found=true;
}else if (name.compare("s67args")==0) {
s67args=val.getVal(); found=true;
}else if (name.compare("s6emits")==0) {
s6emits=val.getValAsInt(); found=true;
}else if (name.compare("s6outputroot")==0) {
s6outputroot=val.getVal(); found=true;
}else if (name.compare("popNeinf")==0) {
popNeinf=val.getValAsDouble(); found=true;
}else if (name.compare("popmuinf")==0) {
popmuinf=val.getValAsDouble(); found=true;
}else if (name.compare("s6outputrootvec")==0) {
s6outputrootvec=val.getValAsStringVec(); found=true;
}else if (name.compare("s6minsnps")==0) {
s6minsnps=val.getValAsInt(); found=true;
}else if (name.compare("s6snpfrac")==0) {
s6snpfrac=val.getValAsDouble(); found=true;
}else if (name.compare("s6indfrac")==0) {
s6indfrac=val.getValAsDouble(); found=true;
}
if(found){
return(checkStage(name,val.getVal()));
}
///////////////// STAGE 7
if (name.compare("s7chunksperregion")==0) {
s7chunksperregion=val.getValAsInt(); found=true;
}else if (name.compare("s7samples")==0) {
s7samples=val.getValAsInt(); found=true;
}else if (name.compare("s7args")==0) {
s7args=val.getVal(); found=true;
}else if (name.compare("popcval")==0) {
popcval=val.getValAsDouble(); found=true;
}else if (name.compare("popcproot")==0) {
popcproot=val.getVal(); found=true;
}else if (name.compare("popcpgenomelen")==0) {
popcpgenomelen=val.getVal(); found=true;
}else if (name.compare("s7outputroot")==0) {
s7outputroot=val.getVal(); found=true;
}else if (name.compare("s7outputrootvec")==0) {
s7outputrootvec=val.getValAsStringVec(); found=true;
}else if (name.compare("s7combineargs")==0) {
s7combineargs=val.getVal(); found=true;
}
///////////////// STAGE 9 (GT)
if (name.compare("gtroot")==0) {
gtroot=val.getVal(); found=true;
}else if(name.compare("gtsampleslist")==0) {
gtsampleslist=val.getVal(); found=true;
}else if(name.compare("gtbootstrapnum")==0) {
gtbootstrapnum=val.getVal(); found=true;
}else if(name.compare("gtpropscutoff")==0) {
gtpropscutoff=val.getVal(); found=true;
}else if(name.compare("gtbinwidth")==0) {
gtbinwidth=val.getVal(); found=true;
}else if(name.compare("gtnummixingiterations")==0) {
gtnummixingiterations=val.getVal(); found=true;
}
if(found){
return(checkStage(name,val.getVal()));
}
cerr<<"WARNING: Setting "<<val.getName()<<" not found!"<<endl;
return(found);
}
void FsProject::resetToStage(int newstage)
{
if(newstage>stage){
cerr<<"Attempted to reset to stage "<<newstage<<" but we are only in stage "<<stage<<". Can only reset to the current or past stages!"<<endl;
throw(runtime_error("reset stage error"));
}
for(int i=newstage;i<nstages;i++) {
validatedoutput[i]=0;
missingfiles[i]=-1;
}
if(newstage<=0){ //reset the stage0 stuff
if(verbose) cout<<"Removing phase/recomb input information..."<<endl;
phasefiles.clear();
recombfiles.clear();
nsnpsvec.clear();
nsnps=0;
ninds=0;
nindsUsed=0;
deleteStage("0");
}
if(newstage<=1){ //reset the stage1 stuff
if(verbose) cout<<"Removing EM results..."<<endl;
s1commands.clear();
s1logfiles.clear();
s1outputrootvec.clear();
s1outputroot="";
Neinf=-1;
muinf=-1;
safeRemoveCommandFile(1);
deleteStage("1");
}
if(newstage<=2){
if(verbose) cout<<"Removing chromopainter main run results..."<<endl;
s2commands.clear();
s2logfiles.clear();
s2outputrootvec.clear();
s2outputroot="";
s2combineargs="";
cval=-1;
cproot="";
cpchunkcounts="";
safeRemoveCommandFile(2);
deleteStage("2");
deleteStage("2a");
}
if(newstage<=3){
if(verbose) cout<<"Removing finestructure mcmc run results..."<<endl;
s3commands.clear();
s3logfiles.clear();
fsroot="";
fsmcmcoutput="";
fsmcmcoutputvec.clear();
old_fsmcmcoutputvec.clear();
mcmcGR.clear();
safeRemoveCommandFile(3);
deleteStage("3");
}
if(newstage<=4){
if(verbose) cout<<"Removing finestructure tree run results..."<<endl;
s4commands.clear();
s4logfiles.clear();
fsroot="";
s4args="";
fstreeoutput="";
fstreeoutputvec.clear();
safeRemoveCommandFile(4);
deleteStage("4");
}
if(newstage<=5){
if(verbose) cout<<"Removing admixture panel construction results..."<<endl;
popidfile="";
donoridfile="";
refdonorfile="";
refidfiles.clear();
popcmdargs.clear();
nrecipsDonor=0;
deleteStage("5");
}
if(newstage<=6){
if(verbose) cout<<"Removing admixture EM results..."<<endl;
s6commands.clear();
s6logfiles.clear();
s6outputrootvec.clear();
s6outputroot="";
popNeinf=-1;
popmuinf=-1;
safeRemoveCommandFile(6);
deleteStage("6");
}
if(newstage<=7){
if(verbose) cout<<"Removing chromopainter admixture run results..."<<endl;
s7combineargs="";
s7commands.clear();
s7logfiles.clear();
s7outputrootvec.clear();
s7outputroot="";
popcval=-1;
popcproot="";
popcpgenomelen="";
safeRemoveCommandFile(7);
deleteStage("7");
deleteStage("7a");
}
if(newstage<=9){
if(verbose) cout<<"Removing globetrotter run results..."<<endl;
gtroot="";
gtsampleslist="";
gtrecomblist="";
gtrecips.clear();
gtdonors.clear();
gtsamplesfiles.clear();
gtparamfiles.clear();
safeRemoveCommandFile(9);
// deleteStage("gt");
}
stage=newstage;
}
void FsProject::createDuplicated(int newstage,string newname)
{
dirname=projectroot(newname);
newname=projectfull(dirname);
setFileName(newname);
dirname=projectroot(newname);
if((newstage>2) & (newstage<5)){ // keeping the chromopainter results, redoing fs
ensureCpRunARoot(2);
}else{
if(applyFiles("new",string("stop"))!=0) {
throw(runtime_error("duplicate error"));
}