annotate tools/rdock/lib/SDRecord.pm @ 0:bc03dbb6eb37 draft

planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
author marpiech
date Mon, 29 Aug 2016 03:38:13 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
1 package SDRecord;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
2 # Perl module for reading/writing SD records from/to STDIN/STDOUT
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
3 # Methods: new
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
4 # readRec
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
5 # writeRec
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
6 # writeData
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
7 # copy
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
8 # addData
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
9 #
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
10 # Data: LINES - reference to array of record text lines
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
11 # DATA - reference to hash array of record data fields
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
12 # DATAREF - reference to hash array of line numbers for data fields
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
13
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
14 my $LINES = 'LINES';
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
15 my $DATA = 'DATA';
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
16 #DM 27 Sept 1999 - also store line number of beginning each data field
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
17 #so we can extract multi-line fields more easily from the LINES array
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
18 my $DATAREF = 'DATAREF';
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
19
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
20 ############################################################
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
21 # Constructor
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
22 sub new {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
23 my $this = {};
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
24 bless $this;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
25 return $this;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
26 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
27
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
28 ############################################################
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
29 # readRec() - read next SD record from STDIN
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
30 # Input params:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
31 # 'LINES' => any value - save lines
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
32 # 'DATA' => any value - save data
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
33 sub readRec {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
34 my $this = shift;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
35 my %params = @_;#input parameters
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
36 my @lines;#array for storing all text lines
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
37 my %data;#hash array for storing all data key,value pairs
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
38 my %dataref;#hash array for storing line number references for each data field
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
39 my ($fieldName,$ob,$cb);
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
40
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
41 #clear current data
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
42 delete $this->{$LINES};
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
43 delete $this->{$DATA};
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
44 delete $this->{$DATAREF};
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
45
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
46 #read lines from STDIN to the next record delimiter
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
47 #store in @lines array
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
48 #DM 16 Nov 1999 - can now cope with DOS text files directly
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
49 $/ = "\n";#Default Unix line separator
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
50 while (<>) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
51 chomp;#Get rid of Unix line separator
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
52 $/ = "\r";
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
53 chomp;#Get rid of DOS line separator
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
54 $/ = "\n";#Reset to normal Unix
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
55 last if ($_ eq '$$$$');#end of record
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
56 push @lines,$_;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
57 #print "$_\n";
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
58 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
59
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
60 #check if we read anything
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
61 if (scalar(@lines) > 0) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
62 #store ref to @lines if required
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
63 $this->{$LINES} = \@lines if (defined $params{$LINES});
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
64 #search for data fields if required
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
65 if (defined $params{$DATA}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
66 $fieldName = '';
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
67 my $lineNum = 0;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
68 foreach $line (@lines) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
69 $lineNum++;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
70 #DM 12 Jul 1999 - include the first three title lines as
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
71 #pseudo data fields
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
72 if ($lineNum <= 3) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
73 $data{"_TITLE$lineNum"} = $line;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
74 #DM 20 Dec 1999 - include dimensionality (2D/3D) as pseudo data field
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
75 if ($lineNum == 2) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
76 $data{"_NDIM"} = substr($line,20,1);
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
77 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
78 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
79 #DM 05 Aug 1999 - include number of atoms as pseudo data field
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
80 elsif ($lineNum == 4) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
81 my @fields = split(" ",$line);
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
82 $data{"_NATOMS"} = $fields[0] if (scalar(@fields)>0);
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
83 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
84 if (index($line,'>') == 0) {#found a data field
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
85 $ob = index($line,'<');#first open bracket
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
86 $cb = rindex($line,'>');#last close bracket
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
87 if (($ob != -1) && ($cb != -1)) { #save field name
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
88 $fieldName = substr($line,$ob+1,$cb-$ob-1);
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
89 $dataref{$fieldName} = $lineNum-1;#store ref to line number
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
90 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
91 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
92 #if field name defined, then store first line of value
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
93 elsif ($fieldName ne '') {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
94 $data{$fieldName} = $line;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
95 $fieldName = '';#clear field name
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
96 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
97 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
98 #store ref to %data in $this
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
99 $this->{$DATA} = \%data;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
100 $this->{$DATAREF} = \%dataref;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
101 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
102 return 1;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
103 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
104 else {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
105 return 0;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
106 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
107 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
108
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
109 ############################################################
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
110 # writeRec() - write current record to STDOUT (mol + data)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
111 sub writeRec {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
112 my $this = shift;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
113 if (defined $this->{$LINES}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
114 foreach $line (@{$this->{$LINES}}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
115 print "$line\n";
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
116 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
117 print "\$\$\$\$\n";
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
118 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
119 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
120
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
121 ############################################################
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
122 # writeMol() - write current mol record to STDOUT
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
123 sub writeMol {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
124 my $this = shift;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
125 if (defined $this->{$LINES}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
126 foreach $line (@{$this->{$LINES}}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
127 print "$line\n";
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
128 last if ($line eq "M END");
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
129 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
130 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
131 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
132
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
133 ############################################################
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
134 # writeData() - list data field/values to STDOUT
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
135 sub writeData {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
136 my $this = shift;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
137 my ($keys ,$value, $lineNum );
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
138 if (defined $this->{$DATA}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
139 foreach $key (sort keys %{$this->{$DATA}}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
140 $value = $this->{$DATA}->{$key};
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
141 $lineNum = $this->{$DATAREF}->{$key};
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
142 #print "$key eq $value (line $lineNum)\n";
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
143 print "\$$key eq \"$value\"\n";
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
144 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
145 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
146 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
147
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
148 ############################################################
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
149 # copy() - create deep copy of SDRecord
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
150 # Input params:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
151 # 'LINES' = any value - deep copy of lines
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
152 # 'DATA' = any value - deep copy of data and dataref
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
153
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
154 sub copy {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
155 my $this = shift;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
156 my %params = @_;#input parameters
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
157 my $clone = new SDRecord;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
158 if ((defined $params{$LINES}) && (defined $this->{$LINES})) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
159 my @lines = @{$this->{$LINES}};
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
160 $clone->{$LINES} = \@lines;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
161 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
162 if (defined $params{$DATA}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
163 if (defined $this->{$DATA}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
164 my %data = %{$this->{$DATA}};
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
165 $clone->{$DATA} = \%data;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
166 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
167 # DM 24 Jul 2001 - DATAREF was missing from deep copy
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
168 # We copy the dataref array using the same DATA input parameter
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
169 # i.e. if the data is copied then so is dataref
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
170 if (defined $this->{$DATAREF}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
171 my %dataref = %{$this->{$DATAREF}};
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
172 $clone->{$DATAREF} = \%dataref;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
173 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
174 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
175 return $clone;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
176 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
177
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
178 ############################################################
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
179 # addData() - adds data to data hash array
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
180 sub addData {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
181 my $this = shift;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
182 my %params = @_;#input parameters
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
183 #if the array is already defined then add to it
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
184 if (defined $this->{$DATA}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
185 my ($keys ,$value );
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
186 while (($key, $value) = each (%params)) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
187 $this->{$DATA}->{$key} = $value;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
188 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
189 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
190 #if not defined, then create it
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
191 else {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
192 $this->{$DATA} = \%params;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
193 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
194 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
195
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
196 ############################################################
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
197 # addDataAndLines() - adds data to data hash array,
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
198 # and adds corresponding lines also so that record may be
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
199 # rewritten with the new fields
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
200 sub addDataAndLines {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
201 my $this = shift;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
202 my %params = @_;#input parameters
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
203
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
204 while (($key, $value) = each (%params)) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
205 #DM 23 Oct 2000
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
206 #Check if data field already exists, if so replace value
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
207 #Note: this only works for single line data fields
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
208 if (defined $this->{$DATA}->{$key}) {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
209 my $keyRef = $this->{$DATAREF}->{$key};
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
210 ${$this->{$LINES}}[$keyRef+1] = $value;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
211 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
212 #else add the corresponding lines to the lines arrays
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
213 else {
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
214 my $keyRef = scalar(@{$this->{$LINES}});
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
215 $this->{$DATAREF}->{$key} = $keyRef;
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
216 push @{$this->{$LINES}},"> <$key>";
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
217 push @{$this->{$LINES}},"$value";
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
218 push @{$this->{$LINES}},"";
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
219 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
220 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
221
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
222 #DM 23 Oct 2000 - add data after adding the lines
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
223 $this->addData(%params);
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
224
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
225 }
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
226
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
227 1;