groovy scripting examples (JAL-???)
[jalview.git] / examples / groovy / stripUniprotPrefixes.groovy
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