Chinaunix首页 | 论坛 | 博客
  • 博客访问: 33249
  • 博文数量: 35
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 360
  • 用 户 组: 普通用户
  • 注册时间: 2021-09-17 18:39
文章分类

全部博文(35)

文章存档

2021年(35)

我的朋友

分类: C/C++

2021-09-18 13:47:11

#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include "structure_use.h"
/*struct Fas
{
    char name[30];
    char *seq;
    Fas *lnk;
};
struct S_e
*/
/*从main中得到文件指针
剥离出序列
*/
Fas *autosearch(FILE*in, FILE*out,int*seq_count)
{
    char _ctr = '\0';
    int l_c = 0;                                                //loop controler
    Fas *head=NULL,*n1=NULL,*n2=NULL;
    char*tmp = (char*)malloc(10000000), *tmp_ing = tmp;
    while (_ctr = fgetc(in))
    {
        if (_ctr == '>')
        {
            if (feof(in))
            {
                break;
            }
            n1 = (Fas*)malloc(sizeof(Fas));
            fgets((*n1).name, 27, in);
            if ((*n1).name[strlen((*n1).name)-1] != '\n')
            {
                (*n1).name[strlen((*n1).name)] = '\r';
                (*n1).name[strlen((*n1).name) + 1] = '\n';
                (*n1).name[strlen((*n1).name) + 2] = '\0';
                while ((_ctr = fgetc(in)) != '\n');
            }
            for (l_c = 0; l_c < 10000000; l_c++)
            {
                if ((_ctr = fgetc(in)) == 'a' || _ctr == 't' || _ctr == 'c' || _ctr == 'g' || _ctr == 'A' || _ctr == 'T' || _ctr == 'C' || _ctr == 'G')
                {
                    *tmp_ing = _ctr;
                    tmp_ing++;
                }
                else if (_ctr == '\r' || _ctr == '\n')                                    //要求序列中不要出现换行
                {
                    NULL;
                }
                else if (_ctr=='>'||_ctr == EOF)
                {
                    *tmp_ing = '\0';
                    break;
                }
                else 
                {
                    printf("unexpected character happened on %s at %d as %c\n", (*n1).name, l_c, _ctr);


                }
            }
            _strupr(tmp);//全部变成大写
            (*seq_count)++;
            (*n1).seq = (char*)malloc(strlen(tmp) + 1);
            strcpy((*n1).seq, tmp);
            if (*seq_count == 1)                                                                            //这个seq_count计数是从1开始
            {
                head = n1;
                n2 = n1;
            }
            else
            {
                (*n2).lnk = n1;
                n2 = n1;
            }
        }
        else
        {
            printf("dropped char as %c\n", _ctr);
        }
        if (feof(in))
        {
            break;
        }
    }
阅读(449) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~