]> git.donarmstrong.com Git - biopieces.git/commitdiff
added indel_seq
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 15 Jun 2009 18:19:52 +0000 (18:19 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 15 Jun 2009 18:19:52 +0000 (18:19 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@531 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/indel_seq [new file with mode: 0755]
code_perl/Maasha/Seq.pm

diff --git a/bp_bin/indel_seq b/bp_bin/indel_seq
new file mode 100755 (executable)
index 0000000..8dd606d
--- /dev/null
@@ -0,0 +1,95 @@
+#!/usr/bin/env perl -w
+
+# 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Introduce indels into sequences in the stream.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+use strict;
+use Maasha::Common;
+use Maasha::Biopieces;
+use Maasha::Seq;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $options, $in, $out, $insertions, $deletions, $seq_len, $record );
+
+$options = Maasha::Biopieces::parse_options(
+    [
+        { long => 'insertions',         short => 'i', type => 'uint',  mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
+        { long => 'insertions_percent', short => 'P', type => 'float', mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
+        { long => 'deletions',          short => 'd', type => 'uint',  mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
+        { long => 'deletions_percent',  short => 'D', type => 'float', mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
+    ]   
+);
+
+$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
+$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+
+while ( $record = Maasha::Biopieces::get_record( $in ) ) 
+{
+    if ( $record->{ "SEQ" } )
+    {
+        $seq_len     = length $record->{ "SEQ" };
+
+        $insertions  = $options->{ "insertions" } || int( $seq_len * ( $options->{ "insertions_percent" } / 100 ) );
+        $deletions   = $options->{ "deletions" }  || int( $seq_len * ( $options->{ "deletions_percent" } / 100 ) );
+
+        Maasha::Common::error( qq(insertions > sequence length: $insertions > $seq_len)  ) if $insertions > $seq_len;
+        Maasha::Common::error( qq(deletions > sequence length: $deletions > $seq_len)  )   if $deletions > $seq_len;
+
+        $record->{ "SEQ" } = Maasha::Seq::seq_insert( $record->{ "SEQ" }, $insertions );
+        $record->{ "SEQ" } = Maasha::Seq::seq_delete( $record->{ "SEQ" }, $deletions );
+
+        $record->{ "SEQ_LEN" } = length $record->{ "SEQ" };
+    }
+
+    Maasha::Biopieces::put_record( $record, $out );
+}
+
+Maasha::Biopieces::close_stream( $in );
+Maasha::Biopieces::close_stream( $out );
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+BEGIN
+{
+    Maasha::Biopieces::status_set();
+}
+
+
+END
+{
+    Maasha::Biopieces::status_log();
+}
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+__END__
index 12839653b5fbb4dec3b992401c22eda77edce6b9..85e391107a181d52d02bab253af1db48cea869b6 100644 (file)
@@ -779,6 +779,56 @@ sub seq_generate
 }
 
 
+sub seq_insert
+{
+    # Martin A. Hansen, June 2009.
+
+    # Randomly duplicates a given number of residues in a given sequence.
+
+    my ( $seq,          # sequence to mutate
+         $insertions,   # number of residues to insert
+       ) = @_;
+
+    # Returns a string.
+
+    my ( $i, $pos );
+
+    for ( $i = 0; $i < $insertions; $i++ )
+    {
+        $pos = int( rand( length $seq ) );
+
+        substr $seq, $pos, 0, substr $seq , $pos, 1;
+    }
+
+    return $seq;
+}
+
+
+sub seq_delete
+{
+    # Martin A. Hansen, June 2009.
+
+    # Randomly deletes a given number of residues from a given sequence.
+
+    my ( $seq,         # sequence to mutate
+         $deletions,   # number of residues to delete
+       ) = @_;
+
+    # Returns a string.
+
+    my ( $i, $pos );
+
+    for ( $i = 0; $i < $deletions; $i++ )
+    {
+        $pos = int( rand( length $seq ) );
+
+        substr $seq, $pos, 1, '';
+    }
+
+    return $seq;
+}
+
+
 sub seq_mutate
 {
     # Martin A. Hansen, June 2009.