forked from solgenomics/yapri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
78 lines (52 loc) · 2.26 KB
/
README
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
YapRI, is "Yet another perl R interface" developed initially to work with
different blocks of commands.
It run the commands esentially as:
R [options] --file=inputcommandfile > outputresultfile
So the YapRI::Base module, create files, put them in a temp dir by default,
open these files, write the R commands to them, execute the files and
store all of them as variables in this object.
Here a synopsis of how works:
use YapRI::Base;
## WORKING WITH THE DEFAULT MODE:
my $rih = YapRI::Base->new();
$rih->add_command('bmp(filename="myfile.bmp", width=600, height=800)');
$rih->add_command('dev.list()');
$rih->add_command('plot(c(1, 5, 10), type = "l")');
$rih->add_command('dev.off()');
$rih->run_command();
my $result_file = $rih->get_resultfiles('default');
## WORKING WITH COMMAND BLOCKS:
my $rih = YapRI::Base->new();
## Create a file-block_1
$rih->add_cmdfile('BLOCK1');
$rih->add_command('x <- c(10, 9, 8, 5)', 'BLOCK1');
$rih->add_command('z <- c(12, 8, 8, 4)', 'BLOCK1');
$rih->add_command('x + z', 'BLOCK1')
## Create a file-block_2
$rih->add_cmdfile('BLOCK2');
$rih->add_command('bmp(filename="myfile.bmp", width=600, height=800)',
'BLOCK2');
$rih->add_command('dev.list()', 'BLOCK2');
$rih->add_command('plot(c(1, 5, 10), type = "l")', 'BLOCK2');
## Run each block
$rih->run_command({ alias => 'BLOCK1' });
$rih->run_command({ alias => 'BLOCK2' });
## Get the results
my $resultfile1 = $rih->get_resultfiles('BLOCK1');
my $resultfile2 = $rih->get_resultfiles('BLOCK2');
Example of a module that uses YapRI::Base, and YapRI::Data::Matrix to
calculate the transpose of the matrix
my $matrix = YapRI::Data::Matrix( {
name => 'matrix1',
rown => 3,
coln => 4,
` rownames => ['A', 'B', 'C'],
colnames => ['alpha', 'beta', 'gamma', 'delta'],
data => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
});
my $rih2 = YapRI::Base->new();
$matrix->send_rbase($rih2);
$rih2->create_block('TRMATRIX', $matrix->get_name());
$rih2->add_command('trmatrix1 <- t('.$matrix->get_name().')', 'TRMATRIX');
$rih2->run_block('TRMATRIX');
my $trmatrix = YapRI::Data::Matrix->read_rbase($rih2, 'TRMATRIX', 'trmatrix1');