Cleaned up lav_to_bed a bit, added functional test. Removed old, unused tools from the ~/tools/filter directory.

This commit is contained in:
Greg Von Kuster
2008-05-28 19:26:42 +00:00
parent 0288543fe7
commit 57fe2ba4b0
17 changed files with 45 additions and 507 deletions
+10
View File
@@ -0,0 +1,10 @@
1 68 4.1
2 71 4.6
3 62 3.8
4 75 4.4
5 58 3.2
6 60 3.1
7 67 3.8
8 68 4.1
9 71 4.3
10 69 3.7
-26
View File
@@ -1,26 +0,0 @@
#! /usr/bin/perl -w
use strict;
use warnings;
# Unpacks name field generated by Text2BedLike.pl
# BedLike2Text.pl [input BedLike file] [output file]
my $bedLike = 0;
my $command = "cut -f 4 $ARGV[0] | sed s/^BedLike\\|// | tr \" \" \"\t\" > $ARGV[1]";
die "Not enough arguments" unless @ARGV == 2;
# Check that the file is BedLike:
open (TEST, "head -n 2 $ARGV[0] |") or die "Cannot run head:$!\n";
while (<TEST>) {
$bedLike = 1 if ([split "\|"]->[3] =~ /^BedLike/);
}
close TEST;
if ($bedLike == 1) {
system($command);
} else {
die "<font color=\"yellow\">Not a BedLike file. Check you query choice</font>\n";
}
-18
View File
@@ -1,18 +0,0 @@
<tool id="BedLike2Text1" name="BedLike2Text">
<description>restores a file generated with Text2BedLike tool to its original form</description>
<command interpreter="perl">BedLike2Text.pl $input $out_file1</command>
<inputs>
<!-- <display>restore $input to the original format</display> -->
<param format="bed" name="input" type="data" label="Restore"/>
</inputs>
<outputs>
<data format="txt" name="out_file1" />
</outputs>
<help>
Expands the 4th field of a BED-like file generated with **Text2BedLike** to restore the original formatting
See documentation for *Text2bedLike* for more information
</help>
</tool>
-39
View File
@@ -1,39 +0,0 @@
#! /usr/bin/perl -w
use strict;
use warnings;
use Carp;
# Converts tab delimited file into BedLike format
# Interval2BedLike [chrom col] [start col] [end col] [strand col] [inupt file] [output file]
my @fields = ();
die "Check arguments\n" unless @ARGV == 6;
open (IN, "<$ARGV[4]") or die "Cannot open $ARGV[4]:$!";
open (OUT, ">$ARGV[5]") or die "Cannot create $ARGV[5]:$!";
while (<IN>) {
die "This tool can only be used on a tab delimited file. If you think your file is delimited with space, comma, or some other non TAB character -> use Convert Characters tool (Edit Text Queries->Convert Characters) to change it to TAB\n" if !m/\t/;
if (!m/^\#/) {
s/\|/:/g;
chop;
@fields = split /\t/;
for my $line ( 0 .. @fields-1 ) {
$fields[$line] =~ s/^\s+//g;
$fields[$line] =~ s/\s+$//g;
}
$fields[$ARGV[0]-1] =~ s/^/chr/ if $fields[$ARGV[0]-1] !~ m/^chr/;
print OUT "$fields[$ARGV[0]-1]\t$fields[$ARGV[1]-1]\t$fields[$ARGV[2]-1]\tBedLike|" . join("|", @fields) . "\t0";
if ($ARGV[3] == 100) {
print OUT "\n";
} else {
print OUT "\t$fields[$ARGV[3]-1]\n";
}
}
}
close IN;
close OUT;
-41
View File
@@ -1,41 +0,0 @@
<tool id="Interval2Bed1" name="Interval2Bed">
<description>creates a Bed query for displaying at UCSC</description>
<command interpreter="perl">Interval2BedLike.pl $input_chromCol $input_startCol $input_endCol $input_strandCol $input $out_file1</command>
<inputs>
<param format="Interval" name="input" type="data" label="In Query"/>
</inputs>
<outputs>
<data format="bed" name="out_file1" />
</outputs>
<help>
**Interval2Bed** can be used convert Interval query into Bed query for dislaying at UCSC Genome Browser
-----
**Example**
You want to convert the following data into BED::
2 - 478789 477812 TEF1/YPR080W
1 - 73302 72328 CDC19/YAL038W
4 + 1347867 1348565 SSN2/YDR443C
7 - 373310 372735 RCS1/YGL071W
Running Text2Bed will generate::
chr2 478789 477812 BedLike|2|-|478789|477812|TEF1/YPR080W 0 -
chr1 73302 72328 BedLike|1|-|73302|72328|CDC19/YAL038W 0 -
chr4 1347867 1348565 BedLike|4|+|1347867|1348565|SSN2/YDR443C 0 +
chr7 373310 372735 BedLike|4|+|1347867|1348565|SSN2/YDR443C 0 -
The BED like data above contain all necessary BED fields: *chromosome*, *start*, *end*, *name*, *score* and *strand*.
Note that all original information is preserved and packed within *name* field (column 4).
.. class:: infomark
**TIP:** To restore original data use **BedLike2Text** tool in *Convert Formats-&gt;BedLike2text*
</help>
</tool>
-39
View File
@@ -1,39 +0,0 @@
#! /usr/bin/perl -w
use strict;
use warnings;
use Carp;
# Converts tab delimited file into BedLike format
# Text2BedLike [chrom col] [start col] [end col] [strand col] [inupt file] [output file]
my @fields = ();
die "Not enough arguments" unless @ARGV == 6;
open (IN, "<$ARGV[4]") or die "Cannot open $ARGV[4]:$!";
open (OUT, ">$ARGV[5]") or die "Cannot create $ARGV[5]:$!";
while (<IN>) {
die "This tool can only be used on a tab delimited file. If you think your file is delimited with space, comma, or some other non TAB character -> use Convert Characters tool (Edit Text Queries->Convert Characters) to change it to TAB\n" if !m/\t/;
if (!m/^\#/) {
s/\|/:/g;
chop;
@fields = split /\t/;
for my $line ( 0 .. @fields-1 ) {
$fields[$line] =~ s/^\s+//g;
$fields[$line] =~ s/\s+$//g;
}
$fields[$ARGV[0]-1] =~ s/^/chr/ if $fields[$ARGV[0]-1] !~ m/^chr/;
print OUT "$fields[$ARGV[0]-1]\t$fields[$ARGV[1]-1]\t$fields[$ARGV[2]-1]\tBedLike|" . join("|", @fields) . "\t0";
if ($ARGV[3] == 100) {
print OUT "\n";
} else {
print OUT "\t$fields[$ARGV[3]-1]\n";
}
}
}
close IN;
close OUT;
-92
View File
@@ -1,92 +0,0 @@
<tool id="Text2BedLike1" name="Text2BedLike">
<description>creates a Bed-like file from a tab delimited file</description>
<command interpreter="perl">Text2BedLike.pl $chr $start $end $strand $input $out_file1</command>
<inputs>
<!-- <display>set the following columns: &lt;br&gt; $chr as chromosome, &lt;br&gt; $start as start, &lt;br&gt; $end as end, &lt;br&gt; $strand as strand in $input</display> -->
<param format="txt" name="input" type="data" label="In Query"/>
<param name="chr" type="select" label="Get Chromosome from">
<option value="1">Column 1</option>
<option value="2">Column 2</option>
<option value="3">Column 3</option>
<option value="4">Column 4</option>
<option value="5">Column 5</option>
<option value="6">Column 6</option>
<option value="7">Column 7</option>
<option value="8">Column 8</option>
<option value="9">Column 9</option>
<option value="10">Column 10</option>
</param>
<param name="start" type="select" label="Start from">
<option value="2">Column 2</option>
<option value="1">Column 1</option>
<option value="3">Column 3</option>
<option value="4">Column 4</option>
<option value="5">Column 5</option>
<option value="6">Column 6</option>
<option value="7">Column 7</option>
<option value="8">Column 8</option>
<option value="9">Column 9</option>
<option value="10">Column 10</option>
</param>
<param name="end" type="select" label="End from">
<option value="3">Column 3</option>
<option value="2">Column 2</option>
<option value="1">Column 1</option>
<option value="4">Column 4</option>
<option value="5">Column 5</option>
<option value="6">Column 6</option>
<option value="7">Column 7</option>
<option value="8">Column 8</option>
<option value="9">Column 9</option>
<option value="10">Column 10</option>
</param>
<param name="strand" type="select" label="Strand from">
<option value="100">No strand</option>
<option value="1">Column 1</option>
<option value="2">Column 2</option>
<option value="3">Column 3</option>
<option value="4">Column 4</option>
<option value="5">Column 5</option>
<option value="6">Column 6</option>
<option value="7">Column 7</option>
<option value="8">Column 8</option>
<option value="9">Column 9</option>
<option value="10">Column 10</option>
</param>
</inputs>
<outputs>
<data format="bed" name="out_file1" />
</outputs>
<help>
BED files are required to **Perform Interval Operations** and **Fetch Sequences and Alignments**
**Text2BedLike** provides a quick way of generating BED files from non BED tab delimited data
-----
**Example**
You want to convert the following data into BED::
2 - 478789 477812 TEF1/YPR080W
1 - 73302 72328 CDC19/YAL038W
4 + 1347867 1348565 SSN2/YDR443C
7 - 373310 372735 RCS1/YGL071W
Running Text2Bed will generate::
chr2 478789 477812 BedLike|2|-|478789|477812|TEF1/YPR080W 0 -
chr1 73302 72328 BedLike|1|-|73302|72328|CDC19/YAL038W 0 -
chr4 1347867 1348565 BedLike|4|+|1347867|1348565|SSN2/YDR443C 0 +
chr7 373310 372735 BedLike|4|+|1347867|1348565|SSN2/YDR443C 0 -
The BED like data above contain all necessary BED fields: *chromosome*, *start*, *end*, *name*, *score* and *strand*.
Note that all original information is preserved and packed within *name* field (column 4).
.. class:: infomark
**TIP:** To restore original data use **BedLike2Text** tool in *Convert Formats-&gt;BedLike2text*
</help>
</tool>
-54
View File
@@ -1,54 +0,0 @@
#! /usr/bin/perl -w
use strict;
use warnings;
use File::Temp "tempfile";
#aggTrack.pl name input output
#creates three custom tracks for wiggles generated by aggregate datapooints tool
#representing mean, minimum, and maximum values
#input format must look like this:
#chr2L 16296021 16296221 0.738439981826 0.00999999977648 1.46687996387
#chr2L 16298881 16299188 0.795374994166 0.00999999977648 1.58074998856
#where last three columns are mean, minimum, and maximum values
#
my ($f_mean, $fn_mean) = tempfile();
my ($f_min, $fn_min) = tempfile();
my ($f_max, $fn_max) = tempfile();
my ($fh_mean, $fhn_mean) = tempfile();
my ($fh_min, $fhn_min) = tempfile();
my ($fh_max, $fhn_max) = tempfile();
my @trackColors = ("0,70,255", "0,130,0", "255,0,0");
my @trackPriority = (10,20,30);
#Find min and max values
die "Not enough agruments\n" unless @ARGV == 3;
my $min = 1000000;
my $max = 0;
open (IN, "<$ARGV[1]") or die "Cannot open $ARGV[1]:$!\n";
while (<IN>) {
chop;
my @tmp = split /\t/;
if ($tmp[@tmp-2] ne "nan") { $min = $tmp[@tmp-2] if ($min > $tmp[@tmp-2]) }
if ($tmp[@tmp-1] ne "nan") { $max = $tmp[@tmp-1] if ($max < $tmp[@tmp-1]) }
print $f_mean (join("\t", @tmp[0..@tmp-4]) . "\t" . $tmp[@tmp-3] . "\n") unless ($tmp[@tmp-3] eq "nan");
print $f_min (join("\t", @tmp[0..@tmp-4]) . "\t" . $tmp[@tmp-2] . "\n") unless ($tmp[@tmp-2] eq "nan");
print $f_max (join("\t", @tmp[0..@tmp-4]) . "\t" . $tmp[@tmp-1] . "\n") unless ($tmp[@tmp-1] eq "nan");
}
$min = sprintf("%.3f", $min);
$max = sprintf("%.3f", $max);
close IN;
print $fh_mean "track type=wiggle_0 name=\"$ARGV[0]_mean\" description=\"mean\" visibility=full color=$trackColors[0] altColor=$trackColors[0] priority=$trackPriority[0] autoScale=off viewLimits=$min:$max\n";
print $fh_min "track type=wiggle_0 name=\"$ARGV[0]_min\" description=\"minimum\" visibility=full color=$trackColors[1] altColor=$trackColors[1] priority=$trackPriority[1] autoScale=off viewLimits=$min:$max\n";
print $fh_max "track type=wiggle_0 name=\"$ARGV[0]_max\" description=\"maximum\" visibility=full color=$trackColors[2] altColor=$trackColors[2] priority=$trackPriority[2] autoScale=off viewLimits=$min:$max\n";
my $catStatus = system("cat $fhn_mean $fn_mean $fhn_min $fn_min $fhn_max $fn_max > $ARGV[2]");
die "aggTrack exited abnormally: $?" unless $catStatus == 0;
`rm -f $fhn_mean $fn_mean $fhn_min $fn_min $fhn_max $fn_max`;
-16
View File
@@ -1,16 +0,0 @@
<tool id="aggTrack1" name="aggTrack">
<description>format aggregate scors as wig track</description>
<command interpreter="perl">aggTrack.pl "$desc" $input $out_file1</command>
<inputs>
<param format="tabular" name="input" type="data" label="Convert this srg to wiggle"/>
<param name="desc" size="20" type="text" value="my intervals" label="Type a name for your data" />
</inputs>
<outputs>
<data format="txt" name="out_file1" />
</outputs>
<help>
Takes output of "aggregate datapoints" tool and creates a UCSC formatted wig track
</help>
</tool>
+15 -14
View File
@@ -1,6 +1,5 @@
#!/usr/bin/env python
#Reads a LAV file and writes two BED files.
import sys
from galaxy import eggs
import pkg_resources
@@ -9,35 +8,37 @@ import bx.align.lav
assert sys.version_info[:2] >= ( 2, 4 )
def main():
def stop_err( msg ):
sys.stderr.write( msg )
sys.exit()
def main():
try:
lav_file = open(sys.argv[1],'r')
bed_file1 = open(sys.argv[2],'w')
bed_file2 = open(sys.argv[3],'w')
except:
print >>sys.stderr,"Error with provided arguments"
print >>sys.stderr,"Usage: python %s input_lav output_bed1 output_bed2" % sys.argv[0]
sys.exit(0)
except Exception, e:
stop_err( str( e ) )
lavsRead = bedsWritten = 0
lavsRead = 0
bedsWritten = 0
species = {}
for lavBlock in bx.align.lav.Reader(lav_file):
# TODO: this is really bad since everything is read into memory. Can we eliminate this tool?
for lavBlock in bx.align.lav.Reader( lav_file ):
lavsRead += 1
for c in lavBlock.components:
spec,chrom = bx.align.lav.src_split( c.src )
spec, chrom = bx.align.lav.src_split( c.src )
if bedsWritten < 1:
if len(species)==0:
if len( species )==0:
species[spec]=bed_file1
elif len(species)==1:
elif len( species )==1:
species[spec]=bed_file2
else:
continue #this is a pairwise alignment...
if spec in species:
species[spec].write("%s\t%i\t%i\t%s\t%i\t%s\n" % (chrom,c.start,c.end,spec+"_"+str(bedsWritten),0,c.strand))
species[spec].write( "%s\t%i\t%i\t%s_%s\t%i\t%s\n" % ( chrom, c.start, c.end, spec, str( bedsWritten ), 0, c.strand ) )
bedsWritten += 1
for spec,file in species.items():
print "#FILE\t%s\t%s" % (file.name, spec)
+16 -22
View File
@@ -1,35 +1,29 @@
<tool id="lav_to_bed1" name="LAV to BED">
<description>Converts a LAV formated file to BED format</description>
<command interpreter="python">lav_to_bed.py $lav_file $bed_file1 $bed_file2</command>
<description>Converts a LAV formated file to BED format</description>
<command interpreter="python">lav_to_bed.py $lav_file $bed_file1 $bed_file2</command>
<inputs>
<page>
<param name="lav_file" type="data" format="lav" label="LAV File" optional="False"/>
</page>
<param name="lav_file" type="data" format="lav" label="LAV File" optional="False"/>
</inputs>
<outputs>
<data name="bed_file1" format="bed"/>
<data name="bed_file2" format="bed"/>
</outputs>
<help>
<tests>
<!-- NOTE: this tool generates 2 output files, but our functional tests currently only handle the last one generated -->
<test>
<param name="lav_file" value="2.lav" ftype="lav" />
<output name="bed_file2" file="lav_to_bed_out2.bed" />
</test>
</tests>
<help>
**Syntax**
This tool converts a LAV formated file to the BED format.
- **LAV format** LAV is an alignment format developed by Webb Miller's group. It is the primary output format for BLASTZ.
- **LAV format** LAV is an alignment format developed by Webb Miller's group at Penn State University. It is the primary output format for BLASTZ.
- **BED format** Browser Extensible Data format was designed at UCSC for displaying data tracks in the Genome Browser. It has three required fields and twelve additional optional ones::
The first three BED fields (required) are:
1. chrom - The name of the chromosome (e.g. chr1, chrY_random).
2. chromStart - The starting position in the chromosome. (The first base in a chromosome is numbered 0.)
3. chromEnd - The ending position in the chromosome, plus 1 (i.e., a half-open interval).
Additional (optional) fields are:
4. name - The name of the BED line.
5. score - A score between 0 and 1000.
6. strand - Defines the strand - either '+' or '-'.
- **BED format** Browser Extensible Data format was designed at UCSC for displaying data tracks in the Genome Browser.
-----
@@ -40,7 +34,7 @@ This tool converts a LAV formated file to the BED format.
#:lav
s {
&quot;/depot/data2/galaxy/hg16/seq/chr19.nib&quot; 1 63811651 0 1
&quot;/depot/data2/galaxy/mm5/seq/chr11.nib-&quot; 1 121648857 0 1
&quot;/depot/data2/galaxy/mm5/seq/chr11.nib&quot; 1 121648857 0 1
}
h {
&quot;> hg16.chr19&quot;
@@ -69,6 +63,6 @@ This tool converts a LAV formated file to the BED format.
chr11 70568379 70568443 mm5_0 0 +
chr11 70573975 70574054 mm5_1 0 +
</help>
<code file="lav_to_bed_code.py"/>
</help>
<code file="lav_to_bed_code.py"/>
</tool>
+3 -3
View File
@@ -7,12 +7,12 @@ def exec_after_process(app, inp_data, out_data, param_dict, tool, stdout, stderr
fields = line.split("\t")
filename_to_build[fields[1]]=fields[2].strip()
else:
new_stdout = new_stdout + line
new_stdout = "%s%s" % ( new_stdout, line )
for name,data in out_data.items():
try:
data.info = new_stdout +"\n"+ stderr
data.info = "%s\n%s" % ( new_stdout, stderr )
data.dbkey = filename_to_build[data.file_name]
data.name = data.name + " ("+data.dbkey+")"
data.name = "%s (%s)" % ( data.name, data.dbkey )
data.flush()
except:
continue
-28
View File
@@ -1,28 +0,0 @@
#!/usr/bin/env python
"""
Sample some number of random lines from a file. Needs to passes over the
input (but that saves us memory).
usage: %prog in_fname out_fname nlines
"""
import random, sys
in_fname, out_fname, lines = sys.argv[1:]
lines = int( lines )
# First pass, count lines in input
nlines = 0
for line in open( in_fname ):
nlines += 1
# Sample
sample = random.sample( range( nlines ), nlines )
# Second pass, select sampled lines and print
out = open( out_fname, 'w' )
for i, line in enumerate( open( in_fname ) ):
if i in sample:
print >> out, line,
out.close()
-15
View File
@@ -1,15 +0,0 @@
<tool id="random_lines1" name="Select random lines">
<description>from a file</description>
<command interpreter="python">random_lines.py $input $out_file1 $nlines</command>
<inputs>
<param format="txt" name="input" type="data" label="Dataset"/>
<param name="nlines" size="5" type="integer" value="10" label="Lines to sample"/>
</inputs>
<outputs>
<data format="input" name="out_file1" metadata_source="input"/>
</outputs>
<help>
Select the specified number of lines randomly (without replacement) from a
file.
</help>
</tool>
-65
View File
@@ -1,65 +0,0 @@
#! /usr/bin/perl -w
use strict;
use warnings;
use File::Temp "tempfile";
# converts srg file into wig file:
#
# if input looks like this:
#
#chr2 16447976 1.08385
#chr2 16447977 0.01
#chr4 16417846 1.26935
#chr4 16418578 1.54405
#
#the the output will look like that:
#
#variableStep chrom=chr2
#16447976 1.08385
#16447977 0.01
#variableStep chrom=chr4
#16417846 1.26935
#16418578 1.54405
#
#srg2wig.pl input_file output_file
#
die "Not enouth arguments\n" unless @ARGV == 2;
open(IN, "<$ARGV[0]") or die "Cannot open $ARGV[0]\n";
my ($fh1, $fn1) = tempfile();
my $i = 0;
while (<IN>) {
chop;
if (m/^(chr\w+)\t(\d+)\t([\d\.]+)$/) {
print $fh1 "$_\n";
} else {
print STDERR "Line $i does not conform to srg format : $_. Skipping...\n";
}
++$i;
}
close (IN);
my ($fh2, $fn2) = tempfile();
my $sortStatus = system("sort -f -n -k 1,2 $fn1 -o $fn2");
die "srg2wig exited abnormally: $?" unless $sortStatus == 0;
open (OUT, ">$ARGV[1]") or die "Cannot create file $ARGV[1]\n";
my @chr = ();
while (<$fh2>) {
chop;
my @tmp = split /\t/;
print OUT "variableStep chrom=$tmp[0]\n" if $. == 1;
push (@chr, $tmp[0]);
if ($chr[@chr-1] ne $chr[@chr-2]) {
print OUT "variableStep chrom=$chr[@chr-1]\n";
print OUT "$tmp[1]\t$tmp[2]\n";
} else {
print OUT "$tmp[1]\t$tmp[2]\n";
}
}
close OUT;
`rm -f $fn1 $fn2`;
-34
View File
@@ -1,34 +0,0 @@
<tool id="srg2wig1" name="Srg2wig">
<description>converter</description>
<command interpreter="perl">srg2wig.pl $input $out_file1</command>
<inputs>
<param format="tabular" name="input" type="data" label="Convert this srg to wiggle"/>
</inputs>
<outputs>
<data format="tabular" name="out_file1" />
</outputs>
<help>
**Syntax**
This tool converts srg tables into variableStep wiggle tables.
If your input looks like this::
chr2 16447976 1.08385
chr2 16447977 0.01
chr4 16417846 1.26935
chr4 16418578 1.54405
it will be converted into this::
variableStep chrom=chr2
16447976 1.08385
16447977 0.01
variableStep chrom=chr4
16417846 1.26935
16418578 1.54405
</help>
</tool>
+1 -1
View File
@@ -184,7 +184,7 @@ html = galaxy.datatypes.images:Html,text/html
interval = galaxy.datatypes.interval:Interval,display_in_upload
jpg = galaxy.datatypes.images:Image,image/jpeg
laj = galaxy.datatypes.images:Laj
lav = galaxy.datatypes.sequence:Lav
lav = galaxy.datatypes.sequence:Lav,display_in_upload
maf = galaxy.datatypes.sequence:Maf,display_in_upload
pdf = galaxy.datatypes.images:Image,application/pdf
png = galaxy.datatypes.images:Image,image/png