-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRandomDNA.pl
More file actions
76 lines (64 loc) · 1.73 KB
/
Copy pathRandomDNA.pl
File metadata and controls
76 lines (64 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
#AUTHORS
# Kaining Hu (c) 201
# Creat a random DNA seq for test v1.0000 2018/03/08
# hukaining@gmail.com
#
use strict;
use warnings;
#use 5.010;
use Getopt::Long;
use Pod::Usage;
use Time::HiRes 'time';
#use Parallel::ForkManager;
#our $MAX_processes=2;
#my $pm=Parallel::ForkManager->new($MAX_processes);
use re 'eval';
our $opfn="";
our $fasheader="randomDNA";
my $verbose;
our $dnal=100;
#our $strict="yes";
GetOptions("o=s" => \$opfn,"verbose"=>\$verbose,"l=i"=>\$dnal,"n=s"=>\$fasheader)
or die("Error in command line arguments\nUsage: perl RandomDNA.pl [options] \n
options:\n
[-o string|output prefix default: rnddna$dnal]\n
[-n string|Add fasta header default: \"randomDNA\" ]\n
[-l int|Length of the DNA. default: $dnal]\n
Note: Creat a random DNA seq for test v1.0000 2018/03/08\n");
chomp $dnal;
if ($dnal<=0) {
die ("[-] Error: Can't creat $dnal bp.\n");
}
#print $ARGV[0],"\n";
#if (not $ARGV[0]) {
#die ("[-] Error: Not find a inputfile.\n");
#}
#my @tmpfliename=@ARGV;
if ($opfn eq ""){
$opfn="rnddna$dnal";
print "Output file: $opfn.fa \nFasta header: $fasheader\n";
}else{
print "Output file: $opfn.fa \nFasta header: $fasheader\n";
}
open OUT, "> $opfn.fa" or die ("[-] Error: Can't open or creat $opfn.fa\n");
print OUT ">$fasheader\n";
our $starttime=time();
#our $tmpseqname="";
our $count1=0;
our $count2=0;
#our $cutseq="";
our $finaldna="";
######main
while($count1<$dnal){
my(@nts)=qw(A T G C);
my $newnt=$nts[rand @nts];
#$finaldna=$finaldna.$newnt;
print OUT "$newnt";
$count1++;
} #while End.
print OUT "\n";
print "Finished Creating a $dnal bp random DNA sequence.\n";
close OUT;
our $endtime=time();
printf "Done! %g Sec %g Min\n",$endtime-$starttime,($endtime-$starttime)/60;