20 February 2008

Posting Code in Blogs

Until the previous post, I'd been hand-converting code samples into HTML for blog entries. Incredibly tedious. Amazingly tedious.

Now I have a tool that does it all for me: Colorer-take5. It integrates with the Eclipse development environment and works like a charm. I just grab the HTML it generates, stick it in <div> and <pre> tags like so:

<div style="color:#AAAAAA; background-color:#0000AA; font-size: small; width: 400px; overflow: auto; padding: 1em"><pre>
<!-- generated HTML -->
</pre></div>


Bam, done. And it's free!

Now I just have to figure out how to make my own coloring scheme.....

Of Document Classes and Timeline Code

My coworker Ezra and I just got through figuring out a bizarre bug in an application created with Flash CS3 (using ActionScript 3.0). Since I didn't see anything else about it online, I thought I'd post it here.

The Set-Up: A loader SWF loads in section SWFs. The section SWFs have timeline code that trigger events based on timeline animations.

The Problem: On their own, the section SWFs worked fine. But once loaded into the loader SWF, only their class code would execute; none of the timeline code would execute, not even traces.

The Really Strange Wrinkle: I created a minimal proof-of-concept test, and it worked fine. It even worked when I used the section SWF from the actual project. So the problem seemed to be in the loader (but it really wasn't).

Here's the code from the minimal proof-of-concept test. Here's the loader class:

package timelinetest {
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.errors.IOError;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLRequest;
public class TestLoader extends Sprite {
public function TestLoader() {
super();
addEventListener(Event.ADDED_TO_STAGE, loadContent);
}
private function loadContent(event:Event):void {
var loader:Loader = new Loader();
var info:LoaderInfo = loader.contentLoaderInfo;
info.addEventListener(IOErrorEvent.IO_ERROR, onContentIOError);
info.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onContentSecurityError);
info.addEventListener(Event.INIT, onContentInit);
loader.load(new URLRequest("./loaded.swf"));
}
private function onContentInit(event:Event):void {
var info:LoaderInfo = event.target as LoaderInfo;
addChild(info.content);
}
private function onContentIOError(event:IOErrorEvent):void {
throw new IOError(event.text);
}
private function onContentSecurityError(event:SecurityErrorEvent):void {
throw new SecurityError(event.text);
}
}
}


... and here's the section class:

package timelinetest {
import flash.display.MovieClip;
import flash.events.Event;
public class TestLoaded extends MovieClip {
public function TestLoaded() {
super();
stop();
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(event:Event):void {
play();
}
public function onSpecialFrameReached():void {
trace("special frame reached");
stop();
}
}
}


... and on frame 10 of the root timeline in loaded.swf I had this code:

trace("calling onSpecialFrameReached()");
onSpecialFrameReached();


So on frame 10, it called onSpecialFrameReached(), which stopped playback. This worked fine. But similar code did not work fine in the actual project.

So What Was the Discrepancy?: Making the following modifications (underlined) to TestLoader.as caused the timeline code failure:

package timelinetest {
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.errors.IOError;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLRequest;
public class TestLoader extends Sprite {
private var loaded:TestLoaded;
public function TestLoader() {
super();
addEventListener(Event.ADDED_TO_STAGE, loadContent);
}
private function loadContent(event:Event):void {
var loader:Loader = new Loader();
var info:LoaderInfo = loader.contentLoaderInfo;
info.addEventListener(IOErrorEvent.IO_ERROR, onContentIOError);
info.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onContentSecurityError);
info.addEventListener(Event.INIT, onContentInit);
loader.load(new URLRequest("./loaded.swf"));
}
private function onContentInit(event:Event):void {
var info:LoaderInfo = event.target as LoaderInfo;
loaded = info.content as TestLoaded;
addChild(loaded);
}
private function onContentIOError(event:IOErrorEvent):void {
throw new IOError(event.text);
}
private function onContentSecurityError(event:SecurityErrorEvent):void {
throw new SecurityError(event.text);
}
}
}


See the difference? Before, there was no reference to TestLoaded in loader.swf. With this change, there is. Before, when loaded.swf was loaded, it contained the only reference to TestLoaded. This was as the document class, which had extra code from the timeline, so it was sort of a unique version of the class. But after the change, loader.swf had a copy of the TestLoaded class as well, a copy which had precedence over the unique version loaded in from loaded.swf. So the version with timeline code was ignored—no execution of timeline code.

The Remedy: This is something that was going to be done anyway—none of the loaded section SWFs should use the base version of the section/loaded class. They should all use their own subclasses. That way, nothing in loader.swf can block them.

