diff --git a/README.md b/README.md
index af241af..40f7376 100644
--- a/README.md
+++ b/README.md
@@ -146,6 +146,10 @@ specification keys you can put in a object in the JSON is as follows:
 * `name`: Give a name to the sequence so you can refer to it from elsewhere
   in the JSON. Note that this has nothing to do with FASTA ids, it is just
   an internal name.
+* `name count`: An optional integer specifying which of a set of sequences
+  generated from the same specification should be named (assumes `name`
+  is also given). The default is to name the first sequence. Note that this
+  number is 1-based. Special values `first` and `last` are also allowed.
 * `random aa`: The sequence should be made of random amino acids.
 * `random nt`: The sequence should be made of random nucleotides.
 * `ratchet`: If `true` and a count and mutation rate are given, sequences
diff --git a/seqgen/__init__.py b/seqgen/__init__.py
index 285814d..51d6e92 100644
--- a/seqgen/__init__.py
+++ b/seqgen/__init__.py
@@ -2,6 +2,6 @@ from seqgen.sequences import Sequences
 
 # Note that the version string must have the following format, otherwise it
 # will not be found by the version() function in ../setup.py
-__version__ = '1.0.11'
+__version__ = '1.0.12'
 
 __all__ = ['Sequences']
diff --git a/seqgen/sequences.py b/seqgen/sequences.py
index 3af0d90..b57ba6d 100644
--- a/seqgen/sequences.py
+++ b/seqgen/sequences.py
@@ -32,6 +32,7 @@ class Sequences(object):
         'length',
         'mutation rate',
         'name',
+        'name count',
         'random aa',
         'random nt',
         'ratchet',
@@ -88,6 +89,27 @@ class Sequences(object):
         self._checkValid()
         self._names = {}
 
+    def _nameCount(self, spec):
+        """
+        Get the name count for a spec
+
+        @param spec: A C{dict} with keys/values specifying a sequence.
+        @return: A 0-based integer count of the sequence index that should be
+            named or C{0} if there is no 'name count' directive in C{spec}.
+        """
+        nSequences = spec.get('count', 1)
+        try:
+            nameCount = spec['name count']
+        except KeyError:
+            return 0
+        else:
+            if nameCount == 'first':
+                return 0
+            elif nameCount == 'last':
+                return nSequences - 1
+            else:
+                return nameCount - 1
+
     def _checkValid(self):
         """
         Check that all specification dicts contain sensible values.
@@ -96,6 +118,7 @@ class Sequences(object):
             to be produced.
         @raise ValueError: If any problem is found.
         """
+        names = set()
         for specCount, spec in enumerate(self._sequenceSpecs, start=1):
             if spec.get('ratchet'):
                 nSequences = spec.get('count', 1)
@@ -109,6 +132,27 @@ class Sequences(object):
                         'Sequence specification %d is specified as ratchet '
                         'but does not give a mutation rate.' % specCount)
 
+            nSequences = spec.get('count', 1)
+
+            nameCount = self._nameCount(spec)
+            if nameCount is not None and nameCount >= nSequences:
+                raise ValueError(
+                    'Sequence specification %d will only produce %d '
+                    'sequence%s but has a (too high) name count value of %d.' %
+                    (specCount, nSequences, '' if nSequences == 1 else 's',
+                     nameCount + 1))
+
+            try:
+                name = spec['name']
+            except KeyError:
+                pass
+            else:
+                if name in names:
+                    raise ValueError("Name '%s' is duplicated in the JSON "
+                                     "specification." % name)
+                else:
+                    names.add(name)
+
     def _checkKeys(self):
         """
         Check that all specification dicts only contain legal keys.
@@ -286,6 +330,8 @@ class Sequences(object):
         alphabet = None
         previousRead = None
         nSequences = spec.get('count', 1)
+        nameCount = self._nameCount(spec)
+
         for count in range(nSequences):
             id_ = None
             if 'sections' in spec:
@@ -329,14 +375,10 @@ class Sequences(object):
             read = Read(id_, sequence)
             read.alphabet = alphabet
 
-            # Keep a reference to this result if it is named.
-            if count == 0 and 'name' in spec:
-                name = spec['name']
-                if name in self._names:
-                    raise ValueError("Name '%s' is duplicated in the JSON "
-                                     "specification." % name)
-                else:
-                    self._names[name] = read
+            # Keep a reference to this result if it is named and this is the
+            # sequence (by count) we want to name.
+            if 'name' in spec and nameCount == count:
+                self._names[spec['name']] = read
 
             if not spec.get('skip'):
                 yield read

Add a 'name count' directive so a certain sequence in a spec can be named
Currently we only assign the name of a named spec to the first sequence in that series. Make it so any one can be named.
diff --git a/test/testSequences.py b/test/testSequences.py
index b4b839d..a57de94 100644
--- a/test/testSequences.py
+++ b/test/testSequences.py
@@ -56,9 +56,8 @@ class TestSequences(TestCase):
         If a duplicate sequence name is present in the JSON, a ValueError
         must be raised.
         """
