Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'Functions calling for exactly Two Arguments' topicStudent Support Forum > General > Archives > "Functions calling for exactly Two Arguments"

Next Comment >Help | Reply To Topic
Author Comment/Response
Michael Senter
07/05/13 7:50pm

Some Mathematica functions call explicitly for two objects, not more or less; however, I want to run these functions over more than three objects.

For example, let's say I collect several genes of interest, and save them in FASTA format. I import them from one file; now I have a variable that contains a list of several proteins; i.e., I have a list of i elements, where each element a_i is a string:

list = ImportString[
Import["/Users/DMSenter/Desktop/GeneList.txt"], "FASTA"]

What I would like to do is find the longest common subsequences of all these strings. The perfect candidate for this seems to be Mathematica's LongestCommonSubsequence function. However, this function expects exactly two objects, in this format:

LongestCommonSubsequence[String 1, String 2]

If I just write:

The code fails to work. I then thought I could write a function that takes two strings and compares them and map it over:

csub[x___String, y___String] = LongestCommonSequence[x, y]
csub /@ list

However, this doesn't work because Map works it's way over each and every element separately. Obviously this fails because my function is expecting two objects, but only gets one from Map.

Is there a nice way to iterate over my list of strings and find the longest common sequence in all of them rather than having to call a function for each two individually, and then compare those in pairs, etc.?

Maybe something as in

For i in list
string = LongestCommonSequence[i, i+]

or so?

URL: ,

Subject (listing for 'Functions calling for exactly Two Arguments')
Author Date Posted
Functions calling for exactly Two Arguments Michael Senter 07/05/13 7:50pm
Re: Functions calling for exactly Two Arguments jf 07/06/13 6:49pm
Re: Re: Functions calling for exactly Two Argum... Peter Pein 07/07/13 06:21am
Next Comment >Help | Reply To Topic