Sponsored Content
Top Forums Shell Programming and Scripting Parse tab delimited file, check condition and delete row Post 302702517 by empyrean on Tuesday 18th of September 2012 12:21:02 PM
Old 09-18-2012
Parse tab delimited file, check condition and delete row

I am fairly new to programming and trying to resolve this problem. I have the file like this.

CHROM POS REF ALT 10_sample.bam 11_sample.bam 12_sample.bam 13_sample.bam 14_sample.bam 15_sample.bam 16_sample.bam
tg93 77 T C T T T T T
tg93 79 C - C C C - -
tg93 79 C G C C C C G C
tg93 80 G A G G G G A A G
tg93 81 A C A A A A C C C
tg93 86 C A C C A A A A C
tg93 105 A G A A A A A G A
tg93 108 A G A A A A G A A
tg93 114 T C T T T T T C T
tg93 131 A C A A A A A A A
tg93 136 G C C G C C G G G
tg93 150 CTCTC - CTCTC - CTCTC CTCTC
In this file, in the heading

CHROM - name POS - position REF - reference ALT - alternate 10 - 16_sample.bam - samplesd I Now i wanted to see how many times the letter in REF and ALT column occured. If either of them is repeated less than two times, i need to delete that row. For example In the first row, i have 'T' in REF and 'C' in ALT . I see in 7 samples, there are 5 T's and 2 blanks and no C. So i need to delete this row. In Second row, REF is 'C' and Alt is '-'. Now in seven samples we have 3 C's, 2 '-'s and 2 blanks. So we keep this row as C and - have repeated more than 2 times. Always we ignore the blanks while counting

The final file after filtering is

#CHROM POS REF ALT 10_sample.bam 11_sample.bam 12_sample.bam 13_sample.bam 14_sample.bam 15_sample.bam 16_sample.bam
tg93 79 C - C C C - -
tg93 80 G A G G G G A A G
tg93 81 A C A A A A C C C
tg93 86 C A C C A A A A C
tg93 108 A G A A A A G A A
tg93 136 G C C G C C G G G
I am able to read the columns in to arrays and display them in the code but i am not sure how to start the loops to read the base and count their occurences and remain the column. Can anyone tell me how i should be proceeding with this? Or it will be helpful if you have any example code i can modify up on.

Thank you for the help !!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check whether a given file is in ASCII format and data is tab-delimited

Hi All, Please help me out with a script which checks whether a given file say abc.txt is in ASCII format and data is tab-delimited. If the condition doesn't satisfy then it should generate error code "100" for file not in ASCII format and "105" if it is not in tab-delimited format. If the... (9 Replies)
Discussion started by: Mandab
9 Replies

2. Shell Programming and Scripting

Delete parts of a string of character in one given column of a tab delimited file

I would like to remove characters from column 7 so that from an input file looking like this: >HWI-EAS422_12:4:1:69:89 GGTTTAAATATTGCACAAAAGGTATAGAGCGT U0 1 0 0 ref_chr8.fa 6527777 F DD I get something like that in an output file: ... (13 Replies)
Discussion started by: matlavmac
13 Replies

3. Shell Programming and Scripting

Delete first column in tab-delimited text-file

I have a large text-file with tab-delimited genetic data that looks like: KSC112 KSC234 0 0 1 1 A G C T I simply wan to delete the first column, but since the file has 600 000 columns, it is not possible with awk (seems to be limited at 32k columns). Does anyone have an idea how to do this? (2 Replies)
Discussion started by: andmal
2 Replies

4. UNIX for Dummies Questions & Answers

How do you delete cells from a space delimited text file given row and column number?

How do you delete cells from a space delimited text file given row and column number? Letś say the row number is r and the column number is c. Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

5. UNIX for Dummies Questions & Answers

Delete header row and reformat from tab delimited to fixed width

Hello gurus, I have a file in a tab delimited format and a header row. I need a code to delete the header in the file, and convert the file to a fixed width format, with all the columns aligned. Below is a sample of the file:... (4 Replies)
Discussion started by: chumsky
4 Replies

6. Shell Programming and Scripting

Delete an entire column from a tab delimited file

Hi, Can anyone please tell me about how we can delete an entire column from a tab delimited file? Mu input_file.txt looks like this: And I want the output as: I used the below code nawk -v d="1" 'BEGIN{FS=OFS="\t"}{$d=""}{print}' input_file.txtBut in the output, the first column is... (5 Replies)
Discussion started by: sampoorna
5 Replies

