Changeset 3570
- Timestamp:
- Jul 19, 2007, 8:45:03 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/src/docbook/developerdoc/plugin_developer.xml
r3565 r3570 1770 1770 by reading the headers from the input stream and checking if 1771 1771 it stopped at an unknown type of line or not: 1772 <example>1773 <title>Checking file headers</title>1774 1772 <programlisting> 1775 1773 public final boolean isImportable(InputStream in) … … 1789 1787 } 1790 1788 </programlisting> 1791 </example>1792 1789 </para> 1793 1790 <para> … … 2721 2718 <methodname>Plugin.getMainType()</methodname> method. The information returned from 2722 2719 <methodname>InteractivePlugin.getGuiContexts()</methodname> 2723 must include: [<constant>Item.BIOASSAYSET</constant>, <constant>Type.ITEM</constant>] since 2724 this is the only place where the web client looks for analysis plug-ins. 2720 must include: [<constant>Item.BIOASSAYSET</constant>, <constant>Type.ITEM</constant>] 2721 since this is the main place where the web client looks for analysis plug-ins. If 2722 the plug-in can work on a subset of the bioassays it may also include 2723 [<constant>Item.BIOASSAY</constant>, <constant>Type.LIST</constant>] 2724 among the contexts. This will make it possible for a user to select 2725 bioassays from the list and then invoke the plug-in. 2725 2726 </para> 2726 2727 2727 <programlisting>private static final Set<GuiContext> guiContexts = 2728 <programlisting> 2729 private static final Set<GuiContext> guiContexts = 2728 2730 Collections.singleton(new GuiContext(Item.BIOASSAYSET, GuiContext.Type.ITEM)); 2729 2731 … … 2733 2735 }</programlisting> 2734 2736 2737 <para> 2738 If the plugin depends on a specific raw data type or on the number of 2739 channels, it should check that the current bioassayset is of the 2740 correct type in the <methodname>InteractivePlugin.isInContext()</methodname> 2741 method. It is also a good idea to check if the current user has permission 2742 to use the current experiment. This permission is needed to create new bioassaysets or 2743 other data belonging to the experiment. 2744 </para> 2745 2746 <programlisting> 2747 public boolean isInContext(GuiContext context, Object item) 2748 { 2749 if (item == null) 2750 { 2751 message = "The object is null"; 2752 } 2753 else if (!(item instanceof BioAssaySet)) 2754 { 2755 message = "The object is not a BioAssaySet: " + item; 2756 } 2757 else 2758 { 2759 BioAssaySet bas = (BioAssaySet)item; 2760 int channels = bas.getRawDataType().getChannels(); 2761 if (channels != 2) 2762 { 2763 message = "This plug-in requires 2-channel data, not " + channels + "-channel."; 2764 } 2765 else 2766 { 2767 Experiment e = bas.getExperiment(); 2768 e.checkPermission(Permission.USE); 2769 } 2770 } 2771 } 2772 </programlisting> 2773 2774 <para> 2775 The plugin should always include a parameter asking for the current 2776 bioassay set when the <methodname>InteractivePlugin.getRequestInformation()</methodname> 2777 is called with <literal>command = Request.COMMAND_CONFIGURE_JOB</literal>. 2778 </para> 2779 2780 <programlisting> 2781 private static final RequestInformation configurePlugin; 2782 private RequestInformation configureJob; 2783 private PluginParameter<BioAssaySet> bioAssaySetParameter; 2784 2785 public RequestInformation getRequestInformation(GuiContext context, String command) 2786 throws BaseException 2787 { 2788 RequestInformation requestInformation = null; 2789 if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN)) 2790 { 2791 requestInformation = getConfigurePlugin(context); 2792 } 2793 else if (command.equals(Request.COMMAND_CONFIGURE_JOB)) 2794 { 2795 requestInformation = getConfigureJob(context); 2796 } 2797 return requestInformation; 2798 } 2799 2800 private RequestInformation getConfigureJob(GuiContext context) 2801 { 2802 if (configureJob == null) 2803 { 2804 bioAssaySetParameter; = new PluginParameter<BioAssaySet>( 2805 "bioAssaySet", 2806 "Bioassay set", 2807 "The bioassay set used as the source for this analysis plugin", 2808 new ItemParameterType<BioAssaySet>(BioAssaySet.class, null, true, 1, null) 2809 ); 2810 2811 List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(); 2812 parameters.add(bioAssaySetParameter); 2813 // Add more plug-in-specific parameters here... 2814 2815 configureJob = new RequestInformation( 2816 Request.COMMAND_CONFIGURE_JOB, 2817 "Configure job", 2818 "Set parameter for plug-in execution", 2819 parameters 2820 ); 2821 } 2822 return configureJob; 2823 } 2824 </programlisting> 2825 2826 <para> 2827 Of course, the <methodname>InteractivePlugin.configure()</methodname> method needs 2828 to validate and store the bioassay set parameter as well: 2829 </para> 2830 2831 <programlisting> 2832 public void configure(GuiContext context, Request request, Response response) 2833 { 2834 String command = request.getCommand(); 2835 try 2836 { 2837 if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN)) 2838 { 2839 // Validate and store configuration parameters 2840 response.setDone("Plugin configuration complete"); 2841 } 2842 else if (command.equals(Request.COMMAND_CONFIGURE_JOB)) 2843 { 2844 List<Throwable> errors = 2845 validateRequestParameters(configureJob.getParameters(), request); 2846 if (errors != null) 2847 { 2848 response.setError(errors.size() + 2849 " invalid parameter(s) were found in the request", errors); 2850 return; 2851 } 2852 storeValue(job, request, bioAssaySetParameter); 2853 // Store other plugin-specific parameters 2854 2855 response.setDone("Job configuration complete", Job.ExecutionTime.SHORT); 2856 } 2857 } 2858 catch (Throwable ex) 2859 { 2860 // Never throw exception, always set response! 2861 response.setError(ex.getMessage(), Arrays.asList(ex)); 2862 } 2863 } 2864 </programlisting> 2865 2866 <para> 2867 Now, the typical <methodname>Plugin.run()</methodname> method loads the specfied bioassay set 2868 and it's spot data. It may do some filtering and recalculation of the spot 2869 intensity value(s). In most cases it will store the result as a child bioassay 2870 set with one bioassay for each bioassay in the parent bioassay set. 2871 Here is an example, which just copies the intensity values, while 2872 removing those with a negative value in either channel. 2873 </para> 2874 2875 <programlisting> 2876 public void run(Request request, Response response, ProgressReporter progress) 2877 { 2878 DbControl dc = sc.newDbControl(); 2879 try 2880 { 2881 BioAssaySet source = (BioAssaySet)job.getParameter("bioAssaySet"); 2882 // Reload with current DbControl 2883 source = BioAssaySet.getById(dc, source.getId()); 2884 int channels = source.getRawDataType().getChannels(); 2885 2886 // Create transformation and new bioassay set 2887 Job j = Job.getById(dc, job.getId()); 2888 Transformation t = source.newTransformation(j); 2889 t.setName("Copy spot intensities >= 0"); 2890 dc.saveItem(t); 2891 2892 BioAssaySet result = t.newProduct(null, "new", true); 2893 result.setName("After: Copying spot intensities"); 2894 dc.saveItem(result); 2895 2896 // Get query for source data 2897 DynamicSpotQuery query = source.getSpotData(); 2898 2899 // Do not return spots with intensities < 0 2900 for (int ch = 1; ch <= channels; ++ch) 2901 { 2902 query.restrict( 2903 Restrictions.gteq( 2904 Dynamic.column(VirtualColumn.channel(ch)), 2905 Expressions.integer(0) 2906 ) 2907 ); 2908 } 2909 2910 // Create batcher and copy data 2911 SpotBatcher batcher = result.getSpotBatcher(); 2912 int spotsCopied = batcher.insert(query); 2913 batcher.close(); 2914 2915 // Commit and return 2916 dc.commit(); 2917 response.setDone("Copied " + spotsCopied + " spots."); 2918 } 2919 catch (Throwable t) 2920 { 2921 response.setError(t.getMessage(), Arrays.asList(t)); 2922 } 2923 finally 2924 { 2925 if (dc != null) dc.close(); 2926 } 2927 } 2928 </programlisting> 2929 2930 <para> 2931 See <xref linkend="api_overview.dynamic_and_batch_api" /> 2932 for more examples of using the analysis API. 2933 </para> 2934 2935 <sect2 id="plugin_developer.analyse.abstractanalysis"> 2936 <title>The AbstractAnalysisPlugin class</title> 2937 2735 2938 <para> 2736 More documentation is available in the old format. 2737 See <ulink url="http://base.thep.lu.se/chrome/site/doc/development/plugins/analysis/index.html" 2738 >http://base.thep.lu.se/chrome/site/doc/development/plugins/analysis/index.html</ulink> 2939 This class is an abstract base class. It is a useful 2940 class for most analysis plug-ins to inherit from. It's main 2941 purpose is to define <classname>PluginParameter</classname> 2942 objects that are commonly used in analysis plug-ins. This includes: 2739 2943 </para> 2740 2944 2945 <itemizedlist> 2946 <listitem> 2947 <para> 2948 The source bioassay set: 2949 <methodname>getSourceBioAssaySetParameter()</methodname>, 2950 <methodname>getCurrentBioAssaySet()</methodname>, 2951 <methodname>getSourceBioAssaySet()</methodname> 2952 </para> 2953 </listitem> 2954 <listitem> 2955 <para> 2956 The name and description of the child bioassay set that 2957 is going to be created by the plug-in: 2958 <methodname>getChildNameParameter()</methodname>, 2959 <methodname>getChildDescriptionParameter()</methodname> 2960 </para> 2961 </listitem> 2962 <listitem> 2963 <para> 2964 The name and description of the transformation that 2965 represents the execution of the plug-in: 2966 <methodname>getTransformationNameParameter()</methodname>, 2967 <methodname>getTransformationName()</methodname> 2968 </para> 2969 </listitem> 2970 </itemizedlist> 2971 2972 </sect2> 2741 2973 2742 2974 </sect1>
Note: See TracChangeset
for help on using the changeset viewer.