-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenericSampleSet.cpp
92 lines (85 loc) · 2.5 KB
/
GenericSampleSet.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "GenericSampleSet.hpp"
void GenericSampleSet::_read(fstream& file)
{
const string& fileName = Base::fileName;
marker::Set* markers = Base::markers;
string ext = name::fileext(fileName);
switch (mapping::extension[ext]) {
case data::raw:
rep = new RawSampleSet<cnvalue>(markers);
break;
case data::raw_ascn:
rep = new RawSampleSet<alleles_cn>(markers);
break;
case data::segmented:
rep = new SegmentedSampleSet<cnvalue>(markers);
break;
case data::segmented_ascn:
rep = new SegmentedSampleSet<alleles_cn>(markers);
default:
throw invalid_conversion("Cannot determine file type from file name extension.");
}
rep->_read(file);
}
void GenericSampleSet::_write(fstream& file)
{
const string& fileName = Base::fileName;
string ext = name::fileext(fileName);
// cast $rep to appropriate type
// runtime checking is skipped (i.e. use static_cast instead of dynamic_cast)
// since exact type can be determined
SampleSet* tmp = NULL;
data::Type outputType = mapping::extension[ext];
if (outputType != rep->type()) {
// output type differs from current representation type: conversion necessary
switch (outputType) {
case data::raw:
switch (rep->type()) {
case data::segmented:
tmp = new RawSampleSet<cnvalue>(*static_cast<SegmentedSampleSet<cnvalue>*>(rep));
swap(rep, tmp);
delete tmp;
break;
default:
throw invalid_conversion("Conversion not supported.");
}
break;
case data::raw_ascn:
switch (rep->type()) {
case data::segmented_ascn:
tmp = new RawSampleSet<alleles_cn>(*static_cast<SegmentedSampleSet<alleles_cn>*>(rep));
swap(rep, tmp);
delete tmp;
break;
default:
throw invalid_conversion("Conversion not supported.");
}
break;
case data::segmented:
switch (rep->type()) {
case data::raw:
tmp = new SegmentedSampleSet<cnvalue>(*static_cast<RawSampleSet<cnvalue>*>(rep));
swap(rep, tmp);
delete tmp;
break;
default:
throw invalid_conversion("Conversion not supported.");
}
break;
case data::segmented_ascn:
switch (rep->type()) {
case data::raw_ascn:
tmp = new SegmentedSampleSet<alleles_cn>(*static_cast<RawSampleSet<alleles_cn>*>(rep));
swap(rep, tmp);
delete tmp;
break;
default:
throw invalid_conversion("Conversion not supported.");
}
break;
default:
throw invalid_conversion("Cannot determine file type from file name extension.");
}
}
rep->_write(file);
}