groovy scripting examples (JAL-???)
authorjprocter <jprocter@compbio.dundee.ac.uk>
Sun, 3 Jul 2011 12:05:24 +0000 (13:05 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Sun, 3 Jul 2011 12:05:24 +0000 (13:05 +0100)
examples/groovy/annotationsascsv.groovy [new file with mode: 0644]
examples/groovy/closures.groovy [new file with mode: 0644]
examples/groovy/iterateOverAlignments.groovy [new file with mode: 0644]
examples/groovy/parseproperties.groovy [new file with mode: 0644]
examples/groovy/printtitle.groovy [new file with mode: 0644]
examples/groovy/removeFeaturesByGroup.groovy [new file with mode: 0644]
examples/groovy/stripUniprotPrefixes.groovy [new file with mode: 0644]

diff --git a/examples/groovy/annotationsascsv.groovy b/examples/groovy/annotationsascsv.groovy
new file mode 100644 (file)
index 0000000..5f0a66a
--- /dev/null
@@ -0,0 +1,9 @@
+// do something groovy in jalview
+print "Hello World.\n";
+def alf = Jalview.getAlignframes();
+for (ala in alf)
+{
+       def alignment = ala.viewport.alignment;
+       // ala is an jalview.gui.AlignFrame object 
+       print new jalview.io.AnnotationFile().printCSVAnnotations(alignment.getAlignmentAnnotation())+"\n";
+}
\ No newline at end of file
diff --git a/examples/groovy/closures.groovy b/examples/groovy/closures.groovy
new file mode 100644 (file)
index 0000000..9e4dd52
--- /dev/null
@@ -0,0 +1,5 @@
+writeAnnot = { 
+  new File(it).append(new jalview.io.AnnotationFile().printAnnotations(Jalview.getAlignframes()[0].getViewport().getAlignment().getAlignmentAnnotation(),null,null)) 
+}
+
+
diff --git a/examples/groovy/iterateOverAlignments.groovy b/examples/groovy/iterateOverAlignments.groovy
new file mode 100644 (file)
index 0000000..83c4169
--- /dev/null
@@ -0,0 +1,20 @@
+import jalview.analysis.*;
+import jalview.datamodel.*;
+import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
+
+def af = Jalview.getAlignframes();
+
+for (ala in af)
+{
+       def al = ala.viewport.alignment;
+       if (al!=null && al.getCodonFrames()!=null)
+       {
+               al.getCodonFrames().each { 
+                       it.getdnaToProt().each {
+                               it2 -> println it2.fromShifts+"\n"
+                       }
+               }
+       }
+}
+       
diff --git a/examples/groovy/parseproperties.groovy b/examples/groovy/parseproperties.groovy
new file mode 100644 (file)
index 0000000..646ebf8
--- /dev/null
@@ -0,0 +1,13 @@
+import jalview.analysis.*;
+import jalview.datamodel.*;
+import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
+
+def af = Jalview.getAlignframes();
+def al = af[0].viewport.alignment;
+ParseProperties pp = new ParseProperties(al);
+pp.getScoresFromDescription("Score", "ScanPS Raw Score", "([-0-9.+]+)");
+def sqs = al.getSequenceAt(0);
+def annots = sqs.getAnnotation();
+
+
diff --git a/examples/groovy/printtitle.groovy b/examples/groovy/printtitle.groovy
new file mode 100644 (file)
index 0000000..8fe91db
--- /dev/null
@@ -0,0 +1,12 @@
+// do something groovy in jalview\r
+print "Hello World.\n";\r
+def alf = Jalview.getAlignframes();\r
+for (ala in alf)\r
+{\r
+       // ala is an jalview.gui.AlignFrame object \r
+       print ala.getTitle()+"\n";\r
+       // get the parent jalview.datamodel.Alignment from the alignment viewport\r
+       def alignment = ala.viewport.alignment;\r
+       // get the first sequence from the jalview.datamodel.Alignment object\r
+       def seq = alignment.getSequenceAt(0); \r
+}\r
diff --git a/examples/groovy/removeFeaturesByGroup.groovy b/examples/groovy/removeFeaturesByGroup.groovy
new file mode 100644 (file)
index 0000000..bf7f74d
--- /dev/null
@@ -0,0 +1,31 @@
+import jalview.analysis.*;
+import jalview.datamodel.*;
+import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
+
+def af = Jalview.getAlignframes();
+
+def todie = "PDBFile"; // about to delete this type of group
+for (ala in af)
+{
+       def al = ala.viewport.alignment.getDataset();
+       if (al!=null)
+       {
+               SequenceI[] seqs = al.getSequencesArray();
+               for (sq in seqs)
+               {
+                       if (sq!=null) {
+                               SequenceFeature[] sf = sq.getSequenceFeatures();
+                               for (sfpos in sf)
+                               {
+                                   if (sfpos!=null && sfpos.getFeatureGroup().equals(todie))
+                                       {
+                                               sq.deleteFeature(sfpos);
+                                       }
+                               }
+                       }
+               }
+       }
+}
+       
+
diff --git a/examples/groovy/stripUniprotPrefixes.groovy b/examples/groovy/stripUniprotPrefixes.groovy
new file mode 100644 (file)
index 0000000..e2bb129
--- /dev/null
@@ -0,0 +1,31 @@
+import jalview.analysis.*;
+import jalview.datamodel.*;
+import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
+
+def af = Jalview.getAlignframes();
+
+// walk through  all alignments, stripping off all text prior to and including last '|' symbol in sequence IDs
+
+for (ala in af)
+{
+       def al = ala.viewport.alignment;
+       if (al!=null)
+       {
+               SequenceI[] seqs = al.getSequencesArray();
+               for (sq in seqs)
+               {
+                       if (sq!=null) {
+                               if (sq.getName().indexOf("|")>-1)
+                               {
+                                       sq.setName(sq.getName().substring(sq.getName().lastIndexOf("|")+1));
+                                       if (sq.getDatasetSequence()!=null)
+                                       {
+                                               sq.getDatasetSequence().setName(sq.getName());
+                                       }
+                               }
+                       }
+               }
+       }
+}
+       
\ No newline at end of file