Class GffStream
High-level GFF/GTF I/O class.

Defined in <seqan/gff_io.h>
Signature class GffStream;

Member Function Overview

Interface Function Overview

Member Variable Overview

Detailed Description

The GffStream class allows to read and write GTF and GFF files.

Remarks

Note that the class GffStream allows to read both GFF 2, 3, and GTF. For writing, only GFF 3 and GTF are supported.

Examples

The following example demonstrates reading a GFF file and printing the annotation locations.

#include <seqan/basic.h>
#include <seqan/gff_io.h>

using namespace seqan;

// USAGE: gff_stream_read IN.gff
//
// Read GFF file and print the positions (reference, position) to stdout.

int main(int argc, char ** argv)
{
    if (argc != 2)
    {
        std::cerr << "USAGE: " << argv[1] << " IN.gff\n";
        return 1;
    }

    GffStream gffIn(argv[1]);
    if (!isGood(gffIn))
    {
        std::cerr << "ERROR: Could not open " << argv[1] << " for reading!\n";
        return 1;
    }

    GffRecord record;
    while (!atEnd(gffIn))
    {
        if (readRecord(record, gffIn) != 0)
        {
            std::cerr << "ERROR: Problem reading from " << argv[1] << "\n";
            return 1;
        }

        // Note that we print the position 1-based since we use text output
        // whereas it is 0-based in the GffRecord.
        std::cout << gffIn.sequenceNames[record.rID]
                  << "\t" << (record.beginPos + 1) << "\n";
    }

    return 0;
}

See Also

Member Functions Detail

GffStream::GffStream(); GffStream::GffStream(fileName[, mode=READ[, fileFormat=GFF]]);

Constructor.

Parameters

fileName The path to the file to open, char const *.
mode The open mode, GffStream::Mode, default is READ.
fileFormat The open mode, GffStream::FileFormat, default is auto-detect.

See Also

Interface Functions Detail

void addSequenceName(gffStream, seqName);

Add the name of a sequence to a GffStream .

Parameters

gffStream The GffStream to add the name to
seqName The name of the sequence to append, CharString.

bool atEnd(gffStream);

Query a GffStream for being at the end of the file.

Parameters

gffStream The GffStream to query. Types: GffStream

Returns

bool true if stream is at the end, false otherwise.

int close(gffStream);

Closes a GffStream

Parameters

gffStream The GffStream to close. Types: GffStream

Returns

int 0 on success, non-0 on failure.

int flush(gffStream);

Flush to a GffStream.

Parameters

gffStream The GffStream to flush. Types: GffStream

Returns

int 0 on success, non-0 on failure.

bool isGood(gffStream);

Query a GffStream for errors.

Parameters

gffStream The GffStream to query.

Returns

bool true if stream is good, false otherwise.

bool open(gffStream, fileName[, mode[, fileFormat]]);

Open a GffStream .

Parameters

gffStream The GffStream to open.
fileName The path to the file to open, char const *.
mode The open mode, GffStream::Mode, defaults to GffStream::Mode::READ.
fileFormat File format to use for writing, GffStream::FileFormat.

Returns

bool true on success, false on failure.

See Also

int readRecord(record, gffStream);

Read a record from a GffStream

Parameters

record The GffRecord to read into, GffRecord.
gffStream The GffStream to read from, GffStream.

Returns

int 0 on success, non-0 on failure.

int writeRecord(gffStream, record);

Write a record to a GffStream.

Parameters

gffStream The GffStream to write to.
record The GffRecord to write.

Returns

int 0 on success, non-0 on failure.

Member Variables Detail

GffStream::FileFormat GffStream::fileFormat

File format to use for writing.

TCharStringSet GffStream::sequenceNames

The names of the sequences (StringSet of CharString), updated when new sequences are seen in GFF file.