SWISS::TextFunc(3pm)

πŸ“¦
version 1.80 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– 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