File: custom_file_endings.cpp

package info (click to toggle)
seqan2 2.4.0%2Bdfsg-14
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 224,136 kB
  • sloc: cpp: 256,886; ansic: 91,672; python: 8,330; sh: 995; xml: 570; makefile: 251; awk: 51; javascript: 21
file content (76 lines) | stat: -rw-r--r-- 1,947 bytes parent folder | download | duplicates (5)
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
//![includes]
#include <seqan/stream.h>
#include <seqan/seq_io.h>
//![includes]
//![custom_file]
namespace seqan
{
// Your custom file format.
struct MyFastaAdaptor_;
using MyFastaAdaptor = Tag<MyFastaAdaptor_>;

// Specilaize sequence input file with custom tag.
using MySeqFileIn = FormattedFile<Fastq, Input, MyFastaAdaptor>;
//![custom_file]
//![custom_format]
// Your custom format tag.
struct MySeqFormat_;
using MySeqFormat = Tag<MySeqFormat_>;

// The extended TagList containing our custom format.
using MySeqInFormats = TagList<MySeqFormat, SeqInFormats>;

// Overloaded file format metafunction.
template <>
struct FileFormat<FormattedFile<Fastq, Input, MyFastaAdaptor> >
{
    using Type = TagSelector<MySeqInFormats>;
};

// Set magic header.
template <typename T>
struct MagicHeader<MySeqFormat, T> : public MagicHeader<Fasta, T>
{};
//![custom_format]
//![custom_extension]
// Specify the valid ending for your fasta adaptor.
template <typename T>
struct FileExtensions<MySeqFormat, T>
{
    static char const * VALUE[1];
};

template <typename T>
char const * FileExtensions<MySeqFormat, T>::VALUE[1] =
{
    ".fa.dat"  // fasta file with dat ending.
};
//![custom_extension]

//![custom_read_record]
// Overload an inner readRecord function to delegate to the actual fasta parser.
template <typename TIdString, typename TSeqString, typename TSpec>
inline void
readRecord(TIdString & meta, TSeqString & seq, FormattedFile<Fastq, Input, TSpec> & file, MySeqFormat)
{
    readRecord(meta, seq, file.iter, Fasta());  // Just delegate to Fasta parser.
}
} // namespace seqan
//![custom_read_record]
//![main]
int main()
{
    using namespace seqan;
    std::string path = getAbsolutePath("demos/howto/custom_file_ending.fa.dat");

    MySeqFileIn seqFile(path.c_str());

    CharString meta;
    Dna5String seq;

    readRecord(meta, seq, seqFile);

    std::cout << "> " << meta << "\n" << seq << std::endl;
    return 0;
}
//![main]