[Biococoa-dev] New goodies - BCStandaloneReader

Hi guys,
Long time, no activity unfortunately. Still there is some news. The
last two weeks I've used my (very) few spare hours to fulfil some
long standing promises, and updated our programs to bring them at
least on par with OSX Tiger. For instance, we were so optimistic
(read: stupid) to write on our website that we would release new
versions of both EnzymeX and iRNAi "soon". That was 2 years ago ;-)
Anyway, they're finished now (iRNAi 2 released today and EnzymeX 3
finishing up). In both of them I used some of Peter's "old" BioCocoa
code to allow reading of most common sequence file formats, and I
would like to share that with you guys. Perhaps Peter can give it a
place on the BioCocoa CVS/SVN or post it on the BioCocoa webpage.
I made a standalone version of the BCReader code, so that adding
these 4 files is sufficient to add reading of all of the following
formats to your app for free:
- BEAST,
- Clustal
- DNA Strider
- EMBL
- Fasta
- GCG-MSF
- GCK (Gene Construction Kit)
- GDE
- Hennig86
- NCBI
- NEXUS
- NONA
- PDB
- Phylip
- PIR
- Plain/Raw
- Swiss-Prot
- TNT
As you can see I've added the binary formats DNAStrider and Gene
Construction Kit files (the latter using a bit of (very simple)
reverse engineering ;-)
Below is a snippet from iRNAi that shows you how to read a sequence
file:
- (IBAction)importSequence:(id)sender{
NSOpenPanel * oPanel = [NSOpenPanel openPanel];
[oPanel setAllowsMultipleSelection:NO];
[oPanel setResolvesAliases: YES];
[oPanel setCanChooseDirectories: NO];
[oPanel setCanChooseFiles: YES];
NSArray *fileTypes = [NSArray arrayWithObjects: @"text",
@"TEXT", @"txt", @"TXT", @"fasta", @"FASTA", @"seq", @"SEQ",
@"html", @"HTML", @"htm", @"HTM", @"rtf", @"RTF", @"rtfd", @"RTFD",
@"gde", @"fas", @"nessig", @"pir", @"nona", @"phylip", @"nexus",
@"GDE", @"FAS", @"NESSIG", @"PIR", @"NONA", @"PHYLIP", @"NEXUS",
@"raw", @"clustal", @"pdb", @"embl", @"swissprot", @"NCBI", @"GCK",
@"RAW", @"CLUSTAL", @"PDB", @"EMBL", @"SWISSPROT", @"ncbi", @"gck",
@"aln", @"hen", @"fst", @"msf", @"nxs", @"non", @"phy", @"tnt",
@"ALN", @"HEN", @"FST", @"MSF", @"NXS", @"NON", @"PHY", @"TNT", @"",
NSFileTypeForHFSTypeCode('TEXT'), NSFileTypeForHFSTypeCode('TXT '),
NSFileTypeForHFSTypeCode('text'),
NSFileTypeForHFSTypeCode('xDNA'), NSFileTypeForHFSTypeCode('DNA '),
NSFileTypeForHFSTypeCode('GCKc'), NSFileTypeForHFSTypeCode('GCKs'),
NSFileTypeForHFSTypeCode('NUCL'), nil];
[oPanel beginSheetForDirectory: nil
file: nil
types: fileTypes
modalForWindow: [NSApp mainWindow]
modalDelegate: self
didEndSelector: @selector
(importPanelDidEnd:returnCode:contextInfo:)
contextInfo: nil];
}
- (void)importPanelDidEnd:(NSOpenPanel *)oPanel returnCode:(int)
returnCode contextInfo:(void *)contextInfo{
if (returnCode == NSOKButton) {
BCReader *reader = [[BCReader alloc]init];
NS_DURING
NSDictionary *dict = [reader readFile: [[oPanel filenames]
objectAtIndex: 0]];
// In the future it would be nice to present a dialog to the user
// where he/she could choose which sequence to open in case the file
// contains multiple sequences
if([[dict objectForKey: @"items"] count] > 0) {
NSString *name = [[dict objectForKey: @"items"]objectAtIndex: 0];
NSString *sequence = [[dict objectForKey: @"matrix"]
objectForKey: name];
// do your stuff here with the obtained sequence...
}
NS_HANDLER
NSBeep();
NSString *title = @"Error Reading File";
NSString *defaultButton = @"OK";
NSString *alternateButton = nil;
NSString *otherButton = nil;
NSString *message = @"iRNAi could not read the selected file,
which might not be a sequence file or not of a format that EnzymeX
does not support. Try converting it to plain text or fasta format.
Alternatively, you can copy the sequence from its native application.";
NSRunAlertPanel(title, message, defaultButton, alternateButton,
otherButton);
NS_ENDHANDLER
[BCReader release];
}
}
The source code can be downloaded here:
http://www.mekentosj.com/biococoa/BCStandaloneReader.zip
Hey, but wait, that's not all!
In 4Peaks I used James S. Derry's JSDTextView to display sequences in
a TextView with linenumbers. James had received a lot of help from
Koen, who basically figured out how to do all this. Unfortunately, in
OSX 10.4 Tiger this textview shows a weird drawing bug so I had to go
on the look out for alternatives. And guess what, Koen actually had
posted some sample code himself as well, which was actually a much
more elegant solution. So I used his KDTextView in 4Peaks.
For iRNAi 2 and EnzymeX 3 I decided to pimp Koen's textview a bit
more and added a number of interesting new features:
- better support for printing
- the mouse location and selections are shown using fancy semi-
transparent overlays
- added columnspacing support in the textcontainer class: instead of
xxxxxxxxxxxxxxxxx now: xxxxx xxxxx xxxxx , without introducing spaces
in the text, so copy/paste, drag and drop, selections etc all work
without having to think about spacing.
Check out iRNAi 2 for a demo (http://www.mekentosj.com/irnai )
It isn't completely ready yet to release it, but once I've finished
EnzymeX 3, I'll post it and let you guys know. Thanks Koen for the
excellent foundation!
Enjoy!
Cheers,
Alex
Ps. Peter kudos on the new stuff your doing and congratulations with
Orbicule, it seems a very successful launch and although not so much
biology, cool product you created!! Didn't have time to write you
this before, but "petje af!" Are you now fulltime doing that?
*********************************************************
** Alexander Griekspoor **
*********************************************************
The Netherlands Cancer Institute
Department of Tumorbiology (H4)
Plesmanlaan 121, 1066 CX, Amsterdam
Tel: + 31 20 - 512 2023
Fax: + 31 20 - 512 2029
AIM: mekentosj at mac.com
E-mail: a.griekspoor at nki.nl
Web: http://www.mekentosj.com
4Peaks - For Peaks, Four Peaks.
2004 Winner of the Apple Design Awards
Best Mac OS X Student Product
http://www.mekentosj.com/4peaks
*********************************************************