comparison cuffcompare_wrapper.py @ 2:8b22e9adae34

Update to the new data table specification.
author Dave Bouvier <dave@bx.psu.edu>
date Wed, 04 Dec 2013 13:24:29 -0500
parents 9d35cf35634e
children 8e534225baa9
comparison
equal deleted inserted replaced
1:9a3f7a890da6 2:8b22e9adae34
6 6
7 def stop_err( msg ): 7 def stop_err( msg ):
8 sys.stderr.write( '%s\n' % msg ) 8 sys.stderr.write( '%s\n' % msg )
9 sys.exit() 9 sys.exit()
10 10
11 # Copied from sam_to_bam.py:
12 def check_seq_file( dbkey, cached_seqs_pointer_file ):
13 seq_path = ''
14 for line in open( cached_seqs_pointer_file ):
15 line = line.rstrip( '\r\n' )
16 if line and not line.startswith( '#' ) and line.startswith( 'index' ):
17 fields = line.split( '\t' )
18 if len( fields ) < 3:
19 continue
20 if fields[1] == dbkey:
21 seq_path = fields[2].strip()
22 break
23 return seq_path
24
25 def __main__(): 11 def __main__():
26 #Parse Command Line 12 #Parse Command Line
27 parser = optparse.OptionParser() 13 parser = optparse.OptionParser()
28 parser.add_option( '-r', dest='ref_annotation', help='An optional "reference" annotation GTF. Each sample is matched against this file, and sample isoforms are tagged as overlapping, matching, or novel where appropriate. See the refmap and tmap output file descriptions below.' ) 14 parser.add_option( '-r', dest='ref_annotation', help='An optional "reference" annotation GTF. Each sample is matched against this file, and sample isoforms are tagged as overlapping, matching, or novel where appropriate. See the refmap and tmap output file descriptions below.' )
29 parser.add_option( '-R', action="store_true", dest='ignore_nonoverlap', help='If -r was specified, this option causes cuffcompare to ignore reference transcripts that are not overlapped by any transcript in one of cuff1.gtf,...,cuffN.gtf. Useful for ignoring annotated transcripts that are not present in your RNA-Seq samples and thus adjusting the "sensitivity" calculation in the accuracy report written in the transcripts accuracy file' ) 15 parser.add_option( '-R', action="store_true", dest='ignore_nonoverlap', help='If -r was specified, this option causes cuffcompare to ignore reference transcripts that are not overlapped by any transcript in one of cuff1.gtf,...,cuffN.gtf. Useful for ignoring annotated transcripts that are not present in your RNA-Seq samples and thus adjusting the "sensitivity" calculation in the accuracy report written in the transcripts accuracy file' )
30 parser.add_option( '-s', dest='use_seq_data', action="store_true", help='Causes cuffcompare to look into for fasta files with the underlying genomic sequences (one file per contig) against which your reads were aligned for some optional classification functions. For example, Cufflinks transcripts consisting mostly of lower-case bases are classified as repeats. Note that <seq_dir> must contain one fasta file per reference chromosome, and each file must be named after the chromosome, and have a .fa or .fasta extension.') 16 parser.add_option( '-s', dest='use_seq_data', action="store_true", help='Causes cuffcompare to look into for fasta files with the underlying genomic sequences (one file per contig) against which your reads were aligned for some optional classification functions. For example, Cufflinks transcripts consisting mostly of lower-case bases are classified as repeats. Note that <seq_dir> must contain one fasta file per reference chromosome, and each file must be named after the chromosome, and have a .fa or .fasta extension.')
31 17
32 # Wrapper / Galaxy options. 18 # Wrapper / Galaxy options.
33 parser.add_option( '', '--dbkey', dest='dbkey', help='The build of the reference dataset' ) 19 parser.add_option( '', '--index', dest='index', help='The path of the reference genome' )
34 parser.add_option( '', '--index_dir', dest='index_dir', help='GALAXY_DATA_INDEX_DIR' )
35 parser.add_option( '', '--ref_file', dest='ref_file', help='The reference dataset from the history' ) 20 parser.add_option( '', '--ref_file', dest='ref_file', help='The reference dataset from the history' )
36 21
37 # Outputs. 22 # Outputs.
38 parser.add_option( '', '--combined-transcripts', dest='combined_transcripts' ) 23 parser.add_option( '', '--combined-transcripts', dest='combined_transcripts' )
39 24
58 except: 43 except:
59 sys.stdout.write( 'Could not determine Cuffcompare version\n' ) 44 sys.stdout.write( 'Could not determine Cuffcompare version\n' )
60 45
61 # Set/link to sequence file. 46 # Set/link to sequence file.
62 if options.use_seq_data: 47 if options.use_seq_data:
63 if options.ref_file != 'None': 48 if options.ref_file:
64 # Sequence data from history. 49 # Sequence data from history.
65 # Create symbolic link to ref_file so that index will be created in working directory. 50 # Create symbolic link to ref_file so that index will be created in working directory.
66 seq_path = "ref.fa" 51 seq_path = "ref.fa"
67 os.symlink( options.ref_file, seq_path ) 52 os.symlink( options.ref_file, seq_path )
68 else: 53 else:
69 # Sequence data from loc file. 54 if not os.path.exists( options.index ):
70 cached_seqs_pointer_file = os.path.join( options.index_dir, 'sam_fa_indices.loc' ) 55 stop_err( 'Reference genome %s not present, request it by reporting this error.' % options.index )
71 if not os.path.exists( cached_seqs_pointer_file ): 56 seq_path = options.index
72 stop_err( 'The required file (%s) does not exist.' % cached_seqs_pointer_file )
73 # If found for the dbkey, seq_path will look something like /galaxy/data/equCab2/sam_index/equCab2.fa,
74 # and the equCab2.fa file will contain fasta sequences.
75 seq_path = check_seq_file( options.dbkey, cached_seqs_pointer_file )
76 if seq_path == '':
77 stop_err( 'No sequence data found for dbkey %s, so sequence data cannot be used.' % options.dbkey )
78 57
79 # Build command. 58 # Build command.
80 59
81 # Base. 60 # Base.
82 cmd = "cuffcompare -o cc_output " 61 cmd = "cuffcompare -o cc_output "