Sponsored Content
Full Discussion: awk logic and math help
Top Forums UNIX for Dummies Questions & Answers awk logic and math help Post 302579785 by wyarosh on Tuesday 6th of December 2011 02:42:27 PM
Old 12-06-2011
Thanks agama. Your code helped a lot. I should have been more specific about the details of my file. It contains multiple variableStep headers after a few hundred thousand lines of the two number fields. I also forgot to mention that I was also trying to export my data with tab separations instead of spaces. I made some minor changes and the program works pretty well, but for some reason the appearance of the tabs I tried to put in with \t isn't consistent. I still want to figure out if I can make the fields consistent. Here is the code I have now.
Code:
echo Enter the name of the file without the .wig
read NAME
echo Thanks, inserting zeros

awk -v cord=${cord:-25} '{if($1 == "variableStep") {print $0} else
    {
        if( $1 > last+cord)
            for( i = last+cord; i < $1; i+= cord )
                printf( "%d\t0\n", i"\t" );
        printf( "%s %s\n", $1, "\t" $2 );
        last = $1;
    }}
' ${NAME}.wig > ${NAME}zeros.wig

Code:
6466951     0.316587
6466976     0.5952
6467001     0.2976
6467026     0.2976
6467051     0.2976
6467076     0.437651
6467101    0
6467126    0
6467151    0
6467176    0
6467201    0
6467226    0
6467251    0
6467276    0
6467301    0
6467326    0
6467351    0

Edit
Okay, for some reason the forum spaces all the fields the same distance apart, but in the file the space between $1 and $2 isn't consistent.

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 12-07-2011 at 05:51 AM.. Reason: Please use code tags for code and data samples, thank you
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk math operation on two files

Hi, I need your help. I've got two files and i need to add 2nd line after occurrence of "Group No X" from data2.txt to 3rd line (after occurrence of "Group No X") from data1.txt. There is the same number of "Groups" in both files and the numbers of groups have the same pattern. data1.txt Group... (2 Replies)
Discussion started by: killerbee
2 Replies

2. Shell Programming and Scripting

Need help with AWK math

