MS2: File-based Module Resources

2020-09-23

This topic is under construction for the 20.11 (November 2020) release of LabKey Server. For current documentation of this feature, click here.

This topic provides a few example resources that could be included in a file-based module to customize your dashboards and queries. You can install our demo module, or recreate one or more of these resources in your own file-based module.

Demo Module

Download this demo module and deploy it on your server:

When you add this module to a ms2 folder (via (Admin) > Folder > Management > Folder Type, you will be able to access custom views, queries, and reports it contains.

File Contents of reportDemo

reportDemo │ module.properties │ build.gradle └───resources    ├───queries    │ └───ms2    │ │ PeptideCounts.sql (SQL Queries)    │ │ PeptidesWithCounts.sql    │ │    │ └───Peptides    │ High Prob Matches.qview.xml (Custom Grid View)    │    ├───reports    │ └───schemas    │ └───ms2    │ └───PeptidesWithCounts    │ Histogram.r (R Report)    │    └───views        reportdemo.html (Custom UI)        reportdemo.view.xml        reportdemo.webpart.xml

Custom Grid View

The file High Prob Matches.qview.xml will display peptides with high Peptide Prophet scores (greater than or equal to 0.9). It's syntax is:

<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="Scan"/>
<column name="Charge"/>
<column name="PeptideProphet"/>
<column name="Fraction/FractionName"/>
</columns>
<filters>
<filter column="PeptideProphet" operator="gte" value="0.9"/>
</filters>
<sorts>
<sort column="PeptideProphet" descending="true"/>
</sorts>
</customView>
  • The root element of the qview.xml file must be <customView> and you should use the namespace indicated.
  • <columns> specifies which columns are displayed. Lookups columns can be included (e.g., "Fraction/FractionName").
  • <filters> may contain any number of filter definitions. (In this example, we filter for rows where PeptideProphet >= 0.9). (docs: <filter>)
  • <sorts> section will be applied in the order they appear in this section. In this example, we sort descending by the PeptideProphet column. To sort ascending simply omit the descending attribute.

See the View

The directory location of the qview.xml file determines where you can find it. To see the view on the ms2.Peptides table:

  • Go to the Peptides table and click (Grid Views) -- the view High Prob Matches has been added to the list.
    • Select (Admin) > Developer Links > Schema Browser.
    • Open ms2, scroll down to Peptides.
    • Select (Grid Views) > High Prob Matches.

SQL Queries

The example module includes two queries:

PeptideCounts.sql

SELECT
COUNT(Peptides.TrimmedPeptide) AS UniqueCount,
Peptides.Fraction.Run AS Run,
Peptides.TrimmedPeptide
FROM
Peptides
WHERE
Peptides.PeptideProphet >= 0.9
GROUP BY
Peptides.TrimmedPeptide,
Peptides.Fraction.Run

PeptidesWithCounts.sql

SELECT
pc.UniqueCount,
pc.TrimmedPeptide,
pc.Run,
p.PeptideProphet,
p.FractionalDeltaMass
FROM
PeptideCounts pc
INNER JOIN
Peptides p
ON (p.Fraction.Run = pc.Run AND pc.TrimmedPeptide = p.TrimmedPeptide)
WHERE pc.UniqueCount > 1

See the SQL Queries

  • To view your SQL queries, go to the schema browser at (Admin) > Go To Module > Query.
  • On the left side, open the nodes ms2 > user-defined queries > PeptideCounts.

Using an additional *.query.xml file, you can add metadata including conditional formatting, additional keys, and field formatting. The *.query.xml file should have same root file name as the *.sql file for the query to be modified. Learn more in this topic: Modules: Query Metadata.

Add R Report

The Histogram.r file presents a report on the PeptidesWithCounts query also defined in the module. It has the following contents:

png(
filename="${imgout:labkeyl_png}",
width=800,
height=300)

hist(
labkey.data$fractionaldeltamass,
breaks=100,
xlab="Fractional Delta Mass",
ylab="Count",
main=NULL,
col = "light blue",
border = "dark blue")

dev.off()

View this R Histogram

  • Go to the Query module's home page ( (Admin) > Go to Module > Query). Note that the home page of the Query module is the Query Browser.
  • Open the ms2 node, and see your two new queries in the user-defined queries section.
  • Click on PeptidesWithCounts and then View Data to run the query and view the results.
  • While viewing the results, you can run your R report by selecting (Reports) > Histogram.

Custom User Interface

In the views directory, you can provide HTML pages and define web parts making it easier for your users to directly access the resources you created. Note that HTML files must not contain spaces in the file name.

reportdemo.html

<p>
<a id="pep-report-link"
href="<%=contextPath%><%=containerPath%>/query-executeQuery.view?schemaName=ms2&query.queryName=PeptidesWithCounts">
Peptides With Counts Report</a>
</p>

Learn about token replacement for contextPath and containerPath in this topic: Module HTML and Web Parts.

reportdemo.view.xml

<view xmlns="http://labkey.org/data/xml/view"
frame="none" title="Report Demo">
</view>

reportdemo.webpart.xml

<webpart xmlns="http://labkey.org/data/xml/webpart" title="Report Demo">
<view name="reportdemo"/>
</webpart>

View the User Interface

Once you have saved all three files, refresh your portal page and enter > Page Admin Mode. You will see a Report Demo web part available on the left side. Add it to the page and you will see your report.

Learn about setting the permissions to view this web part in this topic: Module HTML and Web Parts.

Related Topics