view igv_make_screenshots.xml @ 25:c96924da37af draft

planemo upload for repository https://github.com/bardin-lab/readtagger/tree/master/galaxy commit 0437e9e56f0af2ccfb5f119b0f290109807ed9b0-dirty
author mvdbeek
date Fri, 15 Jun 2018 12:56:58 -0400
parents 2b4c4b610be6
children 6f98222928ee
line wrap: on
line source

<tool id="igv_make_screenshots" name="IGV_screenshots" version="0.1.2">
    <macros>
        <token name="@DISPLAY_LINK@"><![CDATA[
#set $dataset_id = str($__app__.security.encode_id($inputsection.input.dataset.id))
#set $user_id = str($__app__.security.encode_id($__user_id__))
#set $galaxy_url = $__app__.config.galaxy_infrastructure_url
#set $ext = $inputsection.input.extension
#set $element_identifier = $inputsection.input.element_identifier
#set $display_link = "{galaxy_url}/display_application/{dataset_id}/igv_{ext}/local_default/None/data/galaxy_{dataset_id}.{ext}".format(galaxy_url=galaxy_url, dataset_id=dataset_id, ext=ext, user_id=user_id)
]]></token>
        <token name="@PATH@"><![CDATA[#set $path="%s.%s.%s" % ($i, $inputsection.input.element_identifier, $inputsection.input.extension)]]></token>
    </macros>
    <requirements>
        <requirement type="package" version="0.2.9">xvfbwrapper</requirement>
        <!-- TODO: uncomment when igv in conda
        <requirement type="package" version="2.3.93">igv</requirement>
        -->
    </requirements>
    <command detect_errors="exit_code"><![CDATA[
#import re
#if $genome_source.input_type_selector == 'history':
    ln -s '$genome_source.genome' genome.fa &&
#else:
    ln -s '$genome_source.genome.fields.path' genome.fa &&
#end if
samtools faidx genome.fa &&
sed -i.bak -e "s|\"genome.fa\"|\"\$PWD/genome.fa\"|g" '$igv_session' &&
#for $i, $inputsection in enumerate($inputfiles):
    @PATH@
    ln -fs '$inputsection.input' '$path' &&
    #if $inputsection.input.is_of_type('bam')
        ln -fs $inputsection.input.metadata.bam_index '$path'.bai &&
    #end if
#end for
ln -fs $igv_session igv_session.xml &&
cat '$load_session' > load_session.txt &&
echo snapshotDirectory "\$PWD" >> load_session.txt &&
cat load_session.txt '$script_file' '$exit_session' > igv_script.txt &&
cp '$igv_session_remote' '$igv_session_out'
#if not $skip_screenshots:
    && python $__tool_directory__/xvfb_igv.py igv_script.txt '$igv_preferences' $width,$height &&
    zip screenshots.zip *.png &&
    cp screenshots.zip '$screenshots_out'
#end if
    ]]></command>
    <configfiles>
        <configfile name="igv_session">
<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Session genome="genome.fa" hasGeneTrack="false" hasSequenceTrack="true" version="8">
    <Resources>
        #for $i, $inputsection in enumerate($inputfiles):
            @PATH@
            #set $coverage_id="%s_coverage" % $path
        <Resource path="$path"/>
        #end for
    </Resources>
    #for $i, $inputsection in enumerate($inputfiles):
        #if $inputsection.input.is_of_type('bam')
            #set $label=str($inputsection.label) if str($inputsection.label) else str($inputsection.input.element_identifier)
            @PATH
            <Panel height="$inputsection.section_height" name="Panel${label}" width="$width">
            ## First track is the coverage
            <Track altColor="0,0,178" autoScale="true" color="175,175,175" colorScale="ContinuousColorScale;0.0;10.0;255,255,255;175,175,175" displayMode="COLLAPSED" featureVisibilityWindow="-1" fontSize="10" id="$coverage_id" name="$label Coverage" showReference="false" snpThreshold="0.2" sortable="true" visible="true">
                <DataRange baseline="0.0" drawBaseline="true" flipAxis="false" maximum="10.0" minimum="0.0" type="LINEAR"/>
            </Track>
            ## Second track is the actual BAM alignment file
            <Track altColor="0,0,178" autoScale="false" color="0,0,178" displayMode="EXPANDED" featureVisibilityWindow="-1" fontSize="10" id="$path" name="$label" sortable="true" visible="true">
                <RenderOptions colorByTag="$inputsection.color_by_tag" colorOption="TAG" flagUnmappedPairs="false" groupByOption="NONE" groupByTag="BR" linkByTag="READNAME" linkedReads="false" maxInsertSize="1000" minInsertSize="50" quickConsensusMode="false" shadeBasesOption="QUALITY" shadeCenters="true" showAllBases="false" sortByTag="" viewPairs="false"/>
            </Track>
            </Panel>
        #end if
    #end for
    <Panel height="186" name="FeaturePanel" width="$width">
        <Track altColor="0,0,178" autoScale="false" color="0,0,178" displayMode="COLLAPSED" featureVisibilityWindow="-1" fontSize="10" id="Reference sequence" name="Reference sequence" sortable="false" visible="true"/>
        #for $i, $inputsection in enumerate($inputfiles):
            #if not $inputsection.input.is_of_type('bam')
                #set $label=str($inputsection.label) if str($inputsection.label) else str($inputsection.input.element_identifier)
                @PATH@
                <Track altColor="0,0,178" autoScale="false" clazz="org.broad.igv.track.FeatureTrack" color="0,0,178" displayMode="COLLAPSED" featureVisibilityWindow="-1" fontSize="10" id="$path" name="$label" renderer="BASIC_FEATURE" sortable="false" visible="true" windowFunction="count"/>
             #end if
        #end for
    </Panel>
    <PanelLayout dividerFractions="0.004995836802664446,0.12905911740216486,0.2681099084096586,0.5512073272273106,0.8409658617818485"/>
</Session>
        ]]></configfile>
        <configfile name="igv_session_remote">
