Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following script will return a count of sequences. It returns a dictionary with the individual, distinct sequences as keys and the numbers (the first part of each line) where these sequences occur. </p> <pre><code>#!/usr/bin/python import sys from collections import defaultdict def count_sequences(filename): result = defaultdict(list) with open(filename) as f: for index, line in enumerate(f): sequence = line.replace('\n', '') line_number = index + 1 result[sequence].append(line_number) return result if __name__ == '__main__': filename = sys.argv[1] for sequence, occurrences in count_sequences(filename).iteritems(): print "%s: %s, found in %s" % (sequence, len(occurrences), occurrences) </code></pre> <p>Sample output:</p> <pre><code>etc@etc:~$ python ./fasta.py /path/to/my/file GTCGTCGAAAGAGGCTT-GCCCGCTACGCGCCCCCTGATA: 1, found in ['4'] GTCGTCGAAAGAGGCTT-GCCCGCCACGCGCCCGCTGATA: 1, found in ['3'] GTCGTCGAAAGAGGTCT-GACCGCTTCGCGCCCGCTGGTA: 2, found in ['2', '5'] GTCGTCGAAAGAGGTCT-GACCGCTTCTCGCCCGCTGATA: 1, found in ['7'] GTCGTCGAAGCATGCCGGGCCCGCTTCGTGTTCGCTGATA: 1, found in ['1'] GTCGTCGAAAGAGTCTGACCGCTTCTCGCCCGCTGATACG: 1, found in ['6'] </code></pre> <p><strong>Update</strong></p> <p>Changed code to use <code>dafaultdict</code> and <code>for</code> loop. Thanks <a href="https://stackoverflow.com/users/224671/kennytm">@KennyTM</a>.</p> <p><strong>Update 2</strong></p> <p>Changed code to use <code>append</code> rather than <code>+</code>. Thanks <a href="https://stackoverflow.com/users/3171/dave-webb">@Dave Webb</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload