+ Reply to Thread
Results 1 to 6 of 6

Excel for DNA Sequencing analysis - how can I find a string of text within a large string?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-11-2015
    Location
    NC
    MS-Off Ver
    MAC Office 2010
    Posts
    2

    Excel for DNA Sequencing analysis - how can I find a string of text within a large string?

    A TGCTGTGTTGTGGATGAATTAGATGCAG
    B GCAGATCTCAAAAGAAGGAGTACTCCGAA

    1 TGCTGTGTTGTGGATGAATTAGATGCAGATCTCAAAAGAAGGAGTACTCCGAA
    2 TGCTGTGTTGTGGATGAATTAGATCTCAAAAGAAGGAGTACTCCGAA
    3 TGCTGTGTTGTGGATGAATTAGTCAAAAGAAGGAGTACTCCGAA
    4 TGCTGTGTTGTGGATCTCAAAAGAAGGAGTACTCCGAA
    5 TGCTGTGTTGTGGATGAATTAGATGCATCTCAAAAGAAGGAGTACTCCGAA
    6 TGCTGTGTTGTGGATGAAGGAGTACTCCGAA
    7 TGCTGTGTTGTGGATGAATTAGAAGGAGTACTCCGAA
    8 TGCTGTGTTGTGGATGATCTCAAAAGAAGGAGTACTCCGAA
    9 TGCTGTGTTGTGGATGAA


    I want to find how much of Text String A is in Text String 1 starting from Left to Right. Then I want to find out how much of Text String B is in Text String 1 from right to left. So on and so forth for 1-9. Any ideas?
    Last edited by ledzep618; 02-11-2015 at 08:52 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Excel for DNA Sequencing analysis - how can I find a string of text within a large str

    I don't understand:

    When Text String A ends I want to find where Text String 1 it picks up in Text String B, also from left to right. So on and so forth for 1-9. Any ideas?
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    02-11-2015
    Location
    NC
    MS-Off Ver
    MAC Office 2010
    Posts
    2

    Re: Excel for DNA Sequencing analysis - how can I find a string of text within a large str

    Yeah that is poor wording on my part...so take the example of (1)

    You can see that the first 28 letters of (1) correspond to the entirety of (A) from L to R. Then you can also see that from R to L the entirety of (B) is in (1).

    In example (2) you can see that (2) contains the first 24 letters of (A) from L to R. Then from R to L (2) contains 26 letters of (B).

    This is probably confusing to read, but I need a high throughput way of identifying which parts of (A) and which parts of (B) are in each numbered text string.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Excel for DNA Sequencing analysis - how can I find a string of text within a large str

    Ok Try this.

    i wrote this as a starter.

    Sub macro1()
    For Acount = 2 To 3
    For BCount = 2 To 10
    
    MaxCount = 0
    MaxPos = 0
    A = Cells(Acount, 1).Value
    B = Cells(BCount, 3).Value
    
    For Offset = 0 To Len(B) - 1
    Counter = 0
    
    For Count = 1 To Len(A)
    T1 = Mid(A, Count, 1)
    t2 = Mid(B, Count + Offset, 1)
    If Mid(A, Count, 1) = Mid(B, Count + Offset, 1) Then Counter = Counter + 1
    Next
    
    If Counter > MaxCount Then MaxCount = Counter: MaxPos = Offset
    Next
    Cells(BCount, Acount * 2).Value = MaxCount
    Cells(BCount, Acount * 2 + 1).Value = MaxPos
    Next
    Next
    End Sub

    My outputs are in columns D & E and F & G easily expanded

    Column D gives you the max number of matches of the string in A1 in the strings in column C
    Column E tells you where the best Match Ocurred. I suppose I could switch all non matching text to lower case...........

    Column F gives you the max number of matches of the string in A2 in the strings in column C
    Column G tells you where the best Match Ocurred. I suppose I could switch all non matching text to lower case...........
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Excel for DNA Sequencing analysis - how can I find a string of text within a large str

    Ok This code is better as it colour codes your matches.

    Sub macro1()
    For Acount = 2 To 3
    For BCount = 2 To 10
    
    MaxCount = 0
    MaxPos = 0
    A = Cells(Acount, 1).Value
    B = Cells(BCount, 3).Value
    
    For Offset = 0 To Len(B) - 1
    Counter = 0
    
    For Count = 1 To Len(A)
    T1 = Mid(A, Count, 1)
    t2 = Mid(B, Count + Offset, 1)
    If Mid(A, Count, 1) = Mid(B, Count + Offset, 1) Then Counter = Counter + 1
    Next
    
    If Counter > MaxCount Then MaxCount = Counter: MaxPos = Offset
    Next
    Cells(BCount, Acount * 2).Value = MaxCount
    Cells(BCount, Acount * 2 + 1).Value = MaxPos + 1
    If Acount = 2 Then
    Cells(BCount, 3).Characters(MaxPos + 1, MaxCount).Font.Color = RGB(0, 0, 225)
    Else
    Cells(BCount, 3).Characters(MaxPos + 1, MaxCount).Font.Color = RGB(255, 0, 255)
    End If
    Next
    Next
    End Sub

  6. #6
    Forum Contributor
    Join Date
    07-29-2014
    Location
    Oz
    MS-Off Ver
    2010
    Posts
    142

    Re: Excel for DNA Sequencing analysis - how can I find a string of text within a large str

    I looked at a simple set of vba loops to do this, however, there is an issue where the end part of your "A" string is the same as the first part of your "B". Therefore it is not possible to discern whether you are finding the end of "A" or the start of "B". Are the examples you gave the actual strings, or are they made up examples?
    Dan
    Don't forget to ☆ me if I helped you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find a text in a String in Excel
    By swap_dj9 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-18-2013, 03:11 AM
  2. [SOLVED] Find and extract text string from within another text string
    By huy_le in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-12-2013, 03:22 PM
  3. Find and extract text string from within another text string
    By huy_le in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-09-2013, 09:01 PM
  4. [SOLVED] Find partial text string within another text string return original text into cell.
    By mikey42979 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-17-2013, 02:58 PM
  5. web and excel find text string...
    By sal21 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2006, 06:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1