modified: splanegrid.py
[GalaxyCodeBases.git] / BGI / SOAPsnp / Files.cpp
blobb29a25605db2ac90d959896881acb118bfc8c46c
1 /*
2 ******************************************************************************
3 *Copyright 2010
4 * BGI-SHENZHEN
5 *All Rights Reserved
6 *ATHUOR : Bill Tang
7 *CREATE DATE : 2010-9-15
8 *UPDATE DATE : 2010-9-15
9 *UPDATE BY : Zhou Guyue
10 *******************************************************************************
15 #include "soap_snp.h"
16 #include <cassert>
18 /**
19 * DATE: 2010-9-15
20 * FUNCTION: open sfs file
21 * PARAMETER: outfiles : outfile name.
22 writeFr : whether writer frequence file.
23 doBay : whether do Bay.
24 doJoint : whether do Joint
25 * RETURN: OPENSFS_ERROR:if can not open file ,OPENSFS_SUCC : if can open file.
27 int Files::OpenSfsfile(const string outfiles, const int writeFr, const int doBay, const int doJoint)
29 //generete the output filenames
30 if(!outfiles.c_str())
32 printf("Must supply -outfiles (-fai)\n");
33 return OPENSFS_ERROR;
36 fSFSall = outfiles + ".sfs";
37 fFreq = outfiles + ".frq";
38 fJoint = outfiles + ".bjoint";
40 //open the persite FILE streams
41 if(writeFr)
43 //freqfile.clear();
44 //freqfile.open(fFreq.c_str());
45 freqfile= getFILE(fFreq.c_str(),"w");
47 if(doBay)
49 //sfsfile.clear();
50 //sfsfile.open(fSFSall.c_str());
51 sfsfile = getFILE(fSFSall.c_str(),"w");
52 //sfsfile-open(fSFSall.c_str());
54 if(doJoint)
56 //jointSfsfile.clear();
57 //jointSfsfile.open(fJoint.c_str(), ios::binary);
58 jointSfsfile = getFILE(fJoint.c_str(),"w");
60 if ((writeFr && !freqfile) || (doBay && !sfsfile) || (doJoint && !jointSfsfile))
62 cerr << "\topen sfs file failed!" << endl;
63 return OPENSFS_ERROR;
65 return OPENSFS_SUCC;
69 /**
70 * DATE: 2010-9-15
71 * FUNCTION: get file in mode
72 * PARAMETER: fname : file name , mode : write.
73 * RETURN: FILE .
75 FILE* Files::getFILE(const char*fname,const char* mode)
77 FILE *fp;
78 if(NULL == (fp = fopen(fname, mode)))
80 fprintf(stderr,"\t->Error opening FILE handle for file:%s exiting\n",fname);
81 exit(0);
83 return fp;