I think I would solve it like this (with intermediate steps):

x=: 'case_id', LF, 'GCTAGTCG', LF, 'ACGTC', LF

NB. Find the locations of LF's in the string
(LF = ]) x

NB. assign 0 to everything before the LF, assign 1 to everything after it
([: +./\  LF = ]) x

NB. The wonderful "key" adverb lets you apply verbs based on it's key
(another array), eg. box
(</.~ [: +./\ LF =]) x

NB. Get rid of the LF's by replacing < by a version removing LF:
((<@#~ LF~:])/.~ [: +./\ LF = ]) x

This is what I came up with, but smarter people will probably suggest more
elegant ways.

I hope this is useful.
Jan-Pieter

2014-11-25 11:00 GMT+01:00 Ryan <[email protected]>:

> I have a character array with LF's, and want to split it on the
> first LF, and remove the remaining LF's.  I'm wondering if there's a
> simpler
> way than what I'm doing now:
>
> x=: 'case_id', LF, 'GCTAGTCG', LF, 'ACGTC', LF
>
> filterLF=: #~ ~:&LF
> headLF=: {.~ i.&LF
> tailLF=: }.~ i.&LF
> (headLF ; filterLF@tailLF) x
> ┌────────┬─────────────┐
> │>case_id│GCTAGTCGACGTC│
> └────────┴─────────────┘
>
> (I'm reading text files in fasta format: http://rosalind.info/glossary/
> fasta-format/)
>
> Thanks for any suggestions,
> Ryan
>
>
>
> The information in this e-mail is intended only for the person to whom it
> is
> addressed. If you believe this e-mail was sent to you in error and the
> e-mail
> contains patient information, please contact the Partners Compliance
> HelpLine at
> http://www.partners.org/complianceline . If the e-mail was sent to you in
> error
> but does not contain patient information, please contact the sender and
> properly
> dispose of the e-mail.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to