681a0909f82047fd6a17b7a9ec261374b1e6c27a
[jalview.git] / examples / groovy / alignLoadedFile.groovy
1 // run an alignment on the current alignFrame
2 import jalview.ws.jws2.*;
3 import jalview.datamodel.*;
4
5 // First get the JABA service discoverer and see if there are any services.
6 jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer.getDiscoverer();
7 while (disc.isRunning()) {
8 Thread.sleep(50);
9 }
10 if (!disc.isRunning() && !disc.hasServices())
11 {
12   // discoverer is not running, and has no services - so run it again.
13   disc.run();
14 }
15
16 for (jalview.ws.jws2.Jws2Discoverer.Jws2Instance service: disc.getServices()) {
17
18 if (service.serviceType.indexOf("uscle")>-1) {
19   // now - go through the services if any, and find a Muscle service
20   def msaf;
21   try {
22         msaf = currentAlFrame;
23   } catch (q) {
24         // currentAlFrame is not defined - so we were run as an interactive script from the Groovy console
25         // in that case, just pick the first alignmentFrame in the stack.
26         msaf = Jalview.getAlignFrames()[0]
27   };
28   // Finally start Jalview's JabaWS MSA Client with the alignment from msaf
29   new MsaWSClient(service, msaf.getTitle(), msaf.gatherSequencesForAlignment(), false,
30                 true, msaf.getViewport().getAlignment()
31                 .getDataset(), msaf);
32   break;
33 }
34 }