-#!/usr/bin/env perl
-
-# Copyright (C) 2007-2009 Martin A. Hansen.
-
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-# http://www.gnu.org/copyleft/gpl.html
-
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-# Cluster sequences in the stream.
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-
-use warnings;
-use strict;
-use Data::Dumper;
-use Maasha::Common;
-use Maasha::Biopieces;
-use Maasha::Fasta;
-use Maasha::Seq;
-use Maasha::Filesys;
-
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-
-my ( $options, $in, $out, $tmp_dir, $tmp_file, $tmp_fh, $record, $entry, @args, $arg_str, @fields, $line );
-
-$options = Maasha::Biopieces::parse_options(
- [
- { long => 'identity', short => 'i', type => 'float', mandatory => 'no', default => "0.9", allowed => undef, disallowed => undef },
- { long => 'library', short => 'l', type => 'file!', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
- { long => 'no_sort', short => 'n', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
- ]
-);
-
-$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
-$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
-
-$tmp_dir = Maasha::Biopieces::get_tmpdir();
-$tmp_file = "$tmp_dir/uclust.fasta";
-$tmp_fh = Maasha::Filesys::file_write_open( $tmp_file );
-
-while ( $record = Maasha::Biopieces::get_record( $in ) )
-{
- if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) {
- Maasha::Fasta::put_entry( $entry, $tmp_fh );
- }
-
- Maasha::Biopieces::put_record( $record, $out );
-}
-
-close $tmp_fh;
-
-uclust_sort( $tmp_file, $tmp_dir, $options->{ 'verbose' } ) if not $options->{ 'no_sort' };
-
-push @args, "--input $tmp_file";
-push @args, "--id $options->{ 'identity' }";
-push @args, "--tmpdir $tmp_dir";
-push @args, "--uc $tmp_file.out";
-push @args, "--lib $options->{ 'library' }" if $options->{ 'library' };
-push @args, "--libonly" if $options->{ 'library' };
-push @args, "--quiet" if not $options->{ 'verbose' };
-push @args, "> /dev/null 2>&1" if not $options->{ 'verbose' };
-
-$arg_str = join " ", @args;
-
-Maasha::Common::run( "uclust", $arg_str );
-
-$tmp_fh = Maasha::Filesys::file_read_open( "$tmp_file.out" );
-
-while ( $line = <$tmp_fh> )
-{
- next if $line =~ /^#/;
-
- chomp $line;
-
- @fields = split "\t", $line;
-
- $record = {
- REC_TYPE => 'UCLUST',
- TYPE => $fields[ 0 ],
- CLUSTER => $fields[ 1 ],
- SIZE => $fields[ 2 ],
- IDENT => $fields[ 3 ],
- STRAND => $fields[ 4 ],
- Q_BEG => $fields[ 5 ],
- S_BEG => $fields[ 6 ],
- CIGAR => $fields[ 7 ],
- SEQ_NAME => $fields[ 8 ],
- };
-
- Maasha::Biopieces::put_record( $record, $out );
-}
-
-close $tmp_fh;
-
-Maasha::Biopieces::close_stream( $in );
-Maasha::Biopieces::close_stream( $out );
-
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-
-sub uclust_sort
-{
- # Martin A. Hansen, January 2010.
-
- # Sorts a FASTA file according to sequence length
- # - longest first - using uclust.
-
- my ( $file, # file to sort
- $tmp_dir, # temporary directory for sorting
- $verbose, # verbose flag - OPTIONAL
- ) = @_;
-
- # Returns nothing.
-
- my ( @args, $arg_str );
-
- push @args, "--mergesort $file";
- push @args, "--output $file.sort";
- push @args, "--tmpdir $tmp_dir";
- push @args, "--quiet" if not $verbose;
- push @args, "> /dev/null 2>&1" if not $verbose;
-
- $arg_str = join " ", @args;
-
- Maasha::Common::run( "uclust", $arg_str );
-
- rename "$file.sort", $file;
-}
-
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-
-BEGIN
-{
- Maasha::Biopieces::status_set();
-}
-
-
-END
-{
- Maasha::Biopieces::status_log();
-}
-
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-
-__END__