Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

trim2.pl (QSEQ)

View trim2.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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
# !/usr/bin/perl -w
#
# Trim2_Illumina.pl
# Written by: David B. Crabb
# Eric Triplett's Group
# University of Florida
# Last Modified: November 30, 2010
###################################################
#
# Parameters:
# -a raw illumina input file read 1
# -b raw illumina input file read 2
#
###################################################
 
$LENGTH_CUTOFF = 70;
$QUALITY_CUTOFF = 20;
$TRUNCATE = 11;
 
# If Length < 70; throw out.
# If throw out 1; then throw out both.
# Delete first 11 on both sides
# Number of reads in each barcode
# Number thrown out
 
use Getopt::Std;
use File::Basename;
 
# PARSE ARGUMENTS
my %parameters;
getopts( 'a:b:', \%parameters ); #Takes parameters
 
unless ( $parameters{a} && $parameters{b} ) {
print "Usage: perl trim2.pl
-a raw illumina input file read 1
-b raw illumina input file read 2\n";
exit;
}
 
$read1 = $parameters{a};
$read2 = $parameters{b};
 
unless ( open( READ1, "$read1" ) ) {
print "Unable to open $read1\n";
exit;
}
 
unless ( open( READ2, "$read2" ) ) {
print "Unable to open $read2\n";
exit;
}
 
@split_out1 = split( /\./, $prefix );
 
$out_dir = dirname($read1);
$prefix = basename($read1);
 
# Make Singletons Directory
system("mkdir -p $out_dir/singletons/");
open SINGLETONS, ">$out_dir/singletons/$prefix" . "_trim_single.txt" or die $!;
 
while ( $read1_line = <READ1> ) {
chomp($read1_line);
chomp( $read2_line = <READ2> );
 
@line1 = split( /\t/, $read1_line );
@line2 = split( /\t/, $read2_line );
 
$line1[8] =~ s/\./N/g;
$line2[8] =~ s/\./N/g;
 
$line1[8] = trim( $line1[8], $line1[9] );
$line2[8] = trim( $line2[8], $line2[9] );
 
$line1[9] = "";
$line2[9] = "";
 
next if ( ( $line1[8] eq "0" ) && ( $line2[8] eq "0" ) );
 
# Print Singletons
if ( $line1[8] eq "0" ) {
print SINGLETONS join( "\t", @line2 ) . "\n";
}
elsif ( $line2[8] eq "0" ) {
print SINGLETONS join( "\t", @line1 ) . "\n";
}
# Or, print entire thing (interleaved QSEQ)
else {
# Print in QSEQ format, uncomment (and comment FASTQ line)
# print join( "\t", @line1 ) . "\n" . join( "\t", @line2 ) . "\n";
 
# Print in FASTQ (interleaved) format:
# TODO shorten this!
$header = join(':', @line1[0..7]);
$sequence_quality = @line1[8];
@sq = split( /\t/, $sequence_quality);
$sequence = @sq[0];
$quality = @sq[1];
print "\@$header:A\n$sequence\n\+$header:A\n$quality\n";
 
$header = join(':', @line2[0..7]);
$sequence_quality = @line2[8];
@sq = split( /\t/, $sequence_quality);
$sequence = @sq[0];
$quality = @sq[1];
print "\@$header:B\n$sequence\n\+$header:B\n$quality\n";
 
}
}
 
close SINGLE1;
close SINGLE2;
 
# trim($seq, $qual);
sub trim() {
$seq = shift;
$qual = shift;
 
#trim off primer
$seq = substr( $seq, $TRUNCATE );
$qual = substr( $qual, $TRUNCATE );
 
$max = 0;
$sum = 0;
$first = 0;
$start = 0;
$end = 0;
@qualities = split( //, $qual );
$size = scalar @qualities;
 
for ( $a = 0 ; $a < $size ; $a++ ) {
$sum += ( ord( $qualities[$a] ) - 64 - $QUALITY_CUTOFF );
if ( $sum > $max ) {
$max = $sum;
$end = $a;
$start = $first;
}
if ( $sum < 0 ) {
$sum = 0;
$first = $a;
}
}
 
$seq = substr( $seq, $start, $end - $start );
return 0 if ( length($seq) < $LENGTH_CUTOFF );
$seq = $seq . "\t" . substr( $qual, $start, $end - $start );
return $seq;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.