Tstuart Posted May 13, 2013 Share Posted May 13, 2013 Hi, I'm new to alfred & am trying to make a simple workflow to reverse a string of letters and convert each letter to another letter (eg. convert A to T), then copy the output to the clipboard. I have a python script to do this, but I'm having trouble making it part of an alfred workflow. Here's the script: #reversecomplement def reverse(s): """Return the sequence string in reverse order.""" letters = list(s) letters.reverse() return ''.join(letters) def complement(s): """Return the complementary sequence string.""" basecomplement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A', 'a': 't', 'c': 'g', 't': 'a', 'g': 'c'} letters = list(s) letters = [basecomplement[base] for base in letters] return ''.join(letters) def rc(s): """Return the reverse complement of the dna string.""" s = reverse(s) s = complement(s) return s Disclaimer: I have very little experience in writing code. Thanks in advance for your help! Link to comment
jdfwarrior Posted May 14, 2013 Share Posted May 14, 2013 Hi, I'm new to alfred & am trying to make a simple workflow to reverse a string of letters and convert each letter to another letter (eg. convert A to T), then copy the output to the clipboard. I have a python script to do this, but I'm having trouble making it part of an alfred workflow. Here's the script: #reversecomplement def reverse(s): """Return the sequence string in reverse order.""" letters = list(s) letters.reverse() return ''.join(letters) def complement(s): """Return the complementary sequence string.""" basecomplement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A', 'a': 't', 'c': 'g', 't': 'a', 'g': 'c'} letters = list(s) letters = [basecomplement[base] for base in letters] return ''.join(letters) def rc(s): """Return the reverse complement of the dna string.""" s = reverse(s) s = complement(s) return s Disclaimer: I have very little experience in writing code. Thanks in advance for your help! To get this working in Alfred, you would create a new workflow using the Keyword to Script template. In the Run Script item, set the language to python, and drop your code in. You could grab the value of the user input by settings a variable to {query}. Then you could pass that value to any of your functions. When you get done, you would "print" your value. Add a Copy to Clipboard output item, connect it to the end of your Run Script. Then, in the Copy to Clipboard item, set the value to copy as {query}. The {query} placeholder is used when passing data from one item to another in workflows. Link to comment
Tstuart Posted May 14, 2013 Author Share Posted May 14, 2013 Thanks! It's working now Link to comment
Patrik Posted June 3, 2013 Share Posted June 3, 2013 (edited) Hi Tstuart, I have actually been trying to write a similar workflow in perl and could not get it to work for some reason, but have to admit that my programming skills are more non-existant than rusty, so it is really no surprise. I thought that it would be easy enough to implement David's suggestions with your script, but must be missing something, but as I said I have even less experience than you apparently, so it may be something quite basic. I had intended to get a bit more into some basic scripting, but don't really have the time at the moment. Would you mind posting your completed workflow, or at least the corrected code you are using? Thanks in advance! Edited June 3, 2013 by Patrik Link to comment
Tstuart Posted February 13, 2014 Author Share Posted February 13, 2014 Hi Tstuart, I have actually been trying to write a similar workflow in perl and could not get it to work for some reason, but have to admit that my programming skills are more non-existant than rusty, so it is really no surprise. I thought that it would be easy enough to implement David's suggestions with your script, but must be missing something, but as I said I have even less experience than you apparently, so it may be something quite basic. I had intended to get a bit more into some basic scripting, but don't really have the time at the moment. Would you mind posting your completed workflow, or at least the corrected code you are using? Thanks in advance! Hi Patrik, Sorry, I didn't see your comment until now. If you're still interested, I just posted my completed workflows here: http://www.alfredforum.com/topic/3894-biology-workflows-find-dna-sequence-information-and-convert-ng-dna-to-fmol/ Tim Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now