Extract ids from file with perl
#!/usr/bin/perl use strict; use warnings; my $fh=read_fh("fin.txt"); my %idHash; my $lastKey; while () { chomp $_; my @cells = split /\t/, $_; $idHash{$cells[0]}=$.;...2620 days ago
Extract fasta sequence from a multifasta file with fasta header Ids
...$select{$_} = 1; } close LIST; $/ = "\n>"; open OUT, ">$out" or die; open FASTA, "$fasta" or die; while () { s/>//g; my ($id) = split (/\n/, $_); print OUT ">...2530 days ago
Compress and decompress the sequence with perl
use strict; use warnings; my @char; while () { @char = split //; } comp(\@char); #--------------------- my $com= "r0a3m4a4j0"; my @com = split //, $com; dcomp (\@com); #dcomp sub here sub dcomp { my ($com_ref)=@_; my @com=@$com_ref; my $car; for (my $aa=0; $aa2526 days ago
2524 days ago
Calculate Dinucleotide Frequency with Perl
#!/usr/bin/perl -w use strict; my ($genome, $head, $tail); my (%mono_nt, %di_nt); $/ = ">"; open my $fasta, '2350 days ago
Extract the fastq sequence with range in Perl
use Bio::DB::Fasta; open(POSITIONS,"positions.txt"); while(){ chomp; my ($seqName,$begin,$end) = split(/\s/); my $db = Bio::DB::Fasta->new('allGenomeContacted.fa'); my $seq = $db->seq("$seqName", $begin => $end); print "$seq\n"; } close(POSITIONS);2480 days ago
Genetic Algorithms demonstration with word DNA in Perl
...entry_length } map { uc } @dictionary; # build the letter frequencies hash (remember, all letters are uppercase) $freqs{$_}++ foreach split '', join '', @dictionary;...2383 days ago
Perl script for calculate Levenshtein distance
sub levenshtein_dist { my ($str1, $str2) = @_; my ($len1, $len2) = (length $str1, length $str2); if ($len1 == 0) { return $len2; } if ($len2 == 0) { return $len1; } my %mat; for (my $i = 0; $i2352 days ago
Reformat the file names with Perl
...e =~ /^#/; #next if $. == 1; my ($lichenName, $name, $code) = split /\s+/, $line; next unl...e by one for (0..$#files){ $files[$_] =~ s/\.scf$//; my @pName = split /\_/, $files[$_]; next if...2347 days ago
Insert the sequence at desire location in multi-fasta file with Perl
#!/usr/bin/perl use warnings; use strict; use Bio::SeqIO; use Bio::Seq; use File::Copy; #ARGV[0] should be in following format --- Keep the coordinate sorted...2325 days ago