The ability to nest structured types within structured types provides the flexibility to keep your data organized in an intuitive, easily understood format. A good structured type will reflect the natural groupings suggested by the data and such an organization will reduce the number of errors, increase readability and make future changes much easier.
In our protein sequence example, the fields Name, DB and the accession number AC are in some sense related items of data since they specify an entry in a genomic database. As such, we might be motivated to grant them their own structured type GenomicDB nested within ProEntry.
ProEntry := proc( )
description
' Structured type to contain information about a protein sequence
Parameters:
Name, DB, AC, Organism, Sequence, Length
';
if ( nargs=0 ) then
temp := GenomicDB();
return(noeval(ProEntry(GenomicDB('', '', ''), '', '', -1)));
elif ( nargs=6 ) then
return(noeval(ProEntry(GenomicDB(args[1..3]), args[4..6])));
else
print( ProEntry );
error('Invalid ProEntry format');
fi;
end:
We define a structure of type ProEntry as before. Notice the
difference in how the information is stored internally.
> p := ProEntry('ABL1_CAEEL', 'SwissProt', 'P03949', 'C. ELEGANS',
> 'NNEWCEARLYSTRKNDASNQRRLGEIGWVPSNFIAPYNSLDK', 42);
protentry1 := ProEntry(GenomicDB(ABL1_CAEEL,SwissProt,P03949),
C. ELEGANS, NNEWCEARLYSTRKNDASNQRRLGEIGWVPSNFIAPYNSLDK,42)