Another solution (which isn't appropriate for our project, but it might be for others) would be to reference sections in loader.swf using an interface. (But even with this you'd still have to have different implementations in different SWFs, or they might conflict with each other—I think—should test that sometime.)

Really, though, there should be an option when assigning document classes, as there is when linking to a class from the library. You should be allowed to specify whether you want to use the class itself or an ad hoc subclass. If the former, the presence of timeline code should flag a warning message. Remind me to report this to Adobe.

15 February 2008

Happy Belated Valentine's Day!

We at Exopolis launched a "reboot" of our charming, wacky, retro Valentine's Day Mix Tape yesterday:

XOXO, Exo.


It features 26 songs selected by 26 of us. For my song, click here.


I did not actually have a hand in developing this thing, but I did have some "fun" reviving it. The original project was done two years ago by people who are no longer here, and the source files seem to have vanished. I had to decompile the SWF using Sothink SWF Decompiler. It did a pretty good job overall, but there were a couple of bugs that took me hours to track down.

First of all, functions seem to always be formatted this way:
function myFunction(arg1, arg2) {
// function body
}
...rather than this way:
myFunction = function(arg1, arg2) {
// function body
}
Now, normally that doesn't make a difference, and the former version is indeed preferable. But that changes if the declaration is actually supposed to be used to set a class field. A class field like, oh, say onEnterFrame. In that case, the former syntax simply declares a function and then does nothing with it, instead of actually setting the class's native handler. Fun.

Second of all (and this is not the decompiler's fault), Windows font names and Macintosh font names often differ. I spent hours trying to figure out why the "Send to a Friend" form wasn't working until I finally figured out that the dynamically-created text fields were referencing a font called "GFYKersti". In Windows, the exact same font's name is "GFY Kersti". Don'cha just love errors that boil down to a single character difference?

Anyway, now it works and we have the source properly archived in CVSDude. Back to developing new stuff in AS3 rather than trying to revive old stuff in AS2....

13 February 2008

The Most Primitive Stem-Bat

Man, lots of news pertaining to the evolution of flight lately. I saw a presentation on this bit of news at SVP last year—nice to see that it's been published. (Or, uh, will be tomorrow—today it's online early.)

Bats are mysterious creatures—not just in the poetic sense, but in the phylogenetic sense. What are they related to? Where did they come from? For a long time they were considered primate relatives—in fact, Linnaeus included them (as Genus Vespertilio) in his original version of Ordo Primates. In particular, they were often thought to be related to colugos (Cynocephalus), also known as "flying lemurs". Colugos aren't really lemurs, which are true primates, but they are relatives of primates (as are tree shrews, Tupaiidae). Like bats (and several other groups of therian mammal), colugos are arboreal and have large skin membranes used for aerial locomotion. Several characters seemed to unite bats and colugos, or at least put them in the same neighborhood, and this was the status quo for a while.

Then the whole placental tree got shaken up by molecular studies. Soon it became clear that bats were not at all close to colugos or primates, but were instead part of a large radiation with the imaginative name of Pegasoferae (previously mentioned here). Pegasoferae also includes Perissodactyla (horses, rhinos, tapirs), Carnivora (dogs, bears, weasels, seals, cats, hyenas, mongooses, civets, etc.), and Manis (pangolins, a.k.a. "scaly anteaters"—very odd creatures which look like pine cones).

The upshot is that we lost our model (colugos) for what a flightless stem-bat might look like. Now we have nothing (unless some fossil out there has not been recognized as such), so it's hard to tell much about how flight evolved in bats.

Enter a new species from Wyoming. Onychonycteris finneyi is now the most primitive known stem-bat, edging out the previous titleholder, Icaronycteris index. It still has wings, but it also has more primitive characters than any other known stem-bat. As an example, look at bat claws. Modern bats may or may not have a claw on their first manual digit (thumb). I. index has this, as well as a claw on its second manual digit (hence the name—"index finger"). But O. finneyi has claws on all five of its manual digits (hence its name—"onychus" means "claw").

O. finneyi is not a bat ancestor, since it coexisted with more derived stem-bats like I. index. But it does provide some clues as to the ancestral state of flying bats ("apo-chiropterans"). Scans of its ear canals reveal that, unlike modern bats and other known stem-bats, it did not have sonar capabilities. So, in stem-bats, flight evolved before echolocation.

Analysis of its proportions suggests that, like some modern bats, it probably had a flight style where it did not flap continuously, but had a pattern of fluttering up and then gliding down, fluttering up and then gliding down, and so on. (Sort of like a big, leathery butterfly.)

Unlike most modern bats, but like I. index, O. finneyi has a long tail. This evolutionary pattern is also seen in pterosaurs and birds (avialans), where the ancestral trait is a long tail, but the most successful later lineages evolve shortened tails (with occasional reversals).

