Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Armin Sobhani
bioseq
Commits
8b809e84
Commit
8b809e84
authored
Jul 11, 2018
by
Armin Sobhani
Browse files
add fasta file format output capability with unit tests
parent
bbf0119b
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/boost/bioseq/io_formats/fasta.hpp
View file @
8b809e84
...
...
@@ -34,7 +34,18 @@ public:
private:
virtual
void
do_print
(
std
::
basic_ostream
<
CharT
,
Traits
>&
out
,
const
SeqT
&
s
)
{}
{
out
<<
'>'
<<
s
.
long_name
();
for
(
size_t
i
=
0
;
i
<
s
.
size
();
++
i
)
{
if
(
0
==
i
%
70
)
out
<<
std
::
endl
;
out
<<
s
[
i
];
}
out
<<
std
::
endl
;
}
virtual
void
do_scan
(
std
::
basic_istream
<
CharT
,
Traits
>&
in
,
SeqT
&
s
)
{
...
...
test/test_io_fasta.cpp
View file @
8b809e84
...
...
@@ -15,7 +15,7 @@
#define BOOST_TEST_MODULE TestIOFasta
#include
<boost/mpl/list.hpp>
#include
<boost/test/unit_test.hpp>
//
#include <boost/test/output_test_stream.hpp>
#include
<boost/test/output_test_stream.hpp>
// #if (BOOST_VERSION >= 105900)
// # include <boost/test/unit_test_parameters.hpp>
// #else
...
...
@@ -35,27 +35,28 @@
#include
<boost/bioseq/components/description.hpp>
#include
<boost/bioseq/io_formats/fasta.hpp>
namespace
bioseq
=
boost
::
bioseq
;
using
boost
::
test_tools
::
output_test_stream
;
namespace
bsq
=
boost
::
bioseq
;
// preparing str_seq type
template
<
class
CharT
,
class
AllocatorT
>
using
bs_string
=
std
::
basic_string
<
CharT
,
std
::
char_traits
<
CharT
>
,
AllocatorT
>
;
typedef
b
iose
q
::
sequence_host
typedef
b
s
q
::
sequence_host
<
char
,
std
::
allocator
,
bs_string
,
b
iose
q
::
component
::
name
<>
,
b
iose
q
::
component
::
description
<>
,
b
s
q
::
component
::
name
<>
,
b
s
q
::
component
::
description
<>
>
str_seq
;
typedef
b
iose
q
::
ioformat
typedef
b
s
q
::
ioformat
<
char
,
std
::
char_traits
<
char
>
,
str_seq
,
b
iose
q
::
fasta_format
,
b
s
q
::
fasta_format
>
frmt1
;
#if BOOST_WORKAROUND(BOOST_GCC, < 70000)
...
...
@@ -63,24 +64,24 @@ typedef bioseq::ioformat
template
<
>
struct
io_format_traits
<
str_seq
>
{
typedef
frmt1
type
;
};
}}
#else
template
<
>
struct
b
iose
q
::
io_format_traits
<
str_seq
>
{
typedef
frmt1
type
;
};
template
<
>
struct
b
s
q
::
io_format_traits
<
str_seq
>
{
typedef
frmt1
type
;
};
#endif // BOOST_GCC < 70000
// preparing vec_seq type
typedef
b
iose
q
::
sequence_host
typedef
b
s
q
::
sequence_host
<
char
,
std
::
allocator
,
std
::
vector
,
b
iose
q
::
component
::
name
<>
,
b
iose
q
::
component
::
description
<>
,
b
s
q
::
component
::
name
<>
,
b
s
q
::
component
::
description
<>
>
vec_seq
;
typedef
b
iose
q
::
ioformat
typedef
b
s
q
::
ioformat
<
char
,
std
::
char_traits
<
char
>
,
vec_seq
,
b
iose
q
::
fasta_format
,
b
s
q
::
fasta_format
>
frmt2
;
#if BOOST_WORKAROUND(BOOST_GCC, < 70000)
...
...
@@ -88,7 +89,7 @@ typedef bioseq::ioformat
template
<
>
struct
io_format_traits
<
vec_seq
>
{
typedef
frmt2
type
;
};
}}
#else
template
<
>
struct
b
iose
q
::
io_format_traits
<
vec_seq
>
{
typedef
frmt2
type
;
};
template
<
>
struct
b
s
q
::
io_format_traits
<
vec_seq
>
{
typedef
frmt2
type
;
};
#endif // BOOST_GCC < 70000
...
...
@@ -97,38 +98,18 @@ typedef boost::mpl::list<vec_seq, str_seq> seq_types;
BOOST_AUTO_TEST_CASE_TEMPLATE
(
read_single_fasta
,
T
,
seq_types
)
{
// auto start = std::chrono::high_resolution_clock::now();
// for (size_t i = 0; i < 1000; ++i)
// {
std
::
ifstream
in
(
BOOST_BIOSEQ_TEST_DATA_PATH
"/chrMT.fa"
);
T
mt
;
in
>>
mt
;
// }
// auto d = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start);
// std::cout << "Elapsed time: " << d.count() << " ms" << std::endl;
BOOST_CHECK_EQUAL
(
mt
[
0
],
'G'
);
BOOST_CHECK_EQUAL
(
mt
[
1
],
'A'
);
BOOST_CHECK_EQUAL
(
mt
[
69
],
'G'
);
BOOST_CHECK_EQUAL
(
mt
[
139
],
'C'
);
BOOST_CHECK_EQUAL
(
mt
[
16566
],
'A'
);
BOOST_CHECK_EQUAL
(
mt
[
16567
],
'T'
);
BOOST_CHECK_EQUAL
(
mt
[
16568
],
'G'
);
std
::
ifstream
in
(
BOOST_BIOSEQ_TEST_DATA_PATH
"/chrMT.fa"
);
T
mt
;
in
>>
mt
;
BOOST_CHECK
(
16569
==
mt
.
size
()
);
BOOST_CHECK_EQUAL
(
mt
.
name
(),
"gi|113200490|gb|J01415.2|HUMMTCG"
);
BOOST_CHECK_EQUAL
(
mt
.
description
(),
"Homo sapiens mitochondrion, complete genome"
);
BOOST_CHECK_EQUAL
(
mt
.
long_name
(),
"gi|113200490|gb|J01415.2|HUMMTCG Homo sapiens mitochondrion, complete genome"
);
// BOOST_CHECK( mt.short_name() == "gi|113200490|gb|J01415.2|HUMMTCG" );
// BOOST_CHECK( mt.long_name()
// == "gi|113200490|gb|J01415.2|HUMMTCG "
// "Homo sapiens mitochondrion, complete genome" );
// output_test_stream cout(BOOST_BIOSEQ_TEST_DATA_PATH"/chrMT.fa");
// cout << mt;
// BOOST_CHECK(cout.match_pattern());
output_test_stream
cout
(
BOOST_BIOSEQ_TEST_DATA_PATH
"/chrMT.fa"
);
cout
<<
mt
;
BOOST_CHECK
(
cout
.
match_pattern
());
}
BOOST_AUTO_TEST_CASE_TEMPLATE
(
read_multi_fasta
,
T
,
seq_types
)
...
...
@@ -162,6 +143,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(read_multi_fasta, T, seq_types)
BOOST_CHECK_EQUAL
(
reads
[
0
].
long_name
(),
"gi|406593966|ref|NC_018627.1|-40485/1"
);
output_test_stream
cout
(
BOOST_BIOSEQ_TEST_DATA_PATH
"/reads.fa"
);
for
(
const
auto
&
read
:
reads
)
{
cout
<<
read
;
BOOST_CHECK
(
cout
.
match_pattern
());
}
// T copy(reads[0]);
// BOOST_CHECK_EQUAL(copy.name(), "gi|406593966|ref|NC_018627.1|-40485/1");
// BOOST_CHECK_EQUAL(copy.data(), "ACACCAGAAGCATCGTCTGTTGTGGTGATATATGCGGGCTCTTCTGTTATCTCGTTAAGATCGAGATGGAGATTCTTTACTGAGATGTTGTTGGTAGTTTGAAACTTCGTCCCAGGATGCATGCAGAGTATAGATTGAAGATTTTCATCA");
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment