view igv_make_screenshots.xml @ 32:9382c8499e73 draft

planemo upload for repository https://github.com/bardin-lab/readtagger/tree/master/galaxy commit c6f25b122899a00695b5ca9e70d34e2c1d288236-dirty
author mvdbeek
date Sun, 20 Jan 2019 14:30:27 -0500
parents 474837e086cc
children 3f980046df62
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 $file_ext = $inputsection.input.extension
#set $igv_ext = $file_ext if $file_ext != "gff3" else "gff"
#set $element_identifier = $inputsection.input.element_identifier
#set $display_link = "{galaxy_url}/display_application/{dataset_id}/igv_{igv_ext}/local_default/None/data/galaxy_{dataset_id}.{file_ext}".format(galaxy_url=galaxy_url, dataset_id=dataset_id, igv_ext=igv_ext, file_ext=file_ext, user_id=user_id)
]]></token>
        <token name="@PATH@"><![CDATA[
#import re
#set $path="%s.%s.%s" % ($i, re.sub('[^\w\-_]', '_', $inputsection.input.element_identifier), $inputsection.input.extension)
]]></token>
    </macros>
    <requirements>
        <!-- Conda can't give us a fully functioning xvfb at this time,
             need to use custom built container
        <requirement type="package" version="0.2.9">xvfbwrapper</requirement>
        <requirement type="package" version="2.4.9">igv</requirement>
        <requirement type="package" version="1.6.6">xorg-libx11</requirement>
        <requirement type="package" version="1.17.4">xorg-x11-server-xvfb-cos6-x86_64</requirement>
        <requirement type="package" version="11.0.7">mesa-libgl-cos6-x86_64</requirement>
        <requirement type="package" version="2.0.94">libselinux-cos6-x86_64</requirement>
        <requirement type="package" version="1.0.2">openssl</requirement>
        <requirement type="package" version="1.9">samtools</requirement>
        <requirement type="package" version="8.30">coreutils</requirement>
        -->
        <container type="docker">mvdbeek/igv_make_screenshots:0.1.2</container>
    </requirements>
    <command detect_errors="exit_code"><![CDATA[
#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 &&
cp '$igv_session' igv_session.xml &&
sed -i.bak -e "s|\"genome.fa\"|\"\$PWD/genome.fa\"|g" igv_session.xml &&
#for $i, $inputsection in enumerate($inputfiles):
    @PATH@
    ln -fs '$inputsection.input' '$path' &&
    sed -i.bak -e "s|\"$path\"|\"\$PWD/$path\"|g" igv_session.xml &&
    #if $inputsection.input.is_of_type('bam')
        ln -fs $inputsection.input.metadata.bam_index '$path'.bai &&
    #end if
#end for
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:
    && xvfb-run --server-args="-screen 0 ${width}x${height}x24" igv -g genome.fa -o '$igv_preferences' --batch igv_script.txt &&
    mkdir screenshots && mv *.png screenshots
#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" label="IGV session for ${on_string}"/>
        <collection name="screenshots_out" type="list" label="IGV screenshots for ${on_string}">
            <filter>skip_screenshots == False</filter>
            <discover_datasets pattern="__name_and_ext__" directory="screenshots" />
        </collection>
    </outputs>
    <tests>
        <test>
            <param name="genome_source|input_type_selector" value="history"/>
            <param name="genome_source|genome" value="rover_reference.fa"/>
            <param name="script_file" value="complete_batchscript.txt"/>
            <repeat name="inputfiles">
                <param name="input" value="rover_corrected.bam"/>
            </repeat>
            <output name="igv_session_out" file="igv_session.xml" lines_diff="6"/>
            <output_collection name="screenshots_out" type="list" count="1"/>
        </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>