~ubuntu-branches/ubuntu/utopic/idba/utopic-proposed

« back to all changes in this revision

Viewing changes to src/tools/shuffle_reads.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2014-02-13 13:57:55 UTC
  • Revision ID: package-import@ubuntu.com-20140213135755-c97jpl9wl5yzfwfw
Tags: upstream-1.1.1
ImportĀ upstreamĀ versionĀ 1.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file shuffle_reads.cpp
 
3
 * @brief Shuffle a set of reads.
 
4
 * @author Yu Peng (ypeng@cs.hku.hk)
 
5
 * @version 1.0.6
 
6
 * @date 2011-10-31
 
7
 */
 
8
 
 
9
#include <algorithm>
 
10
#include <cctype>
 
11
#include <cstdio>
 
12
#include <cstring>
 
13
#include <deque>
 
14
#include <iostream>
 
15
#include <stdexcept>
 
16
 
 
17
#include "misc/options_description.h"
 
18
#include "misc/utils.h"
 
19
#include "sequence/sequence.h"
 
20
#include "sequence/sequence_io.h"
 
21
 
 
22
using namespace std;
 
23
 
 
24
int main(int argc, char *argv[])
 
25
{
 
26
    OptionsDescription desc;
 
27
 
 
28
    try
 
29
    {
 
30
        desc.Parse(argc, argv);
 
31
 
 
32
        if (argc < 3)
 
33
            throw logic_error("not enough parameters");
 
34
 
 
35
    }
 
36
    catch (exception &e)
 
37
    {
 
38
        cerr << e.what() << endl;
 
39
        cerr << "shuffle_reads - shuffle reads." << endl;
 
40
        cerr << "Usage: shuffle_reads reads.fq shuffle_reads.fa [...] " << endl;
 
41
        cerr << "Allowed Options: " << endl;
 
42
        cerr << desc << endl;
 
43
        exit(1);
 
44
    }
 
45
 
 
46
    deque<Sequence> reads;
 
47
    deque<string> names;
 
48
    ReadSequence(argv[1], reads, names);
 
49
 
 
50
    int n = reads.size()/2;
 
51
    deque<int> aux(n);
 
52
    for (int i = 0; i < n; ++i)
 
53
        aux[i] = i;
 
54
 
 
55
    for (int i = 0; i < n; ++i)
 
56
        swap(aux[i], aux[rand()%(n-i) + i]);
 
57
 
 
58
    FastaWriter writer(argv[2]);
 
59
    for (int i = 0; i < n; ++i)
 
60
    {
 
61
        writer.Write(reads[aux[i]*2], names[aux[i]*2]);
 
62
        writer.Write(reads[aux[i]*2+1], names[aux[i]*2+1]);
 
63
    }
 
64
 
 
65
    return 0;
 
66
}
 
67