<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Session genome="dm6" hasGeneTrack="true" hasSequenceTrack="true" version="8">
    <Resources>#for $i, $inputsection in enumerate($inputfiles):@DISPLAY_LINK@<Resource path="$display_link"/>#end for
    </Resources>
    #for $i, $inputsection in enumerate($inputfiles):
        #if $inputsection.input.is_of_type('bam')
            #set $label=str($inputsection.label) if str($inputsection.label) else str($inputsection.input.element_identifier)
            @DISPLAY_LINK@
            #set $coverage_id="%s_coverage" % $display_link
            <Panel height="$inputsection.section_height" name="Panel${label}" width="$width">
            ## First track is the coverage
            <Track altColor="0,0,178" autoScale="true" color="175,175,175" colorScale="ContinuousColorScale;0.0;10.0;255,255,255;175,175,175" displayMode="COLLAPSED" featureVisibilityWindow="-1" fontSize="10" id="$coverage_id" name="$label Coverage" showReference="false" snpThreshold="0.2" sortable="true" visible="true">
                <DataRange baseline="0.0" drawBaseline="true" flipAxis="false" maximum="10.0" minimum="0.0" type="LINEAR"/>
            </Track>
            ## Second track is the actual BAM alignment file
            <Track altColor="0,0,178" autoScale="false" color="0,0,178" displayMode="EXPANDED" featureVisibilityWindow="-1" fontSize="10" id="$display_link" name="$label" sortable="true" visible="true">
                <RenderOptions colorByTag="$inputsection.color_by_tag" colorOption="TAG" flagUnmappedPairs="false" groupByOption="NONE" groupByTag="BR" linkByTag="READNAME" linkedReads="false" maxInsertSize="1000" minInsertSize="50" quickConsensusMode="false" shadeBasesOption="QUALITY" shadeCenters="true" showAllBases="false" sortByTag="" viewPairs="false"/>
            </Track>
            </Panel>
        #end if
    #end for
    <Panel height="186" name="FeaturePanel" width="$width">
        <Track altColor="0,0,178" autoScale="false" color="0,0,178" displayMode="COLLAPSED" featureVisibilityWindow="-1" fontSize="10" id="Reference sequence" name="Reference sequence" sortable="false" visible="true"/>
        #for $i, $inputsection in enumerate($inputfiles):
            #if not $inputsection.input.is_of_type('bam')
                #set $label=str($inputsection.label) if str($inputsection.label) else str($inputsection.input.element_identifier)
                @DISPLAY_LINK@
                <Track altColor="0,0,178" autoScale="false" clazz="org.broad.igv.track.FeatureTrack" color="0,0,178" displayMode="COLLAPSED" featureVisibilityWindow="-1" fontSize="10" id="$display_link" name="$label" renderer="BASIC_FEATURE" sortable="false" visible="true" windowFunction="count"/>
             #end if
        #end for
    </Panel>
    <PanelLayout dividerFractions="0.004995836802664446,0.12905911740216486,0.2681099084096586,0.5512073272273106,0.8409658617818485"/>
