PC Review


Reply
Thread Tools Rate Thread

Count consecutive characters within a cell

 
 
=?Utf-8?B?SnNoZW5kZWw=?=
Guest
Posts: n/a
 
      21st Sep 2007
I have a genetic sequence such as:
AATTCAGTTACTTTTGCA

I need a formula that will tell me if this cell has a run of 4 or more
consecutive letters. The run can consist of 4 or more A, T, C, or G.

The above example can return simply as "yes" or can be as complex as "this
cell has 4 consecutive T's"

Thanks,
Josh
 
Reply With Quote
 
 
 
 
JE McGimpsey
Guest
Posts: n/a
 
      21st Sep 2007
One way, using a User Define Function:

Public Function XOrMore( _
ByVal sTest As String, _
ByVal X As Long) As Boolean
Dim nCount As Long
Dim i As Long
For i = 2 To Len(sTest)
If Mid(sTest, i - 1, 1) = Mid(sTest, i, 1) Then
nCount = nCount + 1
If nCount = X - 1 Then Exit For
Else
nCount = 0
End If
Next i
XOrMore = nCount = X - 1
End Function

Call as =XorMore(A1, 4)

if you're not familiar with UDFs, see

http://www.mvps.org/dmcritchie/excel/getstarted.htm

In article <70219DEF-DCF8-41B7-B6C4-(E-Mail Removed)>,
Jshendel <(E-Mail Removed)> wrote:

> I have a genetic sequence such as:
> AATTCAGTTACTTTTGCA
>
> I need a formula that will tell me if this cell has a run of 4 or more
> consecutive letters. The run can consist of 4 or more A, T, C, or G.
>
> The above example can return simply as "yes" or can be as complex as "this
> cell has 4 consecutive T's"
>
> Thanks,
> Josh

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      21st Sep 2007
How about just True or False

=LEN(A1)<>LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(
SUBSTITUTE(UPPER(A1),"GGGG",""),"AAAA",""),"TTTT",""),"CCCC",""))

Or

=TRIM(
IF(LEN(A1)=LEN(SUBSTITUTE(UPPER(A1),"GGGG",""))," ","Consecutive G's ")
&IF(LEN(A1)=LEN(SUBSTITUTE(UPPER(A1),"AAAA",""))," ","Consecutive A's ")
&IF(LEN(A1)=LEN(SUBSTITUTE(UPPER(A1),"TTTT",""))," ","Consecutive T's ")
&IF(LEN(A1)=LEN(SUBSTITUTE(UPPER(A1),"CCCC",""))," ","Consecutive C's "))





Jshendel wrote:
>
> I have a genetic sequence such as:
> AATTCAGTTACTTTTGCA
>
> I need a formula that will tell me if this cell has a run of 4 or more
> consecutive letters. The run can consist of 4 or more A, T, C, or G.
>
> The above example can return simply as "yes" or can be as complex as "this
> cell has 4 consecutive T's"
>
> Thanks,
> Josh


--

Dave Peterson
 
Reply With Quote
 
PCLIVE
Guest
Posts: n/a
 
      21st Sep 2007
Here's one way:

=IF(OR(LEN(SUBSTITUTE($A1,REPT(E1,4),""))<LEN(A1),(LEN(SUBSTITUTE($A1,REPT(F1,4),""))<LEN(A1)),(LEN(SUBSTITUTE($A1,REPT(G1,4),""))<LEN(A1)),(LEN(SUBSTITUTE($A1,REPT(H1,4),""))<LEN(A1))),"Yes","No")

Cells E1,F1,G1 and H1 represent the letters that you want to test against 4
consecutive.
E1= A
F1=T
G1=C
H1=G

HTH,
Paul


--

"Jshendel" <(E-Mail Removed)> wrote in message
news:70219DEF-DCF8-41B7-B6C4-(E-Mail Removed)...
>I have a genetic sequence such as:
> AATTCAGTTACTTTTGCA
>
> I need a formula that will tell me if this cell has a run of 4 or more
> consecutive letters. The run can consist of 4 or more A, T, C, or G.
>
> The above example can return simply as "yes" or can be as complex as "this
> cell has 4 consecutive T's"
>
> Thanks,
> Josh



 
Reply With Quote
 
=?Utf-8?B?SnNoZW5kZWw=?=
Guest
Posts: n/a
 
      21st Sep 2007
I used your second equation. Works like a dream. Thanks!

"Dave Peterson" wrote:

> How about just True or False
>
> =LEN(A1)<>LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(
> SUBSTITUTE(UPPER(A1),"GGGG",""),"AAAA",""),"TTTT",""),"CCCC",""))
>
> Or
>
> =TRIM(
> IF(LEN(A1)=LEN(SUBSTITUTE(UPPER(A1),"GGGG",""))," ","Consecutive G's ")
> &IF(LEN(A1)=LEN(SUBSTITUTE(UPPER(A1),"AAAA",""))," ","Consecutive A's ")
> &IF(LEN(A1)=LEN(SUBSTITUTE(UPPER(A1),"TTTT",""))," ","Consecutive T's ")
> &IF(LEN(A1)=LEN(SUBSTITUTE(UPPER(A1),"CCCC",""))," ","Consecutive C's "))
>
>
>
>
>
> Jshendel wrote:
> >
> > I have a genetic sequence such as:
> > AATTCAGTTACTTTTGCA
> >
> > I need a formula that will tell me if this cell has a run of 4 or more
> > consecutive letters. The run can consist of 4 or more A, T, C, or G.
> >
> > The above example can return simply as "yes" or can be as complex as "this
> > cell has 4 consecutive T's"
> >
> > Thanks,
> > Josh

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
=?Utf-8?B?VGVldGhsZXNzIG1hbWE=?=
Guest
Posts: n/a
 
      21st Sep 2007
assume your data in A1

Create a lookup list
A5= AAAA
A6= CCCC
A7= GGGG
A8= TTTT

=IF(SUMPRODUCT(--(ISNUMBER(SEARCH(A5:A8,A1))))>0,"yes","no")


"Jshendel" wrote:

> I have a genetic sequence such as:
> AATTCAGTTACTTTTGCA
>
> I need a formula that will tell me if this cell has a run of 4 or more
> consecutive letters. The run can consist of 4 or more A, T, C, or G.
>
> The above example can return simply as "yes" or can be as complex as "this
> cell has 4 consecutive T's"
>
> Thanks,
> Josh

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I count the Characters in a cell Woozy Microsoft Excel Misc 5 8th Jan 2009 08:26 AM
Count of Characters in a Cell Michelle Microsoft Access 3 29th Aug 2008 08:28 PM
Count Characters in a cell tracktor Microsoft Excel Misc 8 21st May 2008 03:02 AM
Count # of characters in cell loscherland Microsoft Excel Misc 3 22nd Nov 2004 05:46 PM
count how many characters in a cell? SS Microsoft Excel Programming 5 10th Dec 2003 06:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:12 AM.