-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfastq2fasta.pl
88 lines (65 loc) · 1.93 KB
/
fastq2fasta.pl
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
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/perl
use strict;
use warnings;
#use Cwd;
##### ##### ##### ##### #####
use Getopt::Std;
use vars qw( $opt_a $opt_c $opt_v);
# Usage
my $usage = "
fastq2fasta.pl - converts fastq files to fasta format.
by
Brian J. Knaus
December 2009
Copyright (c) 2009 Brian J. Knaus.
License is hereby granted for personal, academic, and non-profit use.
Commercial users should contact the author (http://brianknaus.com).
Great effort has been taken to make this software perform its said
task however, this software comes with ABSOLUTELY NO WARRANTY,
not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Usage: perl script.pl options
required:
-a fastq input file.
optional:
-c inset in nucleotides, used to remove barcodes [default = 0].
-v verbose mode [T/F, default is F].
";
# command line processing.
getopts('a:c:v:');
die $usage unless ($opt_a);
my ($inf, $inset, $verb);
$inf = $opt_a if $opt_a;
$inset = $opt_c ? $opt_c : 0;
$verb = $opt_v ? $opt_v : "F";
##### ##### ##### ##### #####
# Globals.
my ($temp, $in, $out, $outf);
my @temp;
##### ##### ##### ##### #####
# Manage outfile name.
@temp = split(/\//, $inf);
$temp = $temp[$#temp];
@temp = split(/\./, $temp);
$outf = $temp[0];
##### ##### ##### ##### #####
# Main.
# Open input and output files.
open( $in, "<", $inf) or die "Can't open $inf: $!";
open( $out, ">", $outf.".fa") or die "Can't open $outf.fa: $!";
while (<$in>){
chomp($temp[0] = $_); # First line is an id.
chomp($temp[1] = <$in>); # Second line is a sequence.
chomp($temp[2] = <$in>); # Third line is an id.
chomp($temp[3] = <$in>); # Fourth line is quality.
# Prune first char.
$temp[0] = substr($temp[0], 1);
# Substring to inset value.
$temp[1] = substr($temp[1], $inset);
# Print to fasta file.
print $out ">$temp[0]\n";
print $out "$temp[1]\n";
}
close $in or die "$in: $!";
close $out or die "$out: $!";
##### ##### ##### ##### #####
# EOF.