7. Shell Programming and Scripting

Delete and insert columns in a tab delimited file

Hi all , I have a file having 12 columns tab delimited . I need to read this file and remove the column 3 and column 4 and insert a word in column 3 as "AVIALABLE " Is there a way to do this . I am trying like below Thanks DJ cat $FILENAME|awk -F"\t" '{ print $1 "\t... (3 Replies)
Discussion started by: Hypesslearner
3 Replies

8. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

9. UNIX for Beginners Questions & Answers

awk to parse current and next row in tab-delimited file

Hi there, I would like to use awk to reformat a tab-delimited file containing three columns as follows: Data file: sample 1 173 sample 269 530 sample 687 733 sample 1699 1779 Desired output file: sample 174..265, 531..686, 734..1698 I need the value... (5 Replies)
Discussion started by: emiley
5 Replies

10. UNIX for Beginners Questions & Answers

Replace a column in tab delimited file with column in other tab delimited file,based on match

Hello Everyone.. I want to replace the retail col from FileI with cstp1 col from FileP if the strpno matches in both files FileP.txt ... (2 Replies)
Discussion started by: YogeshG
2 Replies
Config::BaseConfigurator(3)				User Contributed Perl Documentation			       Config::BaseConfigurator(3)

NAME
Log::Log4perl::Config::BaseConfigurator - Configurator Base Class SYNOPSIS
This is a virtual base class, all configurators should be derived from it. DESCRIPTION
METHODS "new" Constructor, typically called like my $config_parser = SomeConfigParser->new( file => $file, ); my $data = $config_parser->parse(); Instead of "file", the derived class "SomeConfigParser" may define any type of configuration input medium (e.g. "url => 'http://foobar'"). It just has to make sure its "parse()" method will later pull the input data from the medium specified. The base class accepts a filename or a reference to an array of text lines: "file" Specifies a file which the "parse()" method later parses. "text" Specifies a reference to an array of scalars, representing configuration records (typically lines of a file). Also accepts a simple scalar, which it splits at its newlines and transforms it into an array: my $config_parser = MyYAMLParser->new( text => ['foo: bar', 'baz: bam', ], ); my $data = $config_parser->parse(); If either "file" or "text" parameters have been specified in the constructor call, a later call to the configurator's "text()" method will return a reference to an array of configuration text lines. This will typically be used by the "parse()" method to process the input. "parse" Virtual method, needs to be defined by the derived class. Parser requirements o If the parser provides variable substitution functionality, it has to implement it. o The parser's "parse()" method returns a reference to a hash of hashes (HoH). The top-most hash contains the top-level keywords ("category", "appender") as keys, associated with values which are references to more deeply nested hashes. o The "log4perl." prefix (e.g. as used in the PropertyConfigurator class) is stripped, it's not part in the HoH structure. o Each Log4perl config value is indicated by the "value" key, as in $data->{category}->{Bar}->{Twix}->{value} = "WARN, Logfile" EXAMPLES The following Log::Log4perl configuration: log4perl.category.Bar.Twix = WARN, Screen log4perl.appender.Screen = Log::Log4perl::Appender::File log4perl.appender.Screen.filename = test.log log4perl.appender.Screen.layout = Log::Log4perl::Layout::SimpleLayout needs to be transformed by the parser's "parse()" method into this data structure: { appender => { Screen => { layout => { value => "Log::Log4perl::Layout::SimpleLayout" }, value => "Log::Log4perl::Appender::Screen", }, }, category => { Bar => { Twix => { value => "WARN, Screen" } } } } For a full-fledged example, check out the sample YAML parser implementation in "eg/yamlparser". It uses a simple YAML syntax to specify the Log4perl configuration to illustrate the concept. SEE ALSO
Log::Log4perl::Config::PropertyConfigurator Log::Log4perl::Config::DOMConfigurator Log::Log4perl::Config::LDAPConfigurator (tbd!) COPYRIGHT AND LICENSE
Copyright 2002-2009 by Mike Schilli <m@perlmeister.com> and Kevin Goess <cpan@goess.org>. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.1 2010-02-07 Config::BaseConfigurator(3)
All times are GMT -4. The time now is 10:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy