comparison qseq2fastq/qseq2fastq.pl @ 0:6682236a1432 default tip

Migrated tool version 0.2 from old tool shed archive to new tool shed repository
author vipints
date Tue, 07 Jun 2011 17:42:46 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6682236a1432
1 #!/usr/bin/perl -w
2 use strict;
3 use Carp;
4
5 my $usage = q(
6 qseq2fastq.pl - a script to convert all qseq files in a directory into a single fastq file with sanger-style ASCII q-score encoding
7 USAGE: qseq2fastq.pl <qseq.txt file> <output file>
8 );
9
10 if (scalar(@ARGV) != 2) {
11 print $usage;
12 exit;
13 }
14
15 my $in_file = $ARGV[0];
16 my $output_fastq_file = $ARGV[1];
17
18 my $qfilter = "";
19 open(OUTFASTAQFILE, "> $output_fastq_file");
20
21 open INFILE, "< $in_file" || die "Error: Couldn't open $in_file\n";
22 while(<INFILE>)
23 {
24 chomp;
25 my @this_line = split/\t/, $_;
26 croak("Error: invalid column number in $in_file\n") unless(scalar(@this_line) == 11);
27 if($this_line[10] == 1) {
28 $qfilter = "Y";
29 } else {
30 $qfilter = "N";
31 }
32 # Convert quality scores
33 my @quality_array = split(//, $this_line[9]);
34 my $phred_quality_string = "";
35 # convert each char to Phred quality score
36 foreach my $this_char (@quality_array){
37 my $phred_quality = ord($this_char) - 64; # convert illumina scaled phred char to phred quality score
38 my $phred_char = chr($phred_quality + 33); # convert phred quality score into phred char (sanger style)
39 $phred_quality_string = $phred_quality_string . $phred_char;
40 }
41 # replace "." gaps with N
42 $this_line[8] =~ s/\./N/g;
43 # output line
44 print OUTFASTAQFILE "@" . $this_line[2] . ":" . $this_line[3] . ":" . $this_line[4] . ":" . $this_line[5] . ":" . $qfilter . "\n" . #header line
45 $this_line[8] . "\n" . # output sequence
46 "+" . $this_line[2] . ":" . $this_line[3] . ":" . $this_line[4] . ":" . $this_line[5] . ":" . $qfilter . "\n" . # header line
47 $phred_quality_string . "\n"; # output quality string
48 }
49 close INFILE;
50 close OUTFASTAQFILE;
51 exit;