#NEWLINE# def run( self ) : #NEWLINE# #INDENT# if ( not os . path . exists ( self . outputDirectory ) ) : #NEWLINE# #INDENT# os . makedirs ( self . outputDirectory ) #NEWLINE# #UNINDENT# print ( 'Exporting ontologies...' , file = sys . stderr ) #NEWLINE# ontologiesDir = os . path . join ( self . outputDirectory , 'ontologymaps' ) #NEWLINE# sequenceOntologyDir = os . path . join ( ontologiesDir , 'sequence_ontology' ) #NEWLINE# os . makedirs ( sequenceOntologyDir ) #NEWLINE# shutil . copy ( os . path . join ( self . inputDirectory , 'sequence_ontology.txt' ) , os . path . join ( sequenceOntologyDir , 'sequence_ontology.txt' ) ) #NEWLINE# utils . log ( 'Converting references...' ) #NEWLINE# shutil . rmtree ( self . refsetsDirectory , ignore_errors = True ) #NEWLINE# os . makedirs ( self . refsetsDirectory ) #NEWLINE# shutil . copy ( os . path . join ( self . inputDirectory , 'referenceset_hg37.json' ) , os . path . join ( self . refsetsDirectory , 'hg37.json' ) ) #NEWLINE# os . makedirs ( self . hg37Directory ) #NEWLINE# for refFile in self . referenceFiles : #NEWLINE# #INDENT# refBase = os . path . splitext ( refFile ) [ 0 ] #NEWLINE# destFastaFilename = ( os . path . join ( self . hg37Directory , refBase ) + '.fa' ) #NEWLINE# shutil . copy ( ( os . path . join ( self . inputDirectory , refBase ) + '.fa' ) , destFastaFilename ) #NEWLINE# pysam . tabix_compress ( destFastaFilename , ( destFastaFilename + '.gz' ) ) #NEWLINE# refFasta = pysam . FastaFile ( ( destFastaFilename + '.gz' ) ) #NEWLINE# refFasta . close ( ) #NEWLINE# os . remove ( destFastaFilename ) #NEWLINE# shutil . copy ( ( os . path . join ( self . inputDirectory , refBase ) + '.json' ) , ( os . path . join ( self . hg37Directory , refBase ) + '.json' ) ) #NEWLINE# #UNINDENT# shutil . rmtree ( self . datasetsDirectory , ignore_errors = True ) #NEWLINE# os . makedirs ( self . datasetsDirectory ) #NEWLINE# for ds in self . datasets : #NEWLINE# #INDENT# dsdir = os . path . join ( self . datasetsDirectory , ds ) #NEWLINE# os . makedirs ( dsdir ) #NEWLINE# utils . log ( 'Converting reads...' ) #NEWLINE# dsReadsdir = os . path . join ( dsdir , 'reads' ) #NEWLINE# os . makedirs ( dsReadsdir ) #NEWLINE# for readFile in self . datasetReads [ ds ] : #NEWLINE# #INDENT# destFile = ( os . path . join ( dsReadsdir , readFile . split ( '_' ) [ 1 ] . split ( '.' ) [ 0 ] ) + '.bam' ) #NEWLINE# readSrc = pysam . AlignmentFile ( os . path . join ( self . inputDirectory , readFile ) , 'r' ) #NEWLINE# readDest = pysam . AlignmentFile ( destFile , 'wb' , header = readSrc . header ) #NEWLINE# destFilePath = readDest . filename #NEWLINE# for readData in readSrc : #NEWLINE# #INDENT# readDest . write ( readData ) #NEWLINE# #UNINDENT# readDest . close ( ) #NEWLINE# readSrc . close ( ) #NEWLINE# pysam . index ( destFilePath ) #NEWLINE# #UNINDENT# utils . log ( 'Converting variants...' ) #NEWLINE# dsVariantsdir = os . path . join ( dsdir , 'variants' ) #NEWLINE# os . makedirs ( dsVariantsdir ) #NEWLINE# for vgroup in self . datasetVariants [ ds ] . keys ( ) : #NEWLINE# #INDENT# vgroupdir = os . path . join ( dsVariantsdir , vgroup ) #NEWLINE# os . makedirs ( vgroupdir ) #NEWLINE# for variantFile in self . datasetVariants [ ds ] [ vgroup ] : #NEWLINE# #INDENT# destFile = os . path . join ( vgroupdir , variantFile . split ( '_' ) [ 2 ] ) #NEWLINE# shutil . copy ( os . path . join ( self . inputDirectory , variantFile ) , destFile ) #NEWLINE# pysam . tabix_index ( destFile , preset = 'vcf' ) #NEWLINE# #UNINDENT# #UNINDENT# print ( 'Converting sequence annotations...' , file = sys . stderr ) #NEWLINE# dsSeqAnndir = os . path . join ( dsdir , 'sequenceAnnotations' ) #NEWLINE# os . makedirs ( dsSeqAnndir ) #NEWLINE# for seqAnnFile in self . datasetSequenceAnnotations [ ds ] : #NEWLINE# #INDENT# seqAnnDest = ( os . path . join ( dsSeqAnndir , seqAnnFile . split ( '_' ) [ 1 ] . split ( '.' ) [ 0 ] ) + '.db' ) #NEWLINE# seqAnnSrc = os . path . join ( self . inputDirectory , seqAnnFile ) #NEWLINE# dbgen = generate_gff3_db . Gff32Db ( seqAnnSrc , seqAnnDest ) #NEWLINE# dbgen . run ( ) #NEWLINE# #UNINDENT# #UNINDENT# print ( 'done converting compliance data.' , file = sys . stderr )