Last active
August 29, 2015 14:07
-
-
Save davetang/23a21e26d7ab695113af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my $usage = "Usage: $0 <infile.fa> <number> <length>\n"; | |
my $fasta = shift or die $usage; | |
my $num = shift or die $usage; | |
my $len = shift or die $usage; | |
my $seq = ''; | |
open(IN,'<',$fasta) || die "Could not open $fasta: $!\n"; | |
while(<IN>){ | |
chomp; | |
next if /^>/; | |
$seq .= $_; | |
} | |
close(IN); | |
my $seq_len = length($seq); | |
my $limit = $seq_len - $len + 1; | |
if ($len > $seq_len){ | |
die "Your read length is longer than the input sequence\n"; | |
} | |
my $fake_qual = 'B' x $len; | |
for (1 .. $num){ | |
my $random_start = int(rand($limit)); | |
my $substring = substr($seq,$random_start,$len); | |
my $pos = $random_start + 1; | |
print "\@$_:$pos\n$substring\n+\n$fake_qual\n"; | |
} | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment