Ejemplo n.º 1
0
/*}}}*/
int main(int argc, char** argv)/*{{{*/
{

    if (argc < 2)
    {
        PrintHelp();
        return -1;
    }
    int i = 0;
    int j = 0;
    char outpath[MAX_PATH+1] = "./";
    char listfile[MAX_PATH+1] = "";
    char outAlphabet[NUM_BLOSUM+1] = ""; //if outAlphabet not set, using the default BLOSUM alphabet
    double scale = 100.0;
    //char **filenamelist = NULL;
    bool isOutputLast2Col = false;
    bool isQuietMode = false;

    set <string> filenamelist_set;
    set <string> ::iterator iss;

    int numfile = 0;
    
    int errmsg = 0;
    
    i = 1;
    while(i < argc)/*{{{*/
    {
        if(strcmp(argv[i], "-h") == 0|| strcmp(argv[i], "--help") == 0)
        {
            PrintHelp();
            errmsg = 1;
            break;
        }
        else if (strcmp(argv[i], "-d") == 0)
        {
            my_strcpy(outpath,argv[i+1], MAX_PATH);
            i += 2;
        }
        else if (strcmp(argv[i], "-s") == 0)
        {
            scale = atof(argv[i+1]);
            i += 2;
        }
        else if (strcmp(argv[i], "-i") == 0)
        {
            isOutputInteger = true;
            i ++;
        }
        else if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--list") == 0)
        {
            my_strcpy(listfile,argv[i+1], MAX_PATH);
            i += 2;
        }
        else if (strcmp(argv[i], "--alphabet") == 0 || strcmp(argv[i], "-a") == 0)
        {
            my_strcpy(outAlphabet,argv[i+1], NUM_BLOSUM);
            if(!IsValidAlphabet(outAlphabet))
            {
                errmsg  = -1;
                break;
            }
            i += 2;
        }
        else if (strcmp(argv[i], "-q") == 0)
        {
            isQuietMode = true;
            i ++;
        }
        else if (strcmp(argv[i], "--pssm") == 0)
        {
            isOutputLast2Col = true;
            i ++;
        }
        else
        {
            filenamelist_set.insert(argv[i]);
            i ++;
        }
    }/*}}}*/
    numfile = filenamelist_set.size();

    if(errmsg != 0)
    {
        return errmsg;
    }
    if(strcmp(listfile,"") == 0 && filenamelist_set.size() == 0)
    {
        fprintf(stderr,"Error! neither listfile nor mtx file in the argument list are set\n");
        return -1;
    }
    else if(strcmp(listfile,"") != 0)
    {
        FILE *fpin;
        fpin = fopen(listfile,"r");
        checkfilestream(fpin,listfile,"r");
        int linesize;
        int maxline = 300;
        Array1D <char> line_1darray(maxline+1);
        char *line = line_1darray.array1D;
        while((linesize = fgetline(fpin, line , maxline)) != EOF)
        {
            if(linesize > 0) filenamelist_set.insert(line);
        }
        fclose(fpin);
    }
        
    VerifyFolder(outpath);

    Array1D <char> aaSeq_1darray(LONGEST_SEQ+1);
    Array2D <double> profile_2darray(LONGEST_SEQ, NUM_BLOSUM);
    Array1D <double> parameter_1darray(NUM_PARAMETER);
    char *aaSeq = aaSeq_1darray.array1D;
    double **profile = profile_2darray.array2D;
    double *parameter = parameter_1darray.array1D;
    double *score1 = NULL;
    double *score2 = NULL;
    char modmfile[MAX_PATH+1] = "";
    char pssmfile[MAX_PATH+1] = "";
    char mtxfile[MAX_PATH+1] = "";
    char rtname[MAX_PATH+1] = "";
    char filepath[MAX_PATH+1] = "";
    int length;
    int lengthpssm;

    int cntfile = 0;
    for(iss = filenamelist_set.begin() ; iss !=  filenamelist_set.end(); iss ++)
    {
        score1 = NULL;
        score2 = NULL;

        my_strcpy(mtxfile, (*iss).c_str(), MAX_PATH);
        rootname(mtxfile, rtname);
        getfilepath(mtxfile, filepath);
        if(getmtx(mtxfile, length, aaSeq, parameter, profile, scale) <= 0)
        {
            fprintf(stderr, "%d \t %s getting mtx file error!",cntfile+1, mtxfile);
            continue;
        }
        lengthpssm = length ;

        int profileIndex[NUM_BLOSUM]; //order the profile according to the outAlphabet
        for(j = 0; j < NUM_BLOSUM; j ++) profileIndex[j] = j;
        if(strcmp(outAlphabet,"") != 0)
        {
            for(i = 0 ; i < NUM_AA; i++)
            {
                profileIndex[i] = Char2Digit(outAlphabet[i],  BLOSUM1D_alphabet);
            } 
        }
        else
        {
            my_strcpy(outAlphabet, BLOSUM1D_alphabet, NUM_BLOSUM);
        }


        if(isOutputLast2Col)
        {
            score1 = new double [LONGEST_SEQ];
            score2 = new double [LONGEST_SEQ];
            sprintf(pssmfile, "%s/%s.pssm", filepath, rtname);
            lengthpssm = GetPSSM(pssmfile, lengthpssm, NULL, NULL, NULL, score1, score2);
        }
        if ( length != lengthpssm)
        {
            fprintf(stderr,"Error! length of mtx file and pssm not the same for %s", rtname);
        }
        else
        {
            sprintf(modmfile, "%s/%s.modm", outpath, rtname);
            WriteMODMFile(modmfile, aaSeq, length, profile, profileIndex, outAlphabet, score1, score2, parameter, isOutputInteger);
            if(!isQuietMode) fprintf(stdout,"%d  %s output\n", cntfile+1, modmfile);
        }
        if (score1 != NULL) delete [] score1;
        if (score2 != NULL) delete [] score2;
    }
    //
    return 0;
}
Ejemplo n.º 2
0
void FillTreeClass<T>::setTreeInternal2(T& _safelocker, Items& _items, ThreadedItems& _topLevelItems, const ::profiler::timestamp_t& _beginTime, const ::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, bool _colorizeRows)
{
    //size_t blocksNumber = 0;
    //for (const auto& block : _blocks)
    //    blocksNumber += calculateTotalChildrenNumber(*block.tree);
    //    //blocksNumber += block.tree->total_children_number;
    //m_items.reserve(blocksNumber + _blocks.size()); // blocksNumber does not include root blocks

    RootsMap threadsMap;

    const auto u_thread = ::profiler_gui::toUnicode("thread");
    int i = 0, total = static_cast<int>(_blocks.size());
    //const QSignalBlocker b(this);
    for (const auto& block : _blocks)
    {
        if (_safelocker.interrupted())
            break;

        auto& gui_block = easyBlock(block.tree);
        const auto startTime = gui_block.tree.node->begin();
        const auto endTime = gui_block.tree.node->end();
        if (startTime > _right || endTime < _left)
        {
            _safelocker.setProgress((90 * ++i) / total);
            continue;
        }

        ::profiler::timestamp_t duration = 0;
        EasyTreeWidgetItem* thread_item = nullptr;
        auto thread_item_it = threadsMap.find(block.root->thread_id);
        if (thread_item_it != threadsMap.end())
        {
            thread_item = thread_item_it->second;
        }
        else
        {
            thread_item = new EasyTreeWidgetItem();

            QString threadName;
            if (block.root->got_name())
            {
                QString rootname(::profiler_gui::toUnicode(block.root->name()));
                if (rootname.contains(u_thread, Qt::CaseInsensitive))
                    threadName = ::std::move(QString("%1 %2").arg(rootname).arg(block.root->thread_id));
                else
                    threadName = ::std::move(QString("%1 Thread %2").arg(rootname).arg(block.root->thread_id));
            }
            else
            {
                threadName = ::std::move(QString("Thread %1").arg(block.root->thread_id));
            }

            thread_item->setText(COL_NAME, threadName);

            if (!block.root->children.empty())
                duration = blocksTree(block.root->children.back()).node->end() - blocksTree(block.root->children.front()).node->begin();

            thread_item->setTimeSmart(COL_DURATION, duration);
            thread_item->setBackgroundColor(::profiler_gui::SELECTED_THREAD_BACKGROUND);
            thread_item->setTextColor(::profiler_gui::SELECTED_THREAD_FOREGROUND);

            // Sum of all children durations:
            thread_item->setTimeSmart(COL_SELF_DURATION, block.root->active_time);

            threadsMap.insert(::std::make_pair(block.root->thread_id, thread_item));
        }

        auto item = new EasyTreeWidgetItem(block.tree, thread_item);
        duration = endTime - startTime;

        auto name = *gui_block.tree.node->name() != 0 ? gui_block.tree.node->name() : easyDescriptor(gui_block.tree.node->id()).name();
        item->setText(COL_NAME, ::profiler_gui::toUnicode(name));
        item->setTimeSmart(COL_DURATION, duration);
        item->setTimeMs(COL_BEGIN, startTime - _beginTime);
        item->setTimeMs(COL_END, endTime - _beginTime);

        item->setData(COL_PERCENT_PER_FRAME, Qt::UserRole, 0);

        auto percentage_per_thread = ::profiler_gui::percent(duration, block.root->active_time);
        item->setData(COL_PERCENT_PER_PARENT, Qt::UserRole, percentage_per_thread);
        item->setText(COL_PERCENT_PER_PARENT, QString::number(percentage_per_thread));

        if (gui_block.tree.per_thread_stats != nullptr) // if there is per_thread_stats then there are other stats also
        {
            const auto& per_thread_stats = gui_block.tree.per_thread_stats;
            const auto& per_parent_stats = gui_block.tree.per_parent_stats;
            const auto& per_frame_stats = gui_block.tree.per_frame_stats;


            if (per_thread_stats->calls_number > 1 || !EASY_GLOBALS.display_only_relevant_stats)
            {
                item->setTimeSmart(COL_MIN_PER_THREAD, per_thread_stats->min_duration, "min ");
                item->setTimeSmart(COL_MAX_PER_THREAD, per_thread_stats->max_duration, "max ");
                item->setTimeSmart(COL_AVERAGE_PER_THREAD, per_thread_stats->average_duration());
                item->setTimeSmart(COL_DURATION_SUM_PER_THREAD, per_thread_stats->total_duration);
            }

            item->setData(COL_NCALLS_PER_THREAD, Qt::UserRole, per_thread_stats->calls_number);
            item->setText(COL_NCALLS_PER_THREAD, QString::number(per_thread_stats->calls_number));

            percentage_per_thread = ::profiler_gui::percent(per_thread_stats->total_duration, block.root->active_time);
            item->setData(COL_PERCENT_SUM_PER_THREAD, Qt::UserRole, percentage_per_thread);
            item->setText(COL_PERCENT_SUM_PER_THREAD, QString::number(percentage_per_thread));


            if (per_parent_stats->calls_number > 1 || !EASY_GLOBALS.display_only_relevant_stats)
            {
                item->setTimeSmart(COL_MIN_PER_PARENT, per_parent_stats->min_duration, "min ");
                item->setTimeSmart(COL_MAX_PER_PARENT, per_parent_stats->max_duration, "max ");
                item->setTimeSmart(COL_AVERAGE_PER_PARENT, per_parent_stats->average_duration());
                item->setTimeSmart(COL_DURATION_SUM_PER_PARENT, per_parent_stats->total_duration);
            }

            item->setData(COL_NCALLS_PER_PARENT, Qt::UserRole, per_parent_stats->calls_number);
            item->setText(COL_NCALLS_PER_PARENT, QString::number(per_parent_stats->calls_number));


            if (per_frame_stats->calls_number > 1 || !EASY_GLOBALS.display_only_relevant_stats)
            {
                item->setTimeSmart(COL_MIN_PER_FRAME, per_frame_stats->min_duration, "min ");
                item->setTimeSmart(COL_MAX_PER_FRAME, per_frame_stats->max_duration, "max ");
                item->setTimeSmart(COL_AVERAGE_PER_FRAME, per_frame_stats->average_duration());
                item->setTimeSmart(COL_DURATION_SUM_PER_FRAME, per_frame_stats->total_duration);
            }

            item->setData(COL_NCALLS_PER_FRAME, Qt::UserRole, per_frame_stats->calls_number);
            item->setText(COL_NCALLS_PER_FRAME, QString::number(per_frame_stats->calls_number));
        }
        else
        {
            item->setData(COL_PERCENT_SUM_PER_THREAD, Qt::UserRole, 0);
            item->setText(COL_PERCENT_SUM_PER_THREAD, "");
        }

        const auto color = easyDescriptor(gui_block.tree.node->id()).color();
        //const auto bgColor = ::profiler_gui::fromProfilerRgb(::profiler::colors::get_red(color), ::profiler::colors::get_green(color), ::profiler::colors::get_blue(color));
        const auto fgColor = ::profiler_gui::textColorForRgb(color);//0x00ffffff - bgColor;
        item->setBackgroundColor(color);
        item->setTextColor(fgColor);

        auto item_index = static_cast<unsigned int>(_items.size());
        _items.push_back(item);

        size_t children_items_number = 0;
        ::profiler::timestamp_t children_duration = 0;
        if (!gui_block.tree.children.empty())
        {
            children_items_number = FillTreeClass<T>::setTreeInternal(_safelocker, _items, _beginTime, gui_block.tree.children, item, item, thread_item, _left, _right, _strict, children_duration, _colorizeRows);
            if (_safelocker.interrupted())
                break;
        }

        int percentage = 100;
        auto self_duration = duration - children_duration;
        if (children_duration > 0 && duration > 0)
        {
            percentage = static_cast<int>(0.5 + 100. * static_cast<double>(self_duration) / static_cast<double>(duration));
        }

        item->setTimeSmart(COL_SELF_DURATION, self_duration);
        item->setData(COL_SELF_DURATION_PERCENT, Qt::UserRole, percentage);
        item->setText(COL_SELF_DURATION_PERCENT, QString::number(percentage));

        if (children_items_number > 0 || !_strict || (startTime >= _left && endTime <= _right))
        {
            //total_items += children_items_number + 1;
            gui_block.tree_item = item_index;

            if (_colorizeRows)
                item->colorize(_colorizeRows);

            if (gui_block.expanded)
                item->setExpanded(true);

        }
        else
        {
            _items.pop_back();
            delete item;
        }

        _safelocker.setProgress((90 * ++i) / total);
    }

    i = 0;
    total = static_cast<int>(threadsMap.size());
    for (auto& it : threadsMap)
    {
        auto item = it.second;

        if (item->childCount() > 0)
        {
            //addTopLevelItem(item);
            //m_roots[it.first] = item;

            //_items.push_back(item);
            _topLevelItems.emplace_back(it.first, item);

            //++total_items;
        }
        else
        {
            delete item;
        }

        _safelocker.setProgress(90 + (10 * ++i) / total);
    }

    _safelocker.setDone();
    //return total_items;
}
Ejemplo n.º 3
0
void SplitFasta(const char* seqDataFile, const char *outpath, const char *ext)/*{{{*/
{
	char seqFile[MAX_PATH+1] = "";
	//char command[MAX_COMMAND_LINE+1] = "";
	
	
	FILE *fpSeqData;
	FILE *fpSeq;
	fpSeqData = fopen(seqDataFile,"r");
    checkfilestream(fpSeqData, seqDataFile, "r");

	char id[SIZE_ID+1] = "";
	char str[SIZE_ID+10+1] = "";
    char rtname[MAX_PATH+1] = "";
    rootname(seqDataFile,rtname);
    int linesize;
    Array1D <char> line_1darray(maxline+1);
    char *line = line_1darray.array1D; 
    char delim[] = " \t\r\n>";
    char *pch = NULL;

	fpos_t pos;
    //int i;
	int cnt = 0 ;
	while((linesize = fgetline(fpSeqData,line,maxline)) != EOF)
	{
        if(linesize == 0 || IsBlankLine(line)) continue;

		if(line[0] == '>')//beginning of a record
		{
			cnt ++ ;
            my_strcpy(str, line, SIZE_ID+10);
            pch = strtok(str,delim);
            while(pch != NULL) //take the first word following '>' as id
            {
                my_strcpy(id, pch, SIZE_ID);
                break;
            }
            if(strcmp(id,"") == 0)// if no word following '>', set the id as rootname(seq-file)_cnt
            {
                sprintf(id,"%s_%d", rtname, cnt);
            }

			printf("%d\t:%s exported\n",cnt,id);
			sprintf(seqFile,"%s/%s.%s",outpath,id,ext);
			fpSeq = fopen(seqFile,"w");
            checkfilestream(fpSeq, seqFile, "r");
			fprintf(fpSeq,"%s\n",line);
			while(!feof(fpSeqData))
			{
				fgetpos(fpSeqData,&pos);
				linesize = fgetline(fpSeqData,line,maxline);
                if(linesize == 0 || IsBlankLine(line)) continue;
				if(line[0] == '>')
				{
					fsetpos(fpSeqData,&pos);
					break;
				}
				else
					fprintf(fpSeq,"%s\n",line);

			}
			fclose(fpSeq);
		}
	}
	fclose(fpSeqData);
	printf("%d sequences exported!\n",cnt);
}
Ejemplo n.º 4
0
void FillTreeClass<T>::setTreeInternal1(T& _safelocker, Items& _items, ThreadedItems& _topLevelItems, ::profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, bool _colorizeRows)
{
    _items.reserve(_blocksNumber + _blocksTree.size()); // _blocksNumber does not include Thread root blocks

    ::profiler::timestamp_t finishtime = 0;
    for (const auto& threadTree : _blocksTree)
    {
        const auto node_block = blocksTree(threadTree.second.children.front()).node;
        const auto startTime = node_block->begin();
        const auto endTime = node_block->end();

        if (_beginTime > startTime)
            _beginTime = startTime;

        if (finishtime < endTime)
            finishtime = endTime;
    }

    //const QSignalBlocker b(this);
    const auto u_thread = ::profiler_gui::toUnicode("thread");
    int i = 0;
    const int total = static_cast<int>(_blocksTree.size());
    for (const auto& threadTree : _blocksTree)
    {
        if (_safelocker.interrupted())
            break;

        const auto& root = threadTree.second;
        auto item = new EasyTreeWidgetItem();

        QString threadName;
        if (root.got_name())
        {
            QString rootname(::profiler_gui::toUnicode(root.name()));
            if (rootname.contains(u_thread, Qt::CaseInsensitive))
                threadName = ::std::move(QString("%1 %2").arg(rootname).arg(root.thread_id));
            else
                threadName = ::std::move(QString("%1 Thread %2").arg(rootname).arg(root.thread_id));
        }
        else
        {
            threadName = ::std::move(QString("Thread %1").arg(root.thread_id));
        }

        item->setText(COL_NAME, threadName);

        ::profiler::timestamp_t duration = 0;
        if (!root.children.empty())
            duration = blocksTree(root.children.back()).node->end() - blocksTree(root.children.front()).node->begin();

        item->setTimeSmart(COL_DURATION, duration);
        item->setBackgroundColor(::profiler_gui::SELECTED_THREAD_BACKGROUND);
        item->setTextColor(::profiler_gui::SELECTED_THREAD_FOREGROUND);

        //_items.push_back(item);

        item->setTimeSmart(COL_SELF_DURATION, root.active_time);

        ::profiler::timestamp_t children_duration = 0;
        const auto children_items_number = FillTreeClass<T>::setTreeInternal(_safelocker, _items, _beginTime, root.children, item, nullptr, item, _beginTime, finishtime + 1000000000ULL, false, children_duration, _colorizeRows);

        if (children_items_number > 0)
        {
            //total_items += children_items_number + 1;
            //addTopLevelItem(item);
            //m_roots[threadTree.first] = item;
            _topLevelItems.emplace_back(root.thread_id, item);
        }
        else
        {
            //_items.pop_back();
            delete item;
        }

        _safelocker.setProgress((100 * ++i) / total);
    }

    _safelocker.setDone();
    //return total_items;
}
Ejemplo n.º 5
0
int main(int argc, char** argv)/*{{{*/
{
    bool isNonOptionArg = false;
    if(argc < 2) 
    {
        PrintHelp();
        return 0;
    }
    int i,j;
    char modmfile[MAX_PATH+1] = "";
    char modmfilelist[MAX_PATH+1] = "";
    char outfile[MAX_PATH+1] = "";
    char suppliedAlphabet[SIZE_ALPHABET+1] = ""; /*force supplied alphabet to the alphabet in the output binary file*/
    char outpath[MAX_PATH+1] = ""; /*default output path for the binary file is the same as the ascii file*/
    double value = 0.0;
    int mode = 0;
    const char control_option[] = "bp"; //options which control the program, and does not take parameters

    char tmpfile[MAX_PATH+1] = "/tmp/fileXXXXXX";
    if (mkstemp(tmpfile) == -1)
    {
        fprintf(stderr, "Error! No temporary file can be created\n");
        return -1;
    }
    FILE *fptmp = fopen(tmpfile,"w");
    bool isIDsSet = false;
    bool isOutputTimeInfo = true;

    i = 1;
    while(i < argc)/*{{{*/
    {
        if(argv[i][0] == '-' && !isNonOptionArg) //options
        {
            isNonOptionArg = false;
            if(IsInCharSet(argv[i][1], control_option))//if argv[i][1] is in control_option, it might be used as -aqs
            {
                for(j = 1 ; j < strlen(argv[i]); j++)
                {
                    switch (argv[i][j])
                    {
                        case 'b': isWriteBinaryFile = true; break;
                        case 'p': isPrintOut = true; break;
                        default : fprintf(stderr,"Invalid option, non-control option '%c' can be used together with contorl-option\n", argv[j]); return -1;
                    }
                }
                i ++;
            }
            else if(strcmp(argv[i],"-h") == 0 ||strcmp(argv[i],"--help")==0 )
            {
                PrintHelp(); 
                return 0;
            }
            else if(strcmp(argv[i],"-H") == 0 )
            {
                PrintVerboseHelp();
                return 0;
            }
            else if(strcmp(argv[i],"-a") == 0 )
            {
                my_strcpy(suppliedAlphabet, argv[i+1], SIZE_ALPHABET);
                i += 2;

            }
            else if( (strcmp(argv[i],"-o") == 0) || (strcmp(argv[i], "--out") == 0))  
            {
                if( ( i = option_parser_filename(argc, argv, i, outfile)) == -1)
                    return -1;
            }
            else if( (strcmp(argv[i], "--outpath") == 0))  
            {
                if( ( i = option_parser_filename(argc, argv, i, outpath)) == -1)
                    return -1;
            }
            else if( (strcmp(argv[i],"-l") == 0) )  
            {
                if( ( i = option_parser_filename(argc, argv, i, modmfilelist)) == -1)
                    return -1;
            }
            else if( (strcmp(argv[i], "--mode") == 0))  
            {
                if( ( i = option_parser_numeric(argc, argv, i, mode, true, 0, 1)) == -1)
                    return -1;
            }
            else if (strcmp(argv[i], "--sad") == 0)/*indicating the modm file contains SAD information*/
            {
                isHaveSAD = true;
                i ++;
            }
            else if (strcmp(argv[i], "--notime") == 0)/*do not output time info*/
            {
                isOutputTimeInfo = false;
                i ++;
            }
            else if (strcmp(argv[i], "--") == 0)//next item is non option argument
            {
                isNonOptionArg = true;
                i ++;
                continue;
            }
            else
            {
                fprintf(stderr,"Error! Invalid argument '%s'\n", argv[i]);
                return -1;
            }
        }
        else //non-option argument
        {
            if(!isIDsSet) 
            {
                fptmp = fopen(tmpfile,"w");
                if(fptmp == NULL)
                {
                    fprintf(stderr,"can not open file '%s' for write\n", tmpfile);
                    assert( fptmp != NULL);
                }
            }
            fprintf(fptmp,"%s\n",argv[i]);
            isIDsSet = true;
            i ++;
        }
    }/*}}}*/

    if(isIDsSet) fclose(fptmp);


    if(!isIDsSet && strcmp(modmfilelist, "") == 0)
    {
        fprintf(stderr,"Error! neither ids and idListFile set\n");
        PrintHelp();
        return -1;
    }
    else if(isIDsSet && strcmp(modmfilelist,"") == 0)
    {
        my_strcpy(modmfilelist,tmpfile,MAX_PATH);
    }

    FILE *fpout = NULL;
    if(strcmp(outfile,"") == 0 || strcasecmp(outfile, "stdout") == 0)
    {
        fpout = stdout;
    }
    else
    {
        fpout = fopen(outfile, "w");
        checkfilestream(fpout, outfile,"w");
    }

    clock_t start, finish;
    double duration;
    int tmp;
    start = clock();

    FILE *fpFileList = fopen(modmfilelist, "r");
    checkfilestream(fpFileList, modmfilelist, "r");
    int linesize;
    int maxline = 300;
    Array1D <char> line_1darray(maxline+1);
    char *line = line_1darray.array1D;

    int sizeAlphabet = 0;
    char alphabet[SIZE_ALPHABET+1] = "";
    int numRes = 0;
    Array1D <Profile> profile_1darray(2000);
    Profile *profile = profile_1darray.array1D;
    Array1D <ProfileSAD> profileSAD_1darray(2000);
    ProfileSAD *profileSAD = profileSAD_1darray.array1D;
    double parameter[8];
    int status_sscanf = 0;

    int cntFile  = 0;
    while((linesize = fgetline(fpFileList,line, maxline)) != EOF)
    {
        my_strcpy(modmfile, line, MAX_PATH);

        for(j = 0; j < 8; j ++)
        {
            parameter[j] = 0.0;
        }
        strcpy(alphabet,"");


        if(mode == 0) /*read text file*/
        {
            FILE *fpin = fopen(modmfile,"r");
            checkfilestream(fpin,modmfile,"r");
            char str[100] = "";
            char first_non_blank_char = ' ';
            int cntRes = 0;
            while((linesize = fgetline(fpin, line, maxline)) != EOF)
            {
                if(line[0] == '#' || linesize <=0 ) 
                {
                    continue;
                }
                sscanf(line, " %c", &first_non_blank_char);
                if (first_non_blank_char == 'N')/*alphabet line*/
                {
                    SpanExcluding(line, str);
                    if(!isHaveSAD)
                    {
                        my_strcpy(alphabet, str+5, SIZE_ALPHABET);
                    }
                    else
                    {
                        my_strcpy(alphabet, str+8, SIZE_ALPHABET);
                    }
                }
                else if (isdigit(first_non_blank_char))
                {
                    if(!isHaveSAD)
                    {
                        profile[cntRes].score1 = 0.0;
                        profile[cntRes].score2 = 0.0;
                        status_sscanf = sscanf(line,"%d %c %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",/*{{{*/
                                &profile[cntRes].aaSeqIndex, 
                                &profile[cntRes].aa,
                                &profile[cntRes].p[0],
                                &profile[cntRes].p[1],
                                &profile[cntRes].p[2],
                                &profile[cntRes].p[3],
                                &profile[cntRes].p[4],
                                &profile[cntRes].p[5],
                                &profile[cntRes].p[6],
                                &profile[cntRes].p[7],
                                &profile[cntRes].p[8],
                                &profile[cntRes].p[9],
                                &profile[cntRes].p[10],
                                &profile[cntRes].p[11],
                                &profile[cntRes].p[12],
                                &profile[cntRes].p[13],
                                &profile[cntRes].p[14],
                                &profile[cntRes].p[15],
                                &profile[cntRes].p[16],
                                &profile[cntRes].p[17],
                                &profile[cntRes].p[18],
                                &profile[cntRes].p[19],
                                &profile[cntRes].score1,
                                &profile[cntRes].score2
                                    );/*}}}*/
                        if(status_sscanf < 22)
                        {
                            fprintf(stderr,"current line=%s\n!", line );
                            fprintf(stderr,"The profile maybe incomplete, status_sscanf = %d, number %d, file %s\n!", status_sscanf, cntRes+1, modmfile );
                            assert (status_sscanf >= 22);
                        }
                    }
                    else
                    {
                        profileSAD[cntRes].score1 = 0.0;
                        profileSAD[cntRes].score2 = 0.0;
                        status_sscanf = sscanf(line,"%d %c %1c%1d%1c %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",/*{{{*/
                                &profileSAD[cntRes].aaSeqIndex, 
                                &profileSAD[cntRes].aa,
                                &profileSAD[cntRes].shape,
                                &profileSAD[cntRes].waterAcc,
                                &profileSAD[cntRes].dsspSec,
                                &profileSAD[cntRes].p[0],
                                &profileSAD[cntRes].p[1],
                                &profileSAD[cntRes].p[2],
                                &profileSAD[cntRes].p[3],
                                &profileSAD[cntRes].p[4],
                                &profileSAD[cntRes].p[5],
                                &profileSAD[cntRes].p[6],
                                &profileSAD[cntRes].p[7],
                                &profileSAD[cntRes].p[8],
                                &profileSAD[cntRes].p[9],
                                &profileSAD[cntRes].p[10],
                                &profileSAD[cntRes].p[11],
                                &profileSAD[cntRes].p[12],
                                &profileSAD[cntRes].p[13],
                                &profileSAD[cntRes].p[14],
                                &profileSAD[cntRes].p[15],
                                &profileSAD[cntRes].p[16],
                                &profileSAD[cntRes].p[17],
                                &profileSAD[cntRes].p[18],
                                &profileSAD[cntRes].p[19],
                                &profileSAD[cntRes].score1,
                                &profileSAD[cntRes].score2
                                    );/*}}}*/
                        if(status_sscanf < 25)
                        {
                            fprintf(stderr,"current line=%s\n!", line );
                            fprintf(stderr,"The profile maybe incomplete, status_sscanf = %d, number %d, file %s\n!", status_sscanf, cntRes+1, modmfile );
                            assert (status_sscanf >= 25);
                        }
                    }
                    cntRes ++;
                }
                else if (first_non_blank_char == 'K')
                {
                    int j = 0 ;
                    while((linesize = fgetline(fpin, line, maxline)) != EOF)
                    {
                        status_sscanf = sscanf(line,"%s %s %lf %lf", str, str, &parameter[j], &parameter[j+1]);
                        if(status_sscanf < 4)
                        {
                            fprintf(stderr,"Warning, file %s may not have psi-blast parameters\n", modmfile);
                        }
                        j += 2;
                        if (j >= 8 ) break;
                    }
                }
            }
            fclose(fpin);
            numRes = cntRes;
            if (isWriteBinaryFile)
            {
                char binaryfile[MAX_PATH+1] = "";
                if(strcmp(outpath, "") == 0)  /*if outpath is not set, output to the same folder as the ascii file*/
                {
                    sprintf(binaryfile, "%sbin", modmfile);   /*if outpath is set*/
                }
                else
                {

                    char rtname[MAX_PATH+1] = "";
                    char fileext[MAX_PATH+1] = "";
                    rootname(modmfile, rtname);
                    getfileext(modmfile, fileext);
                    sprintf(binaryfile, "%s/%s.%sbin", outpath, rtname, fileext);
                }
//                fprintf(stdout,"%d \t write out binary file to %s\n", cntFile, binaryfile) ;
                if(strcmp(suppliedAlphabet,"") != 0)
                {
                    my_strcpy(alphabet, suppliedAlphabet, SIZE_ALPHABET);
                }
                if(!isHaveSAD)
                {
                    WriteBinaryMODM(binaryfile, alphabet, numRes, profile, parameter);
                }
                else
                {
                    WriteBinaryMODM(binaryfile, alphabet, numRes, profileSAD, parameter);
                }
            }
        }
        else if(mode == 1)
        {

            if(!isHaveSAD)
            {
                GetBinaryMODM(modmfile, alphabet, numRes, profile, parameter);
                if (isPrintOut)
                {
                    WriteMODM(alphabet, profile, numRes, parameter, fpout);
                }
            }
            else
            {
                GetBinaryMODM(modmfile, alphabet, numRes, profileSAD, parameter);
                if (isPrintOut)
                {
                    WriteMODM(alphabet, profileSAD, numRes, parameter, fpout);
                }
            }
        }
        cntFile ++;
    }

    finish = clock();
    duration = double(finish-start)  /double(CLOCKS_PER_SEC);
    //printf("CLOCKS_PER_SEC=%d, start=%lf, finish=%lf\n", CLOCKS_PER_SEC, start, finish);
    if (isOutputTimeInfo)
    {
        if(mode == 0)
        {
            fprintf(stdout,"reading text file cost %lf seconds\n", duration);
        }
        else if(mode == 1)
        {
            fprintf(stdout,"reading bindary file cost %lf seconds\n", duration);
        }

    }

    if(fpout != NULL && fpout != stdout) fclose(fpout);

    return 0;
}