File size: 1,567 Bytes
e3814d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# --------------------------------------------------------
# a script to transform tsv outputs for loops to bedpe format
# --------------------------------------------------------

import pandas as pd
import argparse

required_domain = ['chrom1', 'start1', 'end1', 'chrom2', 'start2', 'end2', 'name', 'score', 'strand1', 'strand2', 'color']

if __name__=='__main__':
    parser = argparse.ArgumentParser()

    parser.add_argument('-f', '--tsv-file', type=str)
    parser.add_argument('-o', '--output-file', type=str, default = None)
    parser.add_argument('-c', '--default-color', type=str, default = '0,0,255')
    args = parser.parse_args()

    tsv_file = args.tsv_file
    output_file = args.output_file

    default_color = args.default_color

    if output_file is None:
        output_file = args.tsv_file.split('.')[0]+'.bedpe'

    data = pd.read_csv(tsv_file,sep='\t')

    n = len(data)

    default = ['.'] * n

    bedpe_data = {}

    for domain in required_domain:
        if domain in data.columns:
            bedpe_data[domain] = data[domain]
        else:
            if domain == 'color':
                bedpe_data[domain] = default_color
            else:
                bedpe_data[domain] = default
    
    for domain in data.columns:
        if domain not in required_domain:
            bedpe_data[domain] = data[domain]
    
    pd.DataFrame(bedpe_data).to_csv(output_file, sep='\t', index=False)