</Session>
        ]]></configfile>
        <configfile name="load_session">
load igv_session.xml
        </configfile>
        <configfile name="exit_session">
exit
        </configfile>
        <configfile name="igv_preferences">
SAM.SHOW_SOFT_CLIPPED=$show_softclippped
        </configfile>
    </configfiles>
    <inputs>
        <conditional name="genome_source">
            <param name="input_type_selector" type="select" label="Choose the genome source">
                <option value="cached" selected="True">Built-in references</option>
                <option value="history">Select a fasta file from your history</option>
            </param>
            <when value="cached">
                <param name="genome" type="select" label="Select a genome">
                    <options from_data_table="all_fasta" />
                </param>
            </when>
            <when value="history">
                <param name="genome" type="data" format="fasta" label="Select a fasta file as reference genome"/>
            </when>
        </conditional>
        <repeat name="inputfiles" min="1" title="Add tracks">
            <param name="input" type="data" format="bam,gff,gff3,gtf,bed,vcf" label="Choose an input file"/>
            <param name="label" type="text" label="Enter a label for this file. If no label is entered the history name will be used"/>
            <param name="section_height" type="integer" value="300" label="Height for this track"/>
            <param name="color_by_tag" type="text" value="CD" label="Enter a BAM/SAM tag that should detrmine the color of a read">
                <sanitizer invalid_char="">
                    <valid initial="string.letters,string.digits"><add value="_" /> </valid>
                </sanitizer>
            </param>
        </repeat>
        <param name="skip_screenshots" type="boolean" label="Skip taking screenshots? Only produces session files."/>
        <param name="show_softclippped" type="boolean" label="Show softclipped bases?" truevalue="true" falsevalue="false" checked="true"/>
        <param name="script_file" type="data" format="txt" label="Select a IGV script with regions for which to take screenshots"/>
        <param name="width" label="Select the screenshot width" type="integer" min="800" value="1920"/>
        <param name="height" label="Select the screenshot height" type="integer" min="640" value="1080"/>
    </inputs>
    <outputs>
        <data name="igv_session_out" format="xml"/>
        <data name="screenshots_out" format="zip">
            <filter>skip_screenshots == False</filter>
        </data>
    </outputs>
    <tests>
        <test>
            <param name="genome_source|input_type_selector" value="history"/>
            <param name="genome_source|genome" value="rover_reference.fa"/>
            <repeat name="inputfiles">
                <param name="input" value="rover_corrected.bam"/>
            </repeat>
            <output name="igv_session_out" file="igv_session.xml" lines_diff="6"/>
        </test>
    </tests>
    <help><![CDATA[
        This tool can automate taking screenshots using IGV.
        It takes as input a reference genome, an IGV script file (bedtools igv can produce such a file)
        and a variable number of BAM,GFF,GTF,BED or VCF files, and produces a zip file containing screenshots for each genomic region in the IGV script file.
    ]]></help>
    <citations>
        <citation type="doi">10.1093/bib/bbs017</citation>
    </citations>
</tool>