source: tags/cvs_2_svn/GENOM_IMPORT/GASourceFileSwitcher.cpp

Last change on this file was 5390, checked in by westram, 16 years ago
  • TAB-Ex
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1#ifndef GASOURCEFILESWITCHER_H
2#include "GASourceFileSwitcher.h"
3#endif
4
5gellisary::GASourceFileSwitcher::GASourceFileSwitcher(const char * nFile_name)
6{
7    file_name = nFile_name;
8}
9
10int gellisary::GASourceFileSwitcher::make_a_decision()
11{
12    int file_name_size = file_name.size();
13
14    for(int i = (file_name_size-1); i >= 0; i--)
15    {
16        if(file_name[i] == '.')
17        {
18            for(int j = (i+1); j < file_name_size; j++)
19            {
20                extension += file_name[j];
21            }
22        }
23    }
24    if((extension != "embl") && (extension != "gbk") && (extension != "dat") && (extension != "ff") && (extension != "ddbj"))
25    {
26        flat_file.open(file_name.c_str());
27        char tmp_line[128];
28        flat_file.getline(tmp_line,128);
29        std::string t_string(tmp_line);
30        if(t_string.size() > 0)
31        {
32            if((t_string[0] == 'I') && (t_string[1] == 'D') && (t_string[2] == ' '))
33            {
34                extension = "embl";
35            }
36            else if((t_string[0] == 'L') && (t_string[1] == 'O') && (t_string[2] == 'C') && (t_string[3] == 'U') && (t_string[4] == 'S') && (t_string[5] == ' '))
37            {
38                extension = "gbk";
39            }
40        }
41        flat_file.close();
42    }
43    if(extension == "embl" || extension == "dat")
44    {
45        return EMBL;
46    }
47    else if(extension == "gbk")
48    {
49        return GENBANK;
50    }
51    else if((extension == "ff") || (extension == "ddbj"))
52    {
53        if(containsHeader())
54        {
55            return DDBJ;
56        }
57        else
58        {
59            return DDBJ_WITHOUT_HEADER;
60        }
61    }
62    else
63    {
64        return UNKNOWN;
65    }
66}
67
68bool gellisary::GASourceFileSwitcher::containsHeader()
69{
70
71    flat_file.open(file_name.c_str());
72    char buffer[100];
73    while(!flat_file.eof())
74    {
75        flat_file.getline(buffer,100);
76        std::string t_line(buffer);
77        std::string::size_type pos_first = t_line.find_first_of(" ");
78        if(pos_first != std::string::npos)
79        {
80            std::string key_string = t_line.substr(0,pos_first);
81            if(key_string == "ACCESSION" || key_string == "accession")
82            {
83                pos_first += 3;
84                std::string value_string = t_line.substr(pos_first);
85                std::string::size_type pos_second = value_string.find_first_of(" ");
86                if(pos_second != std::string::npos)
87                {
88                    flat_file.close();
89                    return false;
90                }
91                else
92                {
93                    flat_file.close();
94                    return true;
95                }
96                break;
97            }
98            else
99            {
100                continue;
101            }
102        }
103    }
104    if(flat_file.is_open())
105    {
106        flat_file.close();
107    }
108    return false;
109}
110
111gellisary::GASourceFileSwitcher::~GASourceFileSwitcher()
112{
113
114}
Note: See TracBrowser for help on using the repository browser.