#!/usr/bin/perl # Tninsert_only_sam.pl # By Kathryn Ramsey (ramsey.kathryn.m@gmail.com) # Simon L. Dove Lab, Children's Hospital Boston, Harvard Medical School # March 21, 2018 use strict; use warnings; my ($samfile, $outfile); $samfile = shift @ARGV; unless ($samfile =~ /\.sam$/) {die "Tninsert_only_sam.pl - INPUT ERROR!\n";} if ($samfile =~ /([0-9a-zA-Z_]*).sam/) { $outfile = $1."_TnOnly.sam"; } else { die "Error! I didn't recognize the input well enough to define an output file name. Oops!\n";} open SAM, $samfile or die "Could not open '$samfile': $!\n"; open OUT, ">$outfile" or die "Could not open $outfile': $!\n"; my ($line, @line); my $count = 0; while () { chomp; $line = $_; $count++; if ($count <= 3) { print OUT "$line\n"; } else { @line = split; if ($line[1] == '0') { if ($line[9] =~ /TA$/) { print OUT "$line\n"; } } if ($line[1] == '16') { if ($line[9] =~ /^TA/) { print OUT "$line\n"; } } } } close SAM; close OUT;