# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+use warnings;
use strict;
+use POSIX qw( islower );
+use Maasha::Common;
use Data::Dumper;
use IPC::Open2;
use List::Util qw( shuffle );
}
if ( $count = $check_seq =~ tr/FLPQIEflpqie// and $count > 0 ) {
- return "protein";
+ return "PROTEIN";
} elsif ( $count = $check_seq =~ tr/Uu// and $count > 0 ) {
- return "rna";
+ return "RNA";
} else {
- return "dna";
+ return "DNA";
}
}
# Generates all possible DNA oligos of a given wordsize.
- # alternative way: perl -MData::Dumper -e '@CONV = glob( "{T,C,A,G}" x 4 ); print Dumper( \@CONV )'
+ # alternative way: perl -MData::Dumper -e '@CONV = glob( "{A,T,C,G}" x 4 ); print Dumper( \@CONV )'
my ( $wordsize, # size of DNA oligos
$alph, # sequence alphabet
) = @_;
- # returns string
+ # Returns a string
my ( $alph_len, $i, $seq );
}
+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.
+
+ # Introduces a given number of random mutations in a
+ # given sequence of a specified alphabet.
+
+ my ( $seq, # sequence to mutate
+ $mutations, # number of mutations
+ $alph, # alphabet of sequence
+ ) = @_;
+
+ # Returns a string.
+
+ my ( $i, $pos, %lookup_hash );
+
+ $i = 0;
+
+ while ( $i < $mutations )
+ {
+ $pos = int( rand( length $seq ) );
+
+ if ( not exists $lookup_hash{ $pos } )
+ {
+ substr $seq, $pos, 1, res_mutate( substr( $seq , $pos, 1 ), $alph );
+
+ $lookup_hash{ $pos } = 1;
+
+ $i++;
+ }
+ }
+
+ return $seq;
+}
+
+
+sub res_mutate
+{
+ # Martin A. Hansen, June 2009.
+
+ # Mutates a given residue to another from a given alphabet.
+
+ my ( $res, # residue to mutate
+ $alph, # alphabet
+ ) = @_;
+
+ # Returns a char.
+
+ my ( $alph_len, $new );
+
+ $alph_len = scalar @{ $alph };
+ $new = $res;
+
+ while ( uc $new eq uc $res ) {
+ $new = $alph->[ int( rand( $alph_len ) ) ];
+ }
+
+ return POSIX::islower( $res ) ? lc $new : uc $new;
+}
+
+
sub seq_shuffle
{
# Martin A. Hansen, December 2007.
my ( $seq, # sequence string
) = @_;
- # Returns string.
+ # Returns a string.
my ( @list );
{
# Martin A. Hansen, May 2007.
- # returns a requested alphabet
+ # Returns a requested sequence alphabet.
my ( $type, # alphabet type
) = @_;
# returns list
- my ( @alph );
+ my ( %alph_hash, $alph );
+
+ %alph_hash = (
+ DNA => [ qw(A T C G) ],
+ DNA_AMBI => [ qw(A G C U T R Y W S M K H D V B N) ],
+ RNA => [ qw(A U C G) ],
+ RNA_AMBI => [ qw(A G C U T R Y W S M K H D V B N) ],
+ PROTEIN => [ qw(F L S Y C W P H Q R I M T N K V A D E G) ],
+ );
- if ( $type =~ /^dna$/i ) {
- @alph = qw( A T C G );
- } elsif ( $type =~ /^rna$/i ) {
- @alph = qw( A U C G );
- } elsif ( $type =~ /^prot/i ) {
- @alph = qw( F L S Y C W P H Q R I M T N K V A D E G );
+ if ( exists $alph_hash{ uc $type } ) {
+ $alph = $alph_hash{ uc $type };
} else {
die qq(ERROR: Unknown alphabet type: "$type"\n);
}
- return wantarray ? @alph : \@alph;
+ return wantarray ? @{ $alph } : $alph;
}
my ( %analysis, @chars, @chars_lc, $char, %char_hash, $gc, $at, $lc, $max, $res_sum, @indels, %indel_hash );
- $analysis{ "SEQ_TYPE" } = uc Maasha::Seq::seq_guess_type( $seq );
+ $analysis{ "SEQ_TYPE" } = Maasha::Seq::seq_guess_type( $seq );
$analysis{ "SEQ_LEN" } = length $seq;
@indels = qw( - ~ . _ );
map { $analysis{ "RES[$_]" } = $indel_hash{ $_ } } @indels;
$analysis{ "MIX_INDEX" } = sprintf( "%.2f", $max / $analysis{ "SEQ_LEN" } );
- $analysis{ "MELT_TEMP" } = sprintf( "%.2f", 4 * $gc + 2 * $at );
+ #$analysis{ "MELT_TEMP" } = sprintf( "%.2f", 4 * $gc + 2 * $at );
return wantarray ? %analysis : \%analysis;
}