Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Ludovic PLATON
/
IRSOM
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Ludovic PLATON
2018-03-21 10:27:26 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c206d3de63ae18542552fe7b30d31576196b1521
c206d3de
1 parent
d3c5f541
Improve performance of Featurer
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
41 deletions
Featurer/data/data_store.h
Featurer/data/data_store_map.h
Featurer/main.cpp
Featurer/data/data_store.h
View file @
c206d3d
...
...
@@ -3,6 +3,8 @@
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include "../multithread/buffer_producer.h"
#include "data_basic.h"
...
...
@@ -12,38 +14,60 @@ namespace data{
class
Data_Store
{
protected
:
int
size
=
0
;
bool
write_on_add
;
std
::
string
file_name
;
std
::
ofstream
output
;
virtual
void
add_internal
(
data
::
Data_basic
*
data
)
=
0
;
public
:
virtual
~
Data_Store
(){}
Data_Store
()
:
write_on_add
(
false
){}
Data_Store
(
std
::
string
file_name
)
:
write_on_add
(
true
),
file_name
(
file_name
)
{
this
->
output
.
open
(
this
->
file_name
,
std
::
ios
::
trunc
);
}
virtual
~
Data_Store
(){
this
->
output
.
close
();
}
int
getSize
(){
return
this
->
size
;}
virtual
void
add
(
data
::
Data_basic
*
data
)
=
0
;
virtual
multithread
::
Buffer
<
data
::
Data_basic
*>*
get
(
std
::
string
pattern
)
=
0
;
void
write
(
std
::
string
file_name
,
std
::
string
pattern
){
multithread
::
Buffer
<
data
::
Data_basic
*>
*
buf
;
std
::
string
towrite
;
std
::
ofstream
output
;
output
.
open
(
file_name
,
std
::
ios
::
out
|
std
::
ios
::
trunc
);
buf
=
this
->
get
(
pattern
);
int
count_buf
(
0
);
while
(
buf
->
available
()){
if
(
!
buf
->
isEmpty
()){
data
::
Data_basic
*
tmp
=
buf
->
pop
();
towrite
+=
tmp
->
to_csv
()
+
"
\n
"
;
count_buf
++
;
delete
tmp
;
}
else
{
std
::
this_thread
::
sleep_for
(
THREAD_SLEEP
);
}
if
(
count_buf
==
NB_ELT_BUF
){
output
<<
towrite
;
towrite
.
clear
();
count_buf
=
0
;
}
}
if
(
count_buf
>
0
){
output
<<
towrite
;
void
add
(
data
::
Data_basic
*
data
){
this
->
add_internal
(
data
);
if
(
this
->
write_on_add
){
std
::
string
tmp
=
data
->
to_csv
();
this
->
output
<<
tmp
<<
std
::
endl
;
}
output
.
close
();
}
virtual
multithread
::
Buffer
<
data
::
Data_basic
*>*
get
(
std
::
string
pattern
)
=
0
;
// void write(std::string file_name, std::string pattern){
// multithread::Buffer<data::Data_basic*> *buf;
// std::string towrite;
// std::ofstream output;
// output.open(file_name, std::ios::out | std::ios::trunc);
// buf = this->get(pattern);
// int count_buf(0);
// while(buf->available()){
// if(!buf->isEmpty()){
// data::Data_basic* tmp = buf->pop();
// towrite += tmp->to_csv()+"\n";
// count_buf ++;
// delete tmp;
// }else{
// std::this_thread::sleep_for(THREAD_SLEEP);
// }
// if(count_buf == NB_ELT_BUF){
// output << towrite;
// towrite.clear();
// count_buf=0;
// }
// }
// if(count_buf>0){
// output << towrite;
// }
// output.close();
// }
};
}
#endif // DATA_STORE_H
...
...
Featurer/data/data_store_map.h
View file @
c206d3d
...
...
@@ -44,19 +44,21 @@ class Producer_map: public multithread::Buffer_producer<data::Data_basic*>{
protected
:
std
::
unordered_map
<
std
::
string
,
data
::
Data_basic
*>
data_map
;
void
add_internal
(
data
::
Data_basic
*
data
){
this
->
data_map
[
data
->
getName
()]
=
data
;
this
->
size
++
;
}
public
:
Data_Store_Map
(){}
Data_Store_Map
(
std
::
string
file_name
)
:
data
::
Data_Store
(
file_name
){}
~
Data_Store_Map
(){
//~data::Data_Store::~Data_Store();
for
(
auto
const
&
kv
:
this
->
data_map
){
delete
kv
.
second
;
}
}
void
add
(
data
::
Data_basic
*
data
){
this
->
data_map
[
data
->
getName
()]
=
data
;
this
->
size
++
;
}
multithread
::
Buffer
<
data
::
Data_basic
*>
*
get
(
std
::
string
pattern
){
Producer_map
*
tmp
=
new
Producer_map
(
&
(
this
->
data_map
),
pattern
);
tmp
->
start
();
...
...
Featurer/main.cpp
View file @
c206d3d
...
...
@@ -53,27 +53,30 @@ int main(int argc, char* argv[])
/* ************** KMER ******************/
feature
::
Feature_callable
*
kmer
=
static_cast
<
feature
::
Feature_callable
*>
(
feature
::
Kmer
::
get_callable
(
3
));
tmp_ds
=
new
data
::
Data_Store_Map
();
ds
[
"KMER"
+
std
::
to_string
(
3
)]
=
tmp_ds
;
// tmp_ds = new data::Data_Store_Map();
tmp_ds
=
new
data
::
Data_Store_Map
(
output
+
"KMER3.txt"
);
ds
[
"KMER3"
]
=
tmp_ds
;
create_feature_maker
(
kmer
,
feature
::
Kmer
::
TYPE
+
std
::
to_string
(
6
),
tmp_ds
,
&
re
);
kmer
=
static_cast
<
feature
::
Feature_callable
*>
(
feature
::
Kmer
::
get_callable
(
6
));
tmp_ds
=
new
data
::
Data_Store_Map
();
ds
[
"KMER
"
+
std
::
to_string
(
6
)
]
=
tmp_ds
;
tmp_ds
=
new
data
::
Data_Store_Map
(
output
+
"KMER6.txt"
);
ds
[
"KMER
6"
]
=
tmp_ds
;
create_feature_maker
(
kmer
,
feature
::
Kmer
::
TYPE
+
std
::
to_string
(
6
),
tmp_ds
,
&
re
);
/* *********** ORF *********************/
/* ORF callable */
feature
::
Feature_callable
*
orf
=
static_cast
<
feature
::
Feature_callable
*>
(
feature
::
ORF
::
get_callable
());
tmp_ds
=
new
data
::
Data_Store_Map
();
// tmp_ds = new data::Data_Store_Map();
tmp_ds
=
new
data
::
Data_Store_Map
(
output
+
"ORF.txt"
);
ds
[
"ORF"
]
=
tmp_ds
;
create_feature_maker
(
orf
,
feature
::
ORF
::
TYPE
,
tmp_ds
,
&
re
);
/* *********** Codon Position ***************/
feature
::
Feature_callable
*
cp
=
static_cast
<
feature
::
Feature_callable
*>
(
feature
::
CodonPosition
::
get_callable
());
tmp_ds
=
new
data
::
Data_Store_Map
();
// tmp_ds = new data::Data_Store_Map();
tmp_ds
=
new
data
::
Data_Store_Map
(
output
+
"CP.txt"
);
ds
[
"CP"
]
=
tmp_ds
;
create_feature_maker
(
cp
,
feature
::
CodonPosition
::
TYPE
,
tmp_ds
,
&
re
);
...
...
@@ -105,8 +108,8 @@ int main(int argc, char* argv[])
auto
it
=
ds
.
begin
();
while
(
it
!=
ds
.
end
()){
it
->
second
->
write
(
output
+
it
->
first
+
".txt"
,
".*"
);
std
::
cout
<<
"File "
<<
output
+
it
->
first
+
".txt"
<<
" writted"
<<
std
::
endl
;
//
it->second->write(output+it->first+".txt",".*");
//
std::cout << "File " << output+it->first+".txt" << " writted" << std::endl;
delete
it
->
second
;
++
it
;
}
...
...
Please
register
or
login
to post a comment