The work of integrating fossils into the new paradigm of placental evolution is still in its early stages. Hopefully the characters in O. finneyi can help elucidate this problem, just as they have helped to elucidate the origins of bat flight. This fossil is an important clue in The Mystery of the Bat.

References:
  • Nishihara, H., M. Hasegawa and N. Okada (2006 June 27). Pegasoferae, an unexpected mammalian clade revealed by tracking ancient retroposon insertions. Proceedings of the National Academy of Sciences 103: 9929–9934. doi:10.1073/pnas.0603797103
  • Simmons, N. B., K. L. Seymour, J. Habersetzer and G. F. Gunnell (2008 February 14). Primitive Early Eocene bat from Wyoming and the evolution of flight and echolocation. Nature 451:818–821. doi:10.1038/nature06549

Adorable Science

Scientists recently announced the discovery of one of the smallest pterosaurs of all. Pterosaurs were hairy, skin-winged, flying creatures commonly, and somewhat incorrectly, referred to as "pterodactyls". This adorable little guy has been named Nemicolopterus crypticus, meaning "hidden, forest-dwelling wing".

Painted restoration by Chuang Zhao. Taken from the New Scientist article, which has a larger version.

The wingspan is a mere 25 cm. Although the only known specimen is not a fully grown adult, it would not have gotten too much larger had it lived that long. Smaller pterosaur specimens are known, but they represent less mature individuals (i.e., hatchlings).

As I mentioned, pterosaurs are commonly known as "pterodactyls" outside of the paleontological community. "Ptero-dactyle" is an old term for Pterodactylus, a genus of pterosaur known from the Solnhofen deposits in Germany. That term and other terms like "ornithosaurs" have not been in use in paleontology for a very long time. There is, however, a large group of short-tailed pterosaurs called pterodactyloids; Nemicolopterus is not really a "pterodactyl", but it is a pterodactyloid.

Photo showing just how small this thing was. Taken from the ITN article, which erroneously calls it a "dinosaur".

A far more egregious mistake is being committed by many places reporting this creature, though: calling it a dinosaur. Pterosaurs are not dinosaurs, but are generally considered dinosaur cousins. Most scientists consider them non-dinosaurian stem-avians, although the possibility of a stem-archosaurian position has also been investigated. Unfortunately, primitive pterosauromorphs are not known (with the possible exception of Sharovipteryx mirabilis, a poorly-known Triassic animal seemingly having "leg-wings"), so it is difficult to pin down their exact relationships. But it is quite certain that they were not dinosaurs, that is, there is no way that they were descended from the final common ancestor of Iguanodon bernissartensis and Megalosaurus bucklandii.