-        s = Sequences(spec='filename')
         error = "^Name 'a' is duplicated in the JSON specification\\.$"
-        assertRaisesRegex(self, ValueError, error, list, s)
+        assertRaisesRegex(self, ValueError, error, Sequences, spec='filename')
 
     def testNoSequences(self):
         """
@@ -738,3 +737,138 @@ class TestSequences(TestCase):
         # The sequences of the original and the second mutant must be
         # identical.
         self.assertEqual(orig.sequence, mutant2.sequence)
+
+    def testNameCountTooHigh(self):
+        """
+        A name count value that is higher than the number of sequences in
+        a specification must result in a ValueError.
+        """
+        spec = StringIO('''{
+            "sequences": [
+                {
+                    "name": "orig",
+                    "name count": 10,
+                    "count": 2
+                }
+            ]
+        }''')
+        error = ('^Sequence specification 1 will only produce 2 sequences but '
+                 'has a \\(too high\\) name count value of 10\\.$')
+        assertRaisesRegex(self, ValueError, error, Sequences, spec)
+
+    def testNameCountFirst(self):
+        """
+        A name count value of 'first' must result in the first sequence of a
+        series being named.
+        """
+        s = Sequences(StringIO('''{
+            "sequences": [
+                {
+                    "name": "orig",
+                    "name count": "first",
+                    "count": 20,
+                    "mutation rate": 0.1,
+                    "length": 500,
+                    "ratchet": true
+                },
+                {
+                    "id": "copy",
+                    "from name": "orig"
+                }
+            ]
+        }'''))
+        reads = list(s)
+        copySequence = reads[-1].sequence
+        # The final sequence (the copy) must be the same as the first sequence
+        # (and no others).
+        self.assertEqual(reads[0].sequence, copySequence)
+        for i in range(1, 20):
+            self.assertNotEqual(reads[i].sequence, copySequence)
+
+    def testNameCountLast(self):
+        """
+        A name count value of 'last' must result in the last sequence of a
+        series being named.
+        """
+        s = Sequences(StringIO('''{
+            "sequences": [
+                {
+                    "name": "orig",
+                    "name count": "last",
+                    "count": 20,
+                    "mutation rate": 0.1,
+                    "length": 500,
+                    "ratchet": true
+                },
+                {
+                    "id": "copy",
+                    "from name": "orig"
+                }
+            ]
+        }'''))
+        reads = list(s)
+        copySequence = reads[-1].sequence
+        # The final sequence (the copy) must be the same as the second last
+        # (i.e., the final mutant) sequence (and no others).
+        self.assertEqual(reads[-2].sequence, copySequence)
+        for i in range(19):
+            self.assertNotEqual(reads[i].sequence, copySequence)
+
+    def testNameCountOne(self):
+        """
+        A name count value of 1 must result in the first sequence of a
+        series being named.
+        """
+        s = Sequences(StringIO('''{
+            "sequences": [
+                {
+                    "name": "orig",
+                    "name count": 1,
+                    "count": 20,
+                    "mutation rate": 0.1,
+                    "length": 500,
+                    "ratchet": true
+                },
+                {
+                    "id": "copy",
+                    "from name": "orig"
+                }
+            ]
+        }'''))
+        reads = list(s)
+        copySequence = reads[-1].sequence
+        # The final sequence (the copy) must be the same as the first sequence
+        # (and no others).
+        self.assertEqual(reads[0].sequence, copySequence)
+        for i in range(1, 20):
+            self.assertNotEqual(reads[i].sequence, copySequence)
+
+    def testNameCountTwo(self):
+        """
+        A name count value of 2 must result in the second sequence of a
+        series being named.
+        """
+        s = Sequences(StringIO('''{
+            "sequences": [
+                {
+                    "name": "orig",
+                    "name count": 2,
+                    "count": 20,
+                    "mutation rate": 0.1,
+                    "length": 500,
+                    "ratchet": true
+                },
+                {
+                    "id": "copy",
+                    "from name": "orig"
+                }
+            ]
+        }'''))
+        reads = list(s)
+        copySequence = reads[-1].sequence
+        # The final sequence (the copy) must be the same as the second sequence
+        # (and no others).
+        self.assertEqual(reads[1].sequence, copySequence)
+        self.assertNotEqual(reads[0].sequence, copySequence)
+        for i in range(2, 20):
+            self.assertNotEqual(reads[i].sequence, copySequence)

pip install -e .
parse_log_pytest
pytest
pytest
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
backcall==0.2.0
biopython==1.79
bz2file==0.98
cachetools==4.2.4
certifi==2021.5.30
charset-normalizer==2.0.12
cycler==0.11.0
Cython==3.0.12
dark-matter==4.0.13
decorator==5.1.1
idna==3.10
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
ipython==7.16.3
ipython-genutils==0.2.0
jedi==0.17.2
kiwisolver==1.3.1
matplotlib==3.3.4
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
mysql-connector-python==8.0.11
numpy==1.19.5
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
parso==0.7.1
pexpect==4.9.0
pickleshare==0.7.5
Pillow==8.4.0
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
prompt-toolkit==3.0.36
protobuf==3.19.6
ptyprocess==0.7.0
py @ file:///opt/conda/conda-bld/py_1644396412707/work
Pygments==2.14.0
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pysam==0.23.0
pytest==6.2.4
python-dateutil==2.9.0.post0
pyzmq==25.1.2
requests==2.27.1
-e git+https://github.com/acorg/seqgen.git@fa23a119856b254988fc51a41835b927d516df53#egg=seqgen
simplejson==3.20.1
six==1.17.0
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
traitlets==4.3.3
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
urllib3==1.26.20
wcwidth==0.2.13
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: seqgen
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - backcall==0.2.0
      - biopython==1.79
      - bz2file==0.98
      - cachetools==4.2.4
      - charset-normalizer==2.0.12
      - cycler==0.11.0
      - cython==3.0.12
      - dark-matter==4.0.13
      - decorator==5.1.1
      - idna==3.10
      - ipython==7.16.3
      - ipython-genutils==0.2.0
      - jedi==0.17.2
      - kiwisolver==1.3.1
      - matplotlib==3.3.4
      - mysql-connector-python==8.0.11
      - numpy==1.19.5
      - parso==0.7.1
      - pexpect==4.9.0
      - pickleshare==0.7.5
      - pillow==8.4.0
      - prompt-toolkit==3.0.36
      - protobuf==3.19.6
      - ptyprocess==0.7.0
      - pygments==2.14.0
      - pysam==0.23.0
      - python-dateutil==2.9.0.post0
      - pyzmq==25.1.2
      - requests==2.27.1
      - simplejson==3.20.1
      - six==1.17.0
      - traitlets==4.3.3
      - urllib3==1.26.20
      - wcwidth==0.2.13
prefix: /opt/conda/envs/seqgen

test/testSequences.py::TestSequences::testDuplicatedName test/testSequences.py::TestSequences::testNameCountFirst test/testSequences.py::TestSequences::testNameCountLast test/testSequences.py::TestSequences::testNameCountOne test/testSequences.py::TestSequences::testNameCountTooHigh test/testSequences.py::TestSequences::testNameCountTwo
test/testSequences.py::TestSequences::testNamedRecombinant test/testSequences.py::TestSequences::testNoSequences test/testSequences.py::TestSequences::testNoSequencesKey test/testSequences.py::TestSequences::testNonExistentSpecificationFile test/testSequences.py::TestSequences::testNotJSON test/testSequences.py::TestSequences::testOneLetterAlphabet test/testSequences.py::TestSequences::testOneSectionRandomAAs test/testSequences.py::TestSequences::testOneSectionRandomNTs test/testSequences.py::TestSequences::testOneSectionWithLength test/testSequences.py::TestSequences::testOneSectionWithSequence test/testSequences.py::TestSequences::testOneSequenceAAOnly test/testSequences.py::TestSequences::testOneSequenceByLength test/testSequences.py::TestSequences::testOneSequenceIdAndCountGreaterThanOne test/testSequences.py::TestSequences::testOneSequenceIdOnly test/testSequences.py::TestSequences::testOneSequenceIdOnlyDefaultIdPrefix test/testSequences.py::TestSequences::testOneSequenceIdOnlyDefaultLength test/testSequences.py::TestSequences::testOneSequenceIdPrefix test/testSequences.py::TestSequences::testOneSequenceLengthIsAVariable test/testSequences.py::TestSequences::testOneSequenceNameOnly test/testSequences.py::TestSequences::testOneSequenceRandomNTs test/testSequences.py::TestSequences::testOneSequenceSequenceMutated test/testSequences.py::TestSequences::testOneSequenceSequenceOnly test/testSequences.py::TestSequences::testOneSequenceWithIdAndDescription test/testSequences.py::TestSequences::testRatchet test/testSequences.py::TestSequences::testRatchetWithNoCount test/testSequences.py::TestSequences::testRatchetWithNoMutationRate test/testSequences.py::TestSequences::testRecombinantFromFullOtherSequences test/testSequences.py::TestSequences::testSectionWithNameReference test/testSequences.py::TestSequences::testSectionWithNameReferenceTooShort test/testSequences.py::TestSequences::testSectionWithUnknownNameReference test/testSequences.py::TestSequences::testTwoLetterAlphabet test/testSequences.py::TestSequences::testTwoSectionsWithLengths test/testSequences.py::TestSequences::testTwoSequencesButSecondOneSkipped test/testSequences.py::TestSequences::testTwoSequencesByCount test/testSequences.py::TestSequences::testTwoSequencesSecondFromName test/testSequences.py::TestSequences::testTwoSequencesSecondOneNotSkipped test/testSequences.py::TestSequences::testTwoSequencesWithDifferentIdPrefixesAndCounts test/testSequences.py::TestSequences::testUnknownSectionKey test/testSequences.py::TestSequences::testUnknownSpecificationKey
seqgen/sequences.py seqgen/__init__.py README.md
seqgen/sequences.py seqgen/__init__.py README.md