11th June 2009
There is no way I’m aware of to do what the title says. However…
I’m sure that you are aware of the fact that floats representation in any programming language is limited by the precision of the internal binary representations. In other words, you can never have an exact float representation – there will always be some precision associated with the float you are working with. The simplest example is the difference in precision between the float and double types in C.
Suppose I have the following code fragment:
[C] if ( result.score >= input->raw_cut_off ) [/C]
Both result.score and input->raw_cut_off are of type float, and can have positive and negative values. When compared with the greater than or equal ( >= ) operator, it is not always that condition is true – for the precision reasons shortly mentioned above.
As I already said, there is no precision specification for equality operators in C. But it is quite simple to “invent” precision specification; e.g. if I wanted to test for equality only, I could write
[C] if ( fabsf( result.score – input->raw_cut_off ) < 0.000001 )[/C]
In this example, I'm effectively asking for 6-digit precision for the equality comparison of floating-point values. Note, that if you replace that 0.000001 with the actual precision limit of the floating type you are using, you will be "exactly" comparing floating-point numbers - up to that type's precision, of course .
The first-most example with the >= operator can be rewritten as
[C] if ( result.score > ( input->raw_cut_off – precision) ) [/C]
where precision is exactly what it is named, e.g. precision = 0.000001.
Sources used:
Posted in how-to, Programming | No Comments »
12th April 2008
Posted in Software | 4 Comments »
18th October 2007
To start: as of the latest MySQL, syntax presented in the title is not possible. But there are several very easy ways to accomplish what is expected using existing functionality.
There are 3 possible solutions: using INSERT IGNORE, REPLACE, or INSERT … ON DUPLICATE KEY UPDATE.
Imagine we have a table:
CREATE TABLE `transcripts` (
`ensembl_transcript_id` varchar(20) NOT NULL,
`transcript_chrom_start` int(10) unsigned NOT NULL,
`transcript_chrom_end` int(10) unsigned NOT NULL,
PRIMARY KEY (`ensembl_transcript_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Now imagine that we have an automatic pipeline importing transcripts meta-data from Ensembl, and that due to various reasons the pipeline might be broken at any step of execution. Thus, we need to ensure two things: 1) repeated executions of the pipeline will not destroy our database, and 2) repeated executions will not die due to ‘duplicate primary key’ errors.
Method 1: using REPLACE
Read the rest of this entry »
Posted in Programming | 46 Comments »
26th September 2007
These are all excerpts from the Python documentation.
To synchronously and simultaneously loop over two sequences:
questions = ['name', 'quest', 'favourite colour']
answers = ['Lancelot', 'the holy grail', 'blue']
for q, a in zip(questions, answers):
print 'What is your %s? It is %s.' % (q, a)
To loop over a sequence with both key and value:
Read the rest of this entry »
Posted in Programming, Python | No Comments »
26th September 2007
Sample script (copypasted from Well House Consultants training course):
click the PLAIN TEXT header for copy-pasteable version
#!/usr/local/bin/python
author = {"php":"Rasmus Lerdorf",\
"perl":"Larry Wall",\
"tcl":"John Ousterhout",\
"awk":"Brian Kernighan",\
"java":"James Gosling",\
"parrot":"Simon Cozens",\
"python":"Guido van Rossum"}
langs = author.keys()
langs.sort()
for language in langs:
print language,"is the child of",author[language]
You can also define the Python ksort() function similar to that found in PHP:
Read the rest of this entry »
Posted in Programming, Python | 1 Comment »