Skip to content

Commit

Permalink
Initial version, v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerfriendly committed Sep 29, 2014
1 parent 3aaeafa commit c4ef334
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"keys": ["ctrl+shift+r"],
"command": "reverse_complement"
}
]
6 changes: 6 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"keys": ["super+shift+r"],
"command": "reverse_complement"
}
]
6 changes: 6 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"keys": ["ctrl+shift+r"],
"command": "reverse_complement"
}
]
16 changes: 16 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"id": "edit",
"children": [
{
"caption": "Nucleotides",
"id": "nucleotides",
"children": [
{
"command": "reverse_complement"
}
]
}
]
}
]
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ACTG for SublimeText
====================

Nucleotide syntax highlighting and reverse complement support. This is handy for "stare at the screen and squint" DNA analysis.

Features
--------

* Choose 'Nucleotides' syntax highlighting to colorize ACTG and N.
* Automatically associates .fa, .fasta, .fq, .fastq, .sam, and .vcf files.
* Make a selection and hit Control-Shift-R (or Command-Shift-R on Mac) to replace it with the reverse complement.

Bugs
----

* ACTG and N are simply highlighted in place, which can make for some interestingly colored VCF comments and quality strings. A more clever regex would help, if only I could fathom the tmLanguage backreference match syntax.

Patches welcome.

Releases
--------

* 0.0.1: Initial release, 2014-09-29
40 changes: 40 additions & 0 deletions actg.JSON-tmLanguage
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "Nucleotides",
"scopeName": "source.nucleotides",
"fileTypes": [
"fq",
"fastq",
"fa",
"fasta",
"sam",
"vcf"
],
"patterns": [
{
"match": "A",
"name": "keyword.control.nucleotides",
"comment": "adenine"
},
{
"match": "C",
"name": "entity.name.function.nucleotides",
"comment": "cytosine"
},
{
"match": "T",
"name": "constant.numeric.source.nucleotides",
"comment": "thymine"
},
{
"match": "G",
"name": "string.quoted.source.nucleotides",
"comment": "guanine"
},
{
"match": "N",
"name": "comment.block.source.nucleotides",
"comment": "unknown"
}
],
"uuid": "34f308ec-03a9-428e-93dd-d8eae6648d7f"
}
57 changes: 57 additions & 0 deletions actg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'''
actg.py
Reverse complement plugin for Sublime Text 2
'''
import sublime, sublime_plugin

class ReverseComplementCommand(sublime_plugin.TextCommand):
def complement(self, sequence, reverse=False):
"""
Compute the complement of a DNA sequence.
If reverse is True, reverse it too.
"""
flip = {
'A': 'T',
'C': 'G',
'G': 'C',
'T': 'A',
'N': 'N',
'a': 't',
'c': 'g',
'g': 'c',
't': 'a',
'n': 'n'
}

complines = []

# Gracefully handle line endings
if '\n' in sequence:
postfix = '\n'
else:
postfix = ''

for line in sequence.split('\n'):
line_complement = []
for i in list(line):
if not i in flip:
sublime.error_message('Selection contains non-nucleotides.')
return False
line_complement.append(flip[i])

if reverse:
complines.append(''.join(line_complement[::-1]))
else:
complines.append(''.join(line_complement))

return postfix.join(complines)

def run(self, edit):
sels = self.view.sel()
for sel in sels:
if not sel.empty():
ret = self.complement(self.view.substr(sel), reverse=True)
if(ret):
self.view.replace(edit, sel, ret)
64 changes: 64 additions & 0 deletions actg.tmLanguage
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>fq</string>
<string>fastq</string>
<string>fa</string>
<string>fasta</string>
<string>sam</string>
<string>vcf</string>
</array>
<key>name</key>
<string>Nucleotides</string>
<key>patterns</key>
<array>
<dict>
<key>comment</key>
<string>adenine</string>
<key>match</key>
<string>A</string>
<key>name</key>
<string>keyword.control.nucleotides</string>
</dict>
<dict>
<key>comment</key>
<string>cytosine</string>
<key>match</key>
<string>C</string>
<key>name</key>
<string>entity.name.function.nucleotides</string>
</dict>
<dict>
<key>comment</key>
<string>thymine</string>
<key>match</key>
<string>T</string>
<key>name</key>
<string>constant.numeric.source.nucleotides</string>
</dict>
<dict>
<key>comment</key>
<string>guanine</string>
<key>match</key>
<string>G</string>
<key>name</key>
<string>string.quoted.source.nucleotides</string>
</dict>
<dict>
<key>comment</key>
<string>unknown</string>
<key>match</key>
<string>N</string>
<key>name</key>
<string>comment.block.source.nucleotides</string>
</dict>
</array>
<key>scopeName</key>
<string>source.nucleotides</string>
<key>uuid</key>
<string>34f308ec-03a9-428e-93dd-d8eae6648d7f</string>
</dict>
</plist>

0 comments on commit c4ef334

Please sign in to comment.