Protein text to csv?

34 views
Skip to first unread message

Stephen Taylor

unread,
Jul 24, 2020, 12:36:44 PM7/24/20
to BBEdit Talk
Hi, first time poster but long-time BBEdit user. I have a text file of a protein, which I'd like to convert to csv by inserting a comma between each character, like so:

MADEEKLP  -> M,A,D,E,E,K,L,P, ...

And some lines (for secondary structure) have lots of spaces:

  S     TTEEEEE ->  , , S, , , ,T,T,E,E,E,E, ...

Is there a way to do this in BBEdit? I hacked together a simple javascript to do it, but then I have to run that as a local webpage; it would be great just to do it within BBEdit. Sorry if this is a dumb question, and thanks for any responses!

Jan Erik Moström

unread,
Jul 24, 2020, 12:46:34 PM7/24/20
to BBEdit Talk
On 24 Jul 2020, at 18:36, Stephen Taylor wrote:

> Hi, first time poster but long-time BBEdit user. I have a text file of
> a protein, which I'd like to convert to csv by inserting a comma
> between each character, like so:


Find pattern: (.)
Replace pattern: \1,

Done (if I understood you correctly)

This makes
MADE EKLP
become
M,A,D,E, , , , , ,E,K,L,P,

= jem

Bruce Van Allen

unread,
Jul 24, 2020, 12:48:37 PM7/24/20
to bbe...@googlegroups.com
On 7/24/20 at 9:36 AM, stephen...@gmail.com (Stephen Taylor) wrote:

>Is there a way to do this in BBEdit? I hacked together a simple
>javascript to do it, but then I have to run that as a local webpage;

>MADEEKLP -> M,A,D,E,E,K,L,P, ...


Looks like a fairly simple thing to do with Find/Replace, e.g.,

Find:
([A-Z])

Replace:
\1,

[A-Z] matches a single upper case ascii letter.
The parens capture that matched letter.
The \1 in the replacement is that captured value (the first one,
and in this case the only captured value).

This will do most of your work, although you might not want the
comma at the very end after the the very last letter. And there
might be other edge cases.

If your JS script works well, note that BBEdit can run scripts
written with Apple's script editor, and - unknown to many -
Apple's Script Editor accepts scripts written in javascript as
well as those written in AppleScript. So you might want to check
that out. A script can often be more versatile and robust than
using find/replace.

HTH
--

- Bruce

_bruce__van_allen__santa_cruz__ca_

Stephen Taylor

unread,
Jul 24, 2020, 12:56:20 PM7/24/20
to BBEdit Talk
Perfect, this has been driving me crazy for months! Thanks so much!

Bucky Junior

unread,
Jul 24, 2020, 1:07:07 PM7/24/20
to BBEdit Talk
It seems to me to be a simple regex (Regular Expressions) search and
replace with BBEdit’s Find.
First you want to look for upper-case letters A-Z or a space. That would be
[A-Z ] note the space after Z.

Then you want to capture that for later use.
([A-Z ])

Replace it with \1 and a comma
\1,

Turn on Grep and Replace All.
Someone can correct me if I'm wrong.
Bucky
Screen Shot 2020-07-24 at 10.46.09 AM.png
Reply all
Reply to author
Forward
0 new messages