jamescasbon/PyVCF — pull request #128 by martijnvermaat (2013-11-16 20:45:59+00:00)
Title: Do not maintain the order of INFO fields within records

Using an ordinary dict instead of an OrderdDict for the INFO fields makes parsing faster. The INFO fields are sorted by the VCF writer where all fields defined in the VCF header go first and in the same order, followed by the remaining fields in alpabetical order. Note that this make writing slower.

We lose two things:

1. Getting the INFO fields from a record when using PyVCF as a library, but I don't think most users are expecting this anyway.
2. Preserving the original order of the INFO fields, but we are predictable.

The following are some simple benchmarks, starting with just parsing:

1. Without this change (using OrderedDict):

```
In [1]: %timeit list(vcf.Reader(open('vcf/test/1kg.sites.vcf')))
100 loops, best of 3: 15 ms per loop
```

2. With this change (using dict):

```
In [1]: %timeit list(vcf.Reader(open('vcf/test/1kg.sites.vcf')))
100 loops, best of 3: 10 ms per loop
```

Now parsing the same file and writing it back to VCF:

1. Without this change (using OrderedDict, no sorting):

```
In [1]: %%timeit
...: reader = vcf.Reader(open('vcf/test/1kg.sites.vcf'))
...: writer = vcf.Writer(open(os.devnull, 'w'), reader)
...: for record in reader:
...: writer.write_record(record)
...:
10 loops, best of 3: 22.7 ms per loop
```

2. With half this change (using dict, no sorting):

```
In [1]: %%timeit
...: reader = vcf.Reader(open('vcf/test/1kg.sites.vcf'))
...: writer = vcf.Writer(open(os.devnull, 'w'), reader)
...: for record in reader:
...: writer.write_record(record)
...:
100 loops, best of 3: 16.5 ms per loop
```

3. With this change (using dict, sorting during write):

```
In [6]: %%timeit
...: reader = vcf.Reader(open('vcf/test/1kg.sites.vcf'))
...: writer = vcf.Writer(open(os.devnull, 'w'), reader)
...: for record in reader:
...: writer.write_record(record)
...:
100 loops, best of 3: 17.7 ms per loop
```

This should fix #96.