I am trying to do some math, so that I can compare the average of six numbers to a variable. Here is what it looks like (note that when I divide really big numbers, it isn't a real number): $ tail -n 6 named.stats | awk -F\, '{print$1}' 1141804 1140566 1139429 1134210 1084682 895045... (3 Replies)
Discussion started by: brianjb
3 Replies

3. Shell Programming and Scripting

awk math and csv output

Hi I have this list 592;1;Z:\WB\DOCS;/FS3_100G/FILER112/BU/MPS/DOCS;;;;\\FILER112\BUMPS-DOCS\;580,116,544,878 Bytes;656,561 ;77,560 592;2;Z:\WB\FOCUS;/FS3_100G/FILER112/BU/MPS/FOCUS;;;;\\FILER112\BUMPS-FOCUS\;172,430 Bytes;6 ;0 ... (12 Replies)
Discussion started by: nakaedu
12 Replies

4. Shell Programming and Scripting

How to use this logic with awk?

Hi friends, I am having 2 files, I just want to compare 2 files each containing 2 columns 1st column is lat, and 2nd column is long, if anyone can understand below logic please help me in writing script with awk.. here each field of file2 needs to be compared with std_file main counter=0... (1 Reply)
Discussion started by: Akshay Hegde
1 Replies

5. Shell Programming and Scripting

awk in horizontal and vertical math

Based on input ail,UTT,id1_0,COMBO,21,24,21,19,85 al,UTHAST,id1_0,COMBO,342,390,361,361,1454 and awk code as awk -F, '{ K=0; for(i=NF; i>=(NF-4); i--) { K=K+$i; J=J+$i;} { print K } } END { for ( l in J ) printf("%s ",J); }' I'm trying to add columns and lines in single line. line... (6 Replies)
Discussion started by: busyboy
6 Replies

6. Shell Programming and Scripting

awk evaluating a string as a math expression

Hi, I am writing a script in awk trying to replace strings that are math expressions with their result. For example, I have a file that looks like this: 5-1 32/8-1 4*12 17+1-3 I would like to get the following output: 4 3 48 15 I tried doing it the following way (using the "bc"... (8 Replies)
Discussion started by: avi.levi
8 Replies

7. Shell Programming and Scripting

awk --> math-operation in a array

Hi main object is categorize the difference of data-values (TLUFT02B - TLUFT12B). herefor i read out data-files which are named acording to the timeformat yyyymmddhhmm. WR030B 266.48 Grad 0 WR050B 271.46 Grad 0 WR120B 268.11 Grad 0 WV030B 2.51 m/s ... (6 Replies)
Discussion started by: IMPe
6 Replies

8. Shell Programming and Scripting

Count math using awk

Hi expert, I have log : TOTAL-TIME : 2125264636 DATA-BYTES-DOWN : 3766111307032 DATA-BYTES-UP : 455032157567 DL = (3766111307032/2125264636)/1024 = 1.73 UL = (455032157567/2125264636)/1024 = 0.21 I want the result : TOTAL = 1.94 ... (4 Replies)
Discussion started by: justbow
4 Replies

9. Shell Programming and Scripting

Math count %memory using awk

Hi expert, i have log this: Memory: 74410384 Memory: 75831176 Memory: 77961232 Memory: 77074656 Memory: 76086160 Memory: 77128592 Memory: 78045384 Memory: 76696040 Memory: 72401176 Memory: 72520016 Memory: 72137016 Memory: 73175832 Memory: 73034528 Memory: 71770736 Memory:... (4 Replies)
Discussion started by: justbow
4 Replies

10. Shell Programming and Scripting

[awk] Math & Bold-Font?

Heya There is a script which has presets stored in a tab-seperated file. That script also has $help_text, which will be shown when called with invalid arguments or -h. So i do need to have that file ready, so the help text can get the values out of the file, and print it with the $help_text.... (17 Replies)
Discussion started by: sea
17 Replies
Bio::Graphics::Wiggle(3pm)				User Contributed Perl Documentation				Bio::Graphics::Wiggle(3pm)

NAME
Bio::Graphics::Wiggle -- Binary storage for dense genomic features SYNOPSIS
# all positions are 1-based my $wig = Bio::Graphics::Wiggle->new('./test.wig', $writeable, { seqid => $seqid, start => $start, step => $step, min => $min, max => $max }); $wig->erase; my $seqid = $wig->seqid('new_id'); my $max = $wig->max($new_max); my $min = $wig->min($new_min); my $step = $wig->step($new_step); # data stored at modulus step == 0; all else is blank $wig->set_value($position => $value); # store $value at position $wig->set_values($position => @values); # store array of values at position $wig->set_range($start=>$end,$value); # store the same $value from $start to $end my $value = $wig->value($position); # fetch value from position my $values = $wig->values($start,$end); # fetch range of data from $start to $end $wig->window(100); # sample window size $wig->smoothing('mean'); # when sampling, compute the mean value across sample window my $values = $wig->values($start,$end,$samples); # fetch $samples data points from $start to $end DESCRIPTION
IMPORTANT NOTE: This implementation is still not right. See http://genomewiki.ucsc.edu/index.php/Wiggle for a more space-efficient implementation. This module stores "wiggle" style quantitative genome data for display in a genome browser application. The data for each chromosome (or contig, or other reference sequence) is stored in a single file in the following format: 256 byte header 50 bytes seqid, zero-terminated C string 4 byte long integer, value of "step" (explained later) 4 byte perl native float, the "min" value 4 byte perl native float, the "max" value 4 byte long integer, value of "span" 4 byte perl native float, the mean 4 byte perl native float, the standard deviation 2 byte unsigned short, the version number (currently version 0) 4 byte long integer, sequence start position (in 0-based coordinates) null padding to 256 bytes for future use The remainder of the file consists of 8-bit unsigned scaled integer values. This means that all quantitative data will be scaled to 8-bit precision! For a convenient method of creating Wiggle files from UCSC-type WIG input and creating GFF3 output, please see Bio::Graphics::Wiggle::Loader. METHODS
Constructor and Accessors $wig = Bio::Graphics::Wiggle->new($filename,$writeable,{options}) Open/create a wiggle-format data file: $filename -- path to the file to open/create $writeable -- boolean value indicating whether file is writeable. Missing files will only be created if $writeable set to a true value. If path is empty (undef or empty string) and writeable is true, new() will create a temporary file that will be deleted when the object goes out of scope. {options} -- hash ref of the following named options, only valid when creating a new wig file with $writeable true. option name description default ----------- ----- ------- seqid name/id of sequence empty name min minimum value of data points 0 max maximum value of data points 255 step interval between data points 1 span width of data points value of "step" The "step" can be used to create sparse files to save space. By default, step is set to 1, in which case a data value will be stored at each base of the sequence. By setting step to 10, then each value is taken to correspond to 10 bp, and the file will be 10x smaller. For example, consider this step 5 data set: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 20 . . . . 60 . . . . 80 . . . We have stored the values "20" "60" and "80" at positions 1, 6 and 11, respectively. When retrieving this data, it will appear as if positions 1 through 5 have a value of 20, positions 6-10 have a value of 60, and positions 11-14 have a value of 80. In the data file, we store, positions 1,6,and 11 in adjacent bytes. Note that no locking is performed by this module. If you wish to allow multi-user write access to the databases files, you will need to flock() the files yourself. $seqid = $wig->seqid(['new_id']) $max = $wig->max([$new_max]) $min = $wig->min([$new_min]) $step = $wig->step([$new_step]) $span = $wig->span([$new_span]) $mean = $wig->mean([$new_mean]); $stdev = $wig->stdev([$new_stdev]); These accessors get or set the corresponding values. Setting is only allowed if the file was opened for writing. Note that changing the min, max and step after writing data to the file under another parameter set will produce unexpected (and invalid) results, as the existing data is not automatically updated to be consistent. $trim = $wig->trim([$new_trim]); The trim method sets the trimming method, which can be used to trim out extreme values. Three methods are currently supported: none No trimming stdev Trim 1 standard deviation above and below mean stdevN Trim N standard deviations above and below the mean In "stdevN", any can be any positive integer. Setting Data $wig->set_value($position => $value) This method sets the value at $position to $value. If a step>1 is in force, then $position will be rounded down to the nearest multiple of step. $wig->set_range($start=>$end, $value) This method sets the value of all bases between $start and $end to $value, honoring step. $sig->set_values($position => @values) This method writes an array of values into the datababase beginning at $position (or the nearest lower multiple of step). If step>1, then values will be written at step intervals. Retrieving Data $value = $wig->value($position) Retrieve the single data item at position $position, or the nearest lower multiple of $step if step>1. $values = $wig->values($start=>$end) Retrieve the values in the range $start to $end and return them as an array ref. Note that you will always get an array of size ($end-$start+1) even if step>1; the data in between the step intervals will be filled in. $values = $wig->values($start=>$end,$samples) Retrieve a sampling of the values between $start and $end. Nothing very sophisticated is done here; the code simply returns the number of values indicated in $samples, smoothed according to the smoothing method selected (default to "mean"), then selected at even intervals from the range $start to $end. The return value is an arrayref of exactly $samples values. $string = $wig->export_to_wif($start,$end) $string = $wig->export_to_wif64($start,$end) Export the region from start to end in the "wif" format. This data can later be imported into another Bio::Graphics::Wiggle object. The first version returns a binary string. The second version returns a base64 encoded version that is safe for ascii-oriented formata such as GFF3 and XML. $wig->import_from_wif($string) $wig->import_from_wif64($string) Import a wif format data string into the Bio::Graphics::Wiggle object. The first version expects a binary string. The second version expects a base64 encoded version that is safe for ascii-oriented formata such as GFF3 and XML. SEE ALSO
Bio::Graphics::Wiggle::Loader, Bio::Graphics::Panel, Bio::Graphics::Glyph, Bio::Graphics::Feature, Bio::Graphics::FeatureFile AUTHOR
Lincoln Stein <lstein@cshl.org>. Copyright (c) 2007 Cold Spring Harbor Laboratory This package and its accompanying libraries is free software; you can redistribute it and/or modify it under the terms of the GPL (either version 1, or at your option, any later version) or the Artistic License 2.0. Refer to LICENSE for the full license text. In addition, please see DISCLAIMER.txt for disclaimers of warranty. perl v5.14.2 2012-02-20 Bio::Graphics::Wiggle(3pm)
All times are GMT -4. The time now is 10:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy