SWISS::ListBase(3pm)
β¨ SWISS::ListBase β¨
okay bestie, gather round, because this is SWISS::ListBase.pm from the User Contributed Perl Documentation collection and it is literally the blueprint π
π Name π
SWISS::ListBase.pm β the base class of the SWISS:: universe, and yes she's the mother of all list-oriented classes, no cap π
πΈ Description πΈ
So basically: this is the base class for list oriented classes in the SWISS:: hierarchy. She hands down a whole set of quite general list manipulation methods to all the inheriting classes. Think of her as the cool older sister who already did the homework and lets the subclasses copy her notes π«Ά
π¦ Attributes π¦
listβ holds an array, and that array is the essential content of the object. and plot twist: the array elements can be β and, fr fr, frequently are β arrays themselves. arrays all the way down bestie π
π Methods π
β Standard methods β
newinitialize
π Reading methods π
headβ returns the first element of the list. she's the front of the line πtailβ returns all but the first element of the list. bye first element, everybody else stays β¨get patternβ returns a list of all elements matched by$pattern. Only exact matches are returned, but you can absolutely use Perl's regular expressions to pop off. Example:
$listBaseObject->set('EMBL', 'TREMBL', 'SWISSPROT');
$listBaseObject->get('.*EMBL');
returns ('EMBL', 'TREMBL')
get @patternListβ use this one when the ListBase elements are themselves arrays. An array gets returned if all its elements are matched exactly by the elements from@patternListwith the same index. And listen: empty elements in@patternListalways match, every single time. Example:
$listBaseObject->set(['EMBL', 'M1', 'G1', '-'],
['EMBL', 'M2', 'A2', '-'],
['EMBL', 'M2', 'G3', 'ALT_TERM'],
['PROSITE', 'P00001', '1433_2', '1']);
$listBaseObject->get('EMBL');
returns (['EMBL', 'M1', 'G1', '-'],
['EMBL', 'M2', 'A2', '-'],
['EMBL', 'M2', 'G3', 'ALT_TERM'])
$listBaseObject->get('',M2);
returns (['EMBL', 'M2', 'A2', '-'],
['EMBL', 'M2', 'G3', 'ALT_TERM']);
ngl, offering get in the interface is not particularly nice, because it exports implementation details straight into the interface π but it is a powerful method that may save you a lot of programming time. As an alternative, the 'filter' concept is available. choices, bestie β¨
getObject patterngetObject @patternListβ same asget, but returns the results wrapped up cozy in a new ListBase object πfilterβ returns a new object containing all of the elements that match a search criteria. It takes a function as the only parameter. That function should expect a list element, and return true or false depending on whether the element matches the criteria. And here's the iconic part: if the object is not a ListBase object but a member of a subclass, a new object of that subclass will be returned. periodt π
Example:
$tmp = $entry->CCs->filter(&ccTopic('FUNCTION'));
returns a SWISS::CCs object containing all CC blocks from $entry which have the topic 'FUNCTION'.
Functions can also be anonymous functions, if you're feeling mysterious π§
attributeEquals(string attributeName, string attributeValue)β a filter function. If the elements of a ListBase object are objects, they will be returned by this function if they have the attribute and it equals theattributeValue.
Example:
$matchedKWs =
$entry->KWs->filter(SWISS::ListBase::attributeEquals('text', $kw));
attributeMatchedBy(string attributeName, string pattern)β a filter function. If the elements of a ListBase object are objects, they will be returned by this function if they have the attribute and the attribute is matched by the pattern.
Example:
$matchedKWs =
$entry->KWs->filter(SWISS::ListBase::attributeMatchedBy('text',
$kw));
isEmptysizeβ the number of list elements in the object. she counts. she's an icon πelementsβ returns the array of elementshasEvidenceTag $arrayPointer $tagβ returns true if the array pointed to by$arrayPointerhas the evidence tag$taggetEvidenceTags $arrayPointerβ returns the array of evidence tags of$arrayPointergetEvidenceTagsString $arrayPointerβ returns a string containing the evidence tags of$arrayPointer
π Writing methods π
item offset[, newValue]β returns the list element at a specific offset, and optionally sets it to a new value. Negative offsets are relative to the end of the list, so you can vibe backwards πpush listpopshiftunshift listsplice [offset[, length[, list]]]set listβ sets the list attribute to@listadd listβ synonym forpushmerge (ListBase)β appends the elements of ListBase to the object. friendship bracelet behaviour π«Άsort [function]β applies a sort function to the list attribute, or by default, alphabetical sorting. Should be overwritten in derived classes with an adapted sort function. so like, do better in your subclass bestie πdel patternβ deletes all items fully matching$pattern. Example:
$listBaseObject->set('EMBL','TREMBL', 'SWISSPROT');
$listBaseObject->del('EMBL');
$listBaseObject->list();
returns ('TREMBL','SWISSPROT').
If you want to delete more, use something like
$listBaseObject->del('.*EMBL')
which deletes 'EMBL' and 'TREMBL'. one regex, two victims, slay β¨
del @patternListβ to be used if the ListBase objects are arrays. An array is deleted if all its elements are matched by the elements from@patternListwith the same index.
β οΈ Warning: Empty elements in @patternList always match! like, always. be careful bestie π
Using the data from the get example above,
$listBaseObject->del('','', 'A2')
results in
(['EMBL', 'M1', 'G1', '-'],
['EMBL', 'M2', 'G3', 'ALT_TERM'],
['PROSITE', 'P00001', '1433_2', '1'])
updateuniqueβ makes sure each element is contained only once in a ListBase object. The second and subsequent occurrences of the same object are deleted. Example:
$listBaseObject->set(EMBL, TREMBL, SWISSPROT);
$listBaseObject->add(EMBL, MGD, EMBL);
$listBaseObject->unique();
results in (EMBL, TREMBL, SWISSPROT, MGD) β deduplicated and thriving π
setEvidenceTags $arrayPointer @arrayβ sets the evidence Tags of the array pointed to by$arrayPointerto the contents of@array.
To be used if the ListBase elements are themselves arrays. A typical construct would be
foreach $dr ($entry->DRs->elements()) {
$entry->DRs->setEvidenceTags($dr, 'E2', 'E3');
}
Returns $arrayPointer.
addEvidenceTag $arrayPointer $tagβ adds$tagto the evidence tags of$arrayPointer.
To be used if the ListBase elements are themselves arrays. See documentation of setEvidenceTags.
Returns $arrayPointer.
deleteEvidenceTags $arrayPointer $evidenceTagβ deletes$evidenceTagfrom the array pointed to by$arrayPointer.
To be used if the ListBase elements are themselves arrays. A typical construct would be
foreach $dr ($entry->DRs->elements()) {
$entry->DRs->deleteEvidenceTags($dr, 'EC2');
}
Returns $arrayPointer.
and that's the whole page bestie, we ate and left no crumbs π½οΈβ¨ this lil legend ships with perl v5.32.1, dated 2021-08-15, and yes the name <pink>SWISS::ListBase(3pm)</pink> is serving exactly what it needs to serve π
mwah, go forth and manipulate those lists π¦
π¦ where this page comes from
- debian bookworm: libswiss-perl 1.80-1 Β· GPL-2.0-or-later
- debian trixie: libswiss-perl 1.80-1 Β· GPL-2.0-or-later
- ubuntu jammy: libswiss-perl 1.80-1 Β· GPL-2.0-or-later
- ubuntu noble: libswiss-perl 1.80-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms