SWISS::TextFunc(3pm)
π NAME π
SWISS::TextFunc β it's a Perl module, bestie, and it lives over in the User Contributed Perl Documentation corner of the world π¦
πΈ DESCRIPTION πΈ
okay so picture this: you're parsing and formatting SWISS-PROT / TREMBL lines, and you keep writing the same little helper function over and over like a clown π. That's literally what this module is for. It's a repository of functions that get used again and again while parsing and formatting SWISS-PROT/TREMBL lines. The vibe check is basically: if more than two line types need to do approximately the same thing, it probably belongs in here. periodt π
Every single function expects to be called as package->function(param list) β that's the rule, no exceptions, slay β¨
π listFromText
Takes a piece of text, a seperator regex, and a seperator that may appear at the end. Returns an array of items that were seperated in the text by that seperator. It handles null items for you β by which we mean it looses them for you π«Ά (yes, the original says "looses", we're just the messenger).
π textFromList
Takes an array of items, a separator, a terminating string, and a line width. Returns an array of strings, each ending with the separator or the terminator, with a width less than or equal to the width you specified. iconic.
π¨ real talk though: it seems to do the wrong thing for references β not sure why. Don't use it for that. not me warning you π
π wrapText
Takes a string and a length. Returns an array of strings which are shorter or equal in length to length, spliting the string on white space. (Original spelling, we keep it, we don't touch it π )
π wrapOn ($firstLinePrefix, $linePrefix, $colums, $text[, @separators])
Wraps $text into lines with at most $colums colums. Prepends the prefixes to the lines. @separators is a list of expressions on which to wrap. The expression itself is part of the upper line. π§
If no @separators are provided, the $text is wrapped at whitespace β except in EC/TC numbers, or at dashes that separate words. iykyk.
It first tries to wrap on the first item of @separators, then the next, etc. If no wrap on any element of @separators or whitespaces is possible, it wraps into lines of exactly length $colums. no cap.
A special case: the first item of @separators may be a reference to an array. This is used internally for wrapping FT VARIANT-like lines. π
Example:
wrapOn('DE ', 'DE ', 40,
'14-3-3 PROTEIN BETA/ALPHA (PROTEIN KINASE C INHIBITOR PROTEIN-1)',
'\s+')
returns ['14-3-3 PROTEIN BETA/ALPHA (PROTEIN ',
'KINASE C INHIBITOR PROTEIN-1)']
wrapOn('DE ', 'DE ', 40,
'14-3-3 PROTEIN BETA/ALPHA (PROTEIN KINASE C INHIBITOR PROTEIN-1)',
' (?=\()', '\s+')
returns ['14-3-3 PROTEIN BETA/ALPHA ',
'(PROTEIN KINASE C INHIBITOR PROTEIN-1)']
look at that second one go. we love a glow up β¨
π cleanLine
Remove the leading line Identifier and three blanks and trailing spaces from an SP line. little tidy-up moment π§Ήπ
π joinWith ($text, $with, $noAddAfter, @list)
Concatenates $text and @list into one string. Adds $with between the original elements β unless the postfix of the current string is $noAddAfter. This is used to avoid inserting blanks after hyphens during concatenation. So unpleasant strings like 'CALMODULIN-DEPENDENT' are avoided. Unfortunately, a correct reassembly of strings like 'CARBON-DIOXIDE' is not done. π the tradeoff is real.
π insertLineGroup ($textRef, $text, $pattern)
Inserts text block $text into the text referred to by $textRef. $text will replace the text block in $textRef matched by $pattern. boom, swapped π
π uniqueList (@list)
Returns a list in which all duplicates from @list have been removed. dedupe queen π
π currentSpDate
returns the current date in SWISS-PROT format ποΈβ¨
π toMixedCase($text, @regexps)
Convert a text to mixed case, according to one or more regular expressions. In scalar context, returns the new text; in array context, also returns the regexp with which the change was performed, or undef on failure. See the corresponding item in SWISS::GN for more details. fr fr go read that one too π«Ά
and that's the whole page bestie!! π this little icon was brought to you by perl v5.32.1, dated 2021-08-15, and it's still serving looks in SWISS::TextFunc(3pm). mwah ππ
π¦ 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