pan-Archosauria
|?-Pterosauromorpha (possible position)
`--Archosauria
|--pan-Crocodylia
`--pan-Aves
|--Scleromochlus taylori
|--Pterosauromorpha (generally favored position)
| |?-Sharovipteryx (or in Prolacertiformes)
| `--Pterosauria
`--Dinosauromorpha
|--Lagerpetonidae
| |--Dromomeron romeri
| `--Lagerpeton chanarensis
`--Dinosauriformes
|--Marasuchus lilloensis
`--+--Pseudolagosuchus major
|--Dinosauria (including Aves)
`--+--Eucoelophysis baldwini
`--Silesaurus opolensis

All these nomenclatural goof-ups aside, it's a pretty cool animal, and not just for its size. The toes are curved more than in any other pterosaur, and the authors interpret this as an adaptation to arboreality. I can just picture it hanging like a bat from a Mesozoic tree limb.

Preliminary anatomical reconstruction by John Conway. Click here for the full version.

What's interesting here is that it has arboreal adaptations, but it's not a primitive pterosaur. This same evolutionary pattern is seen in birds (avialans): the earliest members lack arboreal specializations, but some later members developer them. But this pattern is not, so far as we know, seen in bat (chiropteran) evolution. The earliest known stem-bats have arboreal adaptations, while the earliest pterosaurs and avialans do not. Might this reflect a fundamental difference in body plan between pan-mammals (including apo-chiropterans) and sauropsids (including pterosaurs and avialans)?

Two N. crypticus in a tree, by John Conway. Click here for the full version.


Reference:
Wang, X., A. W. A. Kellner, Z. Zhou, and D. A. Campos. (2008 February 12). Discovery of a rare arboreal forest-dwelling flying reptile (Pterosauria, Pterodactyloidea) from China. Proceedings of the National Academy of Sciences 106(6):1983–1987. doi:10.1073/pnas.0707728105

04 February 2008

Aetosaur Aethics and the Future of Scientific Publication

As a longtime dinosaur fan and paleontology enthusiast, I've come to expect certain things in my life. One, I will always get dinosaur-related gunk for my birthday and Christmas (and generally get rid of it at SVP's annual auction, unless it's actually something cool). Two, people will always send me links to paleontology news items.

Sometimes the item will genuinely be news to me. Often, though, (especially with dinosaur news) it's just the popular dissemination of something I already knew about. By the time something actually gets published (and reported), it's likely to have spread through the paleo grapevine already—personal communication, online forums, blogs, presentations at meetings (and the associated abstract volumes), etc.

Sometimes this can be mildly annoying for the paleo-aficionado. Right now I am sitting on some pretty cool stuff that I can't discuss with just anybody. But proper research takes time and proper publication takes time.

The former is a necessary evil, but the latter really isn't. Currently the publication process goes something like this:
  1. A writer (or a group of writers) submits a paper to a journal.
  2. One of the editors gets around to reading it. If they don't think it's appropriate, it's back to step 1 with a different journal.
  3. If they do think it's appropriate, they contact one or more potential anonymous reviewers.
  4. Assuming the people contacted agree to review the paper, and then actually do review the paper, the editor looks over the reviews and adds his/her own opinion. If the consensus is negative, we're back to step 1 (possibly preceded by a rewrite).
  5. If the consensus is positive, then the writer (or head writer) is alerted. At this point the writer(s) may respond to the reviews and make any necessary changes to the paper. A final draft is submitted.
  6. The final draft gets typeset and sent to the writer(s) for approval. Any final errors are (hopefully) smoothed out and sent to the printer.
  7. At some point, the paper is finally published.

As can be imagined, this process often takes a very long time. In my own limited experience, it took nearly two years from my first submitted manuscript (which was rightfully rejected) to the actual printing of my final paper (which was rightfully accepted!). Now, over a year of that was taken up with rewrites, but that still leaves about half a year spent just on the process of publication. And, from what I've heard, that's relatively short. (Lucky me!)

Internet publishing could drastically change that. On the Internet, you can almost instantly publish content globally (without killing any trees, either). Already there are some primarily online journals, like Palaeontologia Electronica, and Nature has an online outlet for non-peer-reviewed research at Nature Precedings. Going forward, we are probably going to see a lot of publication migrate from paper to the Internet. (I myself already read far more papers as PDFs than in print.)

This might have positive repercussions beyond that of simply getting scientific information out there faster. Let's take a look at a current event in the paleontologist world:




Last year, Darren Naish wrote a blog post noting that two separate papers had given a new genus to a species of aetosaur* (or, as Naish calls them, "armadillodiles"), "Desmatosuchus" chamaensis. First there was Rioarribasuchus Lucas, Hunt, and Spielmann 2006 (December), and then Heliocanthus Parker 2007 (January). For a full timeline of these events and related events, see this page on Mike Taylor's website.

How did this redundancy happen? Investigation is still pending, but it is notable that William Parker's (28-page) paper was accepted in December of 2005 and that Spencer Lucas was aware that the paper was in press. Lucas et al.'s (2-page) paper was published in the New Mexico Museum of Natural History and Science Bulletin, a bulletin which Lucas (among others) edits. As editor of a museum's bulletin, it's possible to get things published much faster than the 13 months it took for Parker's paper to go from acceptance to publication. It looks an awful lot like a "claim jump", which is in violation of ICZN ethics (although that would not invalidate the name Rioarribasuchus—Christopher Taylor wrote a post with more details on what the ICZN says here.) But there hasn't been a proper investigation yet, and Lucas hasn't made a public response to the claims of wrongdoing.

I won't speculate on whether or not Lucas et al. are guilty of a breach of ethics, but I will speculate on what would have happened if scientific publications were just published online instead of in print. I think Parker's paper would have gone online in December of 2005 and his Heliocanthus would not be a junior objective synonym. In fact, since Heliocanthus was actually first named in Parker's 2003 thesis, he might have gotten it published even sooner than 2005. (The ICZN does not consider names published in theses to be valid. [Correction.—the ICZN does not consider names in unpublished theses to be valid, and Parker's thesis was not published. Thanks to David Marjanovic for that correction.]) None of this would have even been an issue.

Online publishing won't solve every problem, but I think it will make this sort of taxonomic shenanigan much less common. Of course that's no comfort to anyone involved in this situation (dubbed "Aetogate"), and scientists should be held to proper ethical conduct, anyway. Still, though, the faster scientific publication moves online, the better, in my opinion.

* pronounced more or less like "I eat a sore"