annotate minimus2/minimus2_wrapper.pl @ 0:937ba44abdb7 default tip

Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
author edward-kirton
date Tue, 07 Jun 2011 17:29:43 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
1 #!/usr/bin/env perl
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
2
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
3 use strict;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
4 use Getopt::Long;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
5 use Env qw(TMPDIR TEMPDIR);
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
6
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
7 my $usage=<<'ENDHERE';
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
8 NAME:
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
9 minimus2_wrapper.pl
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
10 PURPOSE:
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
11 To combine two sets of assembled contig sequences. This script wraps Minimus2, part of the AMOS package.
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
12 REQUIRED ARGUMENTS:
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
13 $1 : infile1 in Fasta format
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
14 $2 : infile2 in Fasta format
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
15 $4 : outfile of combined assembly in Fasta format
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
16 $5 : outfile of singletons in Fasta format
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
17 OPTIONS:
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
18 -tmpdir <dir> : path of temporary directory to use (optional); tempfiles will be discarded upon completion
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
19 -prefix1 <string> : rename reads in infile1 using <prefix>.<counter> format
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
20 -prefix2 <string> : rename reads in infile2 using <prefix>.<counter> format
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
21 NOTE:
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
22 - Minimus2 will fail if there are duplicate IDs between infile1 and infile2; use prefix options to avoid this.
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
23 ENDHERE
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
24
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
25 # OPTIONS
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
26 our $tmpdir;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
27 my ($help,$prefix1,$prefix2);
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
28 GetOptions(
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
29 'tmpdir=s' => \$tmpdir,
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
30 'prefix1=s' => \$prefix1,
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
31 'prefix2=s' => \$prefix2,
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
32 'help' => \$help
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
33 );
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
34 if ($help) { print $usage; exit; }
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
35
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
36 # VALIDATE
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
37 die("Expect exactly four arguments\n") unless @ARGV == 4;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
38 my ($infile1,$infile2,$contigs_outfile,$singletons_outfile)=@ARGV;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
39 if ($tmpdir) {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
40 unless (-d $tmpdir) {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
41 mkdir($tmpdir) or die("Unable to create tmpdir, $tmpdir\n");
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
42 }
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
43 } elsif ($TMPDIR and -d $TMPDIR) {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
44 $tmpdir=$TMPDIR;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
45 } elsif ($TEMPDIR and -d $TEMPDIR) {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
46 $tmpdir=$TEMPDIR;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
47 } elsif (-d "/tmp") {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
48 $tmpdir="/tmp";
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
49 } elsif (-d "/scratch") {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
50 $tmpdir="/scratch";
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
51 } else {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
52 die("Tmpdir required\n");
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
53 }
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
54 $tmpdir .= "/$$";
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
55 mkdir($tmpdir) or die("Unable to mkdir $tmpdir\n");
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
56
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
57 # CHECK EXECUTABLES
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
58 my $toAmos=`which toAmos`;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
59 chomp $toAmos;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
60 dienice("toAmos executable not found\n") unless $toAmos and -f $toAmos;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
61 my $minimus2=`which minimus2`;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
62 chomp $minimus2;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
63 dienice("minimus2 executable not found\n") unless $minimus2 and -f $minimus2;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
64 my $deltafilter=`which delta-filter`;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
65 chomp $deltafilter;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
66 dienice("delta-filter executable not found\n") unless $deltafilter and -f $deltafilter;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
67 my $showcoords=`which show-coords`;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
68 chomp $showcoords;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
69 dienice("show-coords executable not found\n") unless $showcoords;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
70
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
71 # CONCATENATE INFILES
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
72 open(IN1, "<$infile1") or dienice("Unable to open infile1, $infile1\n");
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
73 my $infile="$tmpdir/infile.seq";
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
74 open(OUT, ">$infile") or dienice("Unable to open tmpfile, $infile\n");
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
75 my $n1=0;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
76 while (<IN1>) {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
77 if (/^>/) {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
78 ++$n1;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
79 if ($prefix1) {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
80 print OUT ">$prefix1.$n1\n";
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
81 } else {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
82 print OUT;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
83 }
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
84 } else {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
85 print OUT;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
86 }
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
87 }
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
88 close IN1;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
89 dienice("Infile 1 contains no sequences or is not in Fasta format\n") unless $n1;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
90 my $n2=0;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
91 open(IN2, "<$infile2") or dienice("Unable to open infile2, $infile2\n");
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
92 while (<IN2>) {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
93 if (/^>/) {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
94 ++$n2;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
95 if ($prefix2) {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
96 print OUT ">$prefix2.$n2\n";
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
97 } else {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
98 print OUT;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
99 }
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
100 } else {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
101 print OUT;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
102 }
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
103 }
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
104 close IN2;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
105 close OUT;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
106 dienice("Infile 2 contains no sequences or is not in Fasta format\n") unless $n2;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
107
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
108 # CONVERT FORMAT
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
109 eval { `toAmos -s $infile -o $tmpdir/infile.afg` };
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
110 dienice("ERROR CONVERTING TO AMOS FORMAT\n") if $@;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
111
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
112 # CO-ASSEMBLY
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
113 # explicitly defining the delta-filter and show-coords executables is more robust
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
114 eval { `minimus2 $tmpdir/infile -D REFCOUNT=$n1 -D DELTAFILTER=$deltafilter -D SHOWCOORDS=$showcoords` };
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
115 dienice("ERROR EXECUTING MINIMUS2\n") if $@;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
116
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
117 # MOVE FILES AND CLEANUP TMPDIR
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
118 eval { `mv $tmpdir/infile.fasta $contigs_outfile` };
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
119 dienice("ERROR MOVING CONTIGS OUTFILE\n") if $@;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
120 eval { `mv $tmpdir/infile.singletons.seq $singletons_outfile` };
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
121 dienice("ERROR MOVING SINGLETONS OUTFILE\n") if $@;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
122 eval { `rm -rf $tmpdir` };
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
123 die("ERROR CLEANING UP TEMP DIR\n") if $@;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
124 exit;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
125
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
126 # CLEANUP TEMPFILES BEFORE QUITTING
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
127 sub dienice {
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
128 my $msg=shift;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
129 `rm -rf $tmpdir`;
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
130 die($msg);
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
131 }
937ba44abdb7 Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
edward-kirton
parents:
diff changeset
132 __END__