Add coordinates to line of output extracted from input file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add coordinates to line of output extracted from input file
# 1  
Old 11-26-2017
Add coordinates to line of output extracted from input file

I am trying to compare/confirm the output of an script using the perl below, which does execute. However I can not seem to print $1 and $2 in each line of the input separated by a tab in each line of the output. The input file is quite large so I have only included a portion, but the format is the same. Thank you Smilie.


perl
Code:
#!/usr/bin/perl   # execute perl script

 use strict;
 use warnings;
 use Vcf;

 my $filename = $ARGV[0];

 open ( my $handle, "<", $filename);
 my $vcf = Vcf->new(fh=>$handle);
 $vcf->parse_header();
 vcf_iterate();

 sub vcf_iterate
 {
 while ( my $x=$vcf->next_data_hash() )
 {
 foreach my $sample ( keys $$x{gtypes} )
 {
 print "SAMPLE=$sample, genotype_raw=$$x{gtypes}{$sample}{GT}, ";
 my $decoded_genotype = decode_genotype($x, $sample);
 print "decoded_genotype=$decoded_genotype\n";
   }
  }
}

sub decode_genotype
{
my ( $x, $sample ) = ( $_[0], $_[1] );
my $gt = $vcf->decode_genotype($$x{REF}, $$x{ALT}, $$x{gtypes}{$sample}{GT}); # returns 'G/G'
return $gt;
 }

current output
Code:
SAMPLE=MEC1, genotype_raw=0/1, decoded_genotype=G/A
SAMPLE=MEC1, genotype_raw=1/1, decoded_genotype=G/G
SAMPLE=MEC1, genotype_raw=0/1, decoded_genotype=T/C
SAMPLE=MEC1, genotype_raw=0/1, decoded_genotype=A/G
SAMPLE=MEC1, genotype_raw=0/1, decoded_genotype=T/C

desired output
Code:
             $1  tab   $2,
SAMPLE=MEC1, chr1   949608, genotype_raw=0/1, decoded_genotype=G/A
SAMPLE=MEC1, chr1   949654, genotype_raw=1/1, decoded_genotype=G/G
SAMPLE=MEC1, chr1   977330, genotype_raw=0/1, decoded_genotype=T/C
SAMPLE=MEC1, chr1   981931, genotype_raw=0/1, decoded_genotype=A/G
SAMPLE=MEC1, chr1   982994, genotype_raw=0/1, decoded_genotype=T/C

input
Code:
##fileformat=VCFv4.1
....
....
....
##INFO=<ID=OREF,Number=.,Type=String,Description="List of original reference bases">
##INFO=<ID=OALT,Number=.,Type=String,Description="List of original variant bases">
##INFO=<ID=OMAPALT,Number=.,Type=String,Description="Maps OID,OPOS,OREF,OALT entries to specific ALT alleles">
##deamination_metric=0.183561
#CHROM  POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  MEC1
chr1    949608  .   G   A   852.727 PASS    .   .
chr1    949654  .   A   G   3815.58 PASS    .   .
chr1    977330  .   T   C   261.147 PASS    .   .
chr1    981931  .   A   G   352.821 PASS    .   .
chr1    982994  .   T   C   496.098 PASS    .   .


Last edited by cmccabe; 11-26-2017 at 09:14 PM.. Reason: fixed format
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to add unique prefix to extracted zip folder

In the bash below in each .zip there is a folder to be extracted Variants that I am trying to make unique by adding the prefix, before the _ from the .zip. The script does execute, but the prefix is not added to the extracted folder. Rather the Variants folder is added to each file within it. Thank... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

Reducing the decimal points of numbers (3d coordinates) in a file; how to input data to e.g. Python

I have a file full of coordinates of the form: 37.68899917602539 58.07500076293945 57.79100036621094 The numbers don't always have the same number of decimal points. I need to reduce the decimal points of all the numbers (there are 128 rows of 3 numbers) to 2. I have tried to do this... (2 Replies)
Discussion started by: crunchgargoyle
2 Replies

3. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

4. Shell Programming and Scripting

Print output and read input on same line

How do I print output and read input on the same line in ksh? echo Hello, what is your name? read name (1 Reply)
Discussion started by: robin_simple
1 Replies

5. Shell Programming and Scripting

Two Input Lines Into Single Output Line (CSV)

Hi all, My search karate must be weak because I'm about certain something very like this has been asked and answered here many times. I'll give you the exact scenario I've wasted a few hours of my Saturday on: :wall: I'm trying to read through a very large number (~200) of router and... (28 Replies)
Discussion started by: svermill
28 Replies

6. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

7. Shell Programming and Scripting

How to add data from 2 input files and save it in 1 output file

Hi, i have 2 input files which are file1.txt and file2.txt. I need to extract data from file1.txt and file2.txt and save it in file3.txt like example below:- File1.txt ID scrap1 Name scrap1 start 1 end 10 ID scrap2 Name scrap2 start 11 end ... (4 Replies)
Discussion started by: redse171
4 Replies

8. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

9. UNIX for Dummies Questions & Answers

add new lines of text before and after each input line

I have a file that contains hundreds of lines such as: this_is_macro,000001 this_is_macro,000002 this_is_macro,000003 I would like to add the variable words MACROBEGIN MACRO_000001 MACROBEGIN MACRO_000002 MACROBEGIN MACRO_000003 above each line and add the word MACROEND ... (2 Replies)
Discussion started by: kenneth.mcbride
2 Replies

10. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies
Login or Register to Ask a Question