File: format_reads.py

package info (click to toggle)
vg 1.59.0%2Bds-0.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 361,528 kB
  • sloc: cpp: 479,590; ansic: 191,648; python: 23,671; javascript: 13,961; sh: 7,025; makefile: 5,577; perl: 3,636; lisp: 293; java: 136
file content (53 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import sys
import argparse


class FQRecord:
    def __init__(self):
        self.seq = ""
        self.qual = ""
        self.anno = ""
        self.name = ""

    def string(self):
        ret = "@" + self.name.strip() + "\n" + \
        self.seq + "\n" + \
        "+" + self.anno + "\n" + \
        self.qual
        return ret


"""Takes in a pseudo fasta and makes a
pseudo fastq from it"""
def make_fastq(record, name, fake_qual, seq="", anno=""):
    if record.name == "":
        record.name = name
    
    record.qual = "".join([fake_qual for i in range(0, len(record.seq))])

    return record

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", dest="infile", type=str, required=True)
    parser.add_argument("-n", dest="namebase", type=str, required=True)
    parser.add_argument("-q", dest="qual", type=str, required=True)
    return parser.parse_args()
    

if __name__ == "__main__":
    ## Add the sample name to the front of the
    ## read line.
    args = parse_args()
    readfile = args.infile
    name_base = args.namebase
    fake_qual = args.qual
    count = 0
    with open(readfile, "r") as fi:
        for line in fi:
            record = FQRecord()
            record.seq = line.strip()
            record.name = name_base + "_" + str(count)
            record = make_fastq(record, "", fake_qual)
            print(record.string())
            count += 1