Hello Monks... I have a gene that is present in the genome in reverse complement, but the SNPs were described as though it was in standard 5' to 3' format. I'm trying to write a script that will change instances of "A" "C" "G" "T" in a tab delimited txt infile (from Excel) into "T" "G" "C" "A" in an output file while keeping the first column (the rows identifying all of the samples) and column headers (identifying all positions where SNPs occur) the same... I've not been very successful... here's what I have. Please bear with me as I'm very new to programming (and even the command line for that matter!) Thanks!
#!usr/bin/perl
use strict;
use warnings;
my $infile = "xxx_capillary_SNPs.txt\n"; #I'm identifying the file I w
+ant to open
open $infile = <STDIN> || die "open infile failed\n"; #opening the inp
+ut file
chomp ($infile); #I'm trying to keep the first column and header rows
+of the file I'm opening for use in the output file
my $A = 'T'; #change A to T
my $C = 'G'; #change C to G
my $G = 'G'; #change G to C
my $T = 'A'; #change T to A
{
open $outfile = "$file + _revcomp\n" || die "open outfile failed\n"; #
+I want to make a new file entitled "xxx_capillary_SNPs_revcomp.txt as
+ the outputfile
print $A, $C, $G, $T to
}
print $outfile "\n";
close $infile
close $outfile;
print "script complete\n";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.