+ minor changes to support transcriptome data
[qpalma.git] / scripts / createAlignmentFileFromPrediction.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import cPickle
5 import sys
6 import pdb
7 import os
8 import os.path
9 import math
10 from qpalma.parsers import *
11
12 from Evaluation import load_chunks
13
14 def prediction_on(current_dir,filtered_reads,out_fname):
15
16 import qparser
17 qparser.parse_reads(filtered_reads)
18
19 out_fh = open(out_fname,'w+')
20
21 allPredictions = load_chunks(current_dir)
22 allPositions = {}
23
24 for current_prediction in allPredictions:
25 id = current_prediction['id']
26
27 #current_ground_truth = qparser.fetch_read(id)
28 #true_cut = current_ground_truth['true_cut']
29 #seq = current_ground_truth['seq']
30 #q1 = current_ground_truth['prb']
31 seq = current_prediction['est']
32
33 # CHECK !!!
34 q1 = 'zzz'
35
36 chr = current_prediction['chr']
37 strand = current_prediction['strand']
38 start_pos = current_prediction['start_pos']
39 alignment = current_prediction['alignment']
40
41 predExons = current_prediction['predExons']
42 predExons = [e+start_pos for e in predExons]
43
44 p_start = current_ground_truth['p_start']
45 e_stop = current_ground_truth['exon_stop']
46 e_start = current_ground_truth['exon_start']
47 p_stop = current_ground_truth['p_stop']
48
49 correct_prediction = False
50
51 (qStart, qEnd, tStart, tEnd, num_exons, qExonSizes, qStarts, qEnds,\
52 tExonSizes,tStarts, tEnds) = alignment
53
54 new_line = '%d\t%d\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n' %\
55 (id,chr,strand,seq,str(q1)[1:-1],start_pos,qStart,qEnd,tStart,tEnd,num_exons,\
56 str(qExonSizes)[1:-1].replace(' ',''),str(qStarts)[1:-1].replace(' ',''),\
57 str(qEnds)[1:-1].replace(' ',''),str(tExonSizes)[1:-1].replace(' ',''),\
58 str(tStarts)[1:-1].replace(' ',''),str(tEnds)[1:-1].replace(' ',''))
59
60 out_fh.write(new_line)
61
62 return allPositions
63
64 if __name__ == '__main__':
65 current_dir = sys.argv[1]
66 filtered_reads = sys.argv[2]
67 out_fh = sys.argv[3]
68 prediction_on(current_dir,filtered_reads,out_fh)