-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamplesheet.pm
More file actions
executable file
·189 lines (156 loc) · 3.33 KB
/
Copy pathsamplesheet.pm
File metadata and controls
executable file
·189 lines (156 loc) · 3.33 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package samplesheet;
use strict;
use warnings;
use Data::Dumper;
use File::Basename;
use File::Path qw(make_path);
use File::Spec::Functions;
use Switch;
##########@@@@@@@@@@@@@@@ CONSTRUCTOR @@@@@@@@@@@@@@@##########
sub new {
my ($class, $samplesheetfile) = @_;
my $self = {
file => $samplesheetfile,
dir => dirname($samplesheetfile),
project => basename(dirname($samplesheetfile))
};
bless $self, $class;
$self->_parse();
return $self;
}
##########@@@@@@@@@@@@@@@ INTERNAL METHODS @@@@@@@@@@@@@@@##########
sub _parse {
my ($self) = @_;
my $flag;
open IN, $self->{file};
while (<IN>) {
next if ($_ =~ /^$/);
next if ($_ =~ /^#/);
chomp;
if ($_ =~ /^\[Header\]/) {
$flag = 'header';
next;
}
elsif ($_ =~ /^\[Reads\]/) {
$flag = 'reads';
next;
}
elsif ($_ =~ /^\[Settings\]/) {
$flag = 'settings';
next;
}
elsif ($_ =~ /^\[Data\]/) {
$flag = 'data';
next;
}
if (! $flag ) {
return(1)
#something went wrong, quit
}
my @columns = split(",", $_);
switch($flag) {
case /header|settings/ {
$self->{$flag}->{$columns[0]} = $columns[1];
}
case 'reads' {
if (! $self->{reads}) {
push(@{$self->{reads}}, $columns[0]);
}
}
case 'data' {
## parse sample header
if ($_ =~ /^Sample_ID,Sample_Name,/ ) {
my $index = 0;
foreach my $hcolumn (split(",", $_)) {
$self->{hvalues}->{$index} = lc($hcolumn);
$self->{hcolumns}->{lc($hcolumn)} = $index;
$index++;
}
}
else {
my $index = 0;
foreach my $scolumn (split(",", $_)) {
if (! $index) {
$self->{currentsample} = $scolumn;
}
else {
## key value pair of header, value per column
$self->{samples}->{$self->{currentsample}}->{$self->{hvalues}->{$index}} = $scolumn;
}
$index++;
}
}
}
}
}
}
##########@@@@@@@@@@@@@@@ METHODS @@@@@@@@@@@@@@@##########
sub determineSeqtype {
my $self = shift;
if ($self->{project} =~ /^\d{6}_M/i) {
$self->{seqtype} = 'MiSeq';
return('MiSeq');
}
elsif ($self->{project} =~ /^\d{6}_N/i) {
$self->{seqtype} = 'NextSeq';
return('NextSeq');
}
}
sub getHeader {
my $self = shift;
return $self->{hcolumns};
}
sub getSampleDescription {
my ($self, $sample) = @_;
return($self->{samples}->{$sample}->{description});
}
sub getSampleDestination {
my ($self, $sample) = @_;
my @sample_project = split(/@/, $self->getSampleUD($sample));
if ($sample_project[1]) {
return $sample_project[1];
}
else {
return 0;
}
}
sub getSamples {
my ($self) = @_;
return keys %{$self->{samples}};
}
sub getSampleIndex {
my ($self, $sample) = @_;
return($self->{samples}->{$sample}->{'index'});
}
sub getSampleIndex2 {
my ($self, $sample) = @_;
return($self->{samples}->{$sample}->{'index2'});
}
sub getSampleInfo {
my ($self, $sample) = @_;
return($self->{samples}->{$sample});
}
sub getSampleUD {
my ($self, $sample) = @_;
return($self->{samples}->{$sample}->{'sample_project'});
}
sub getSampleUser {
my ($self, $sample) = @_;
my @sample_project = split(/@/, $self->getSampleUD($sample));
if ($sample_project[0]) {
return $sample_project[0];
}
else {
return 0;
}
}
sub print {
my ($self, $arg) = @_;
if (! $arg) {
print Dumper($self);
}
else {
print Dumper($arg);
}
}
1;