def write(self, raw_data, filename) : """ Write raw LRG data to a file. The data is parsed before writing, if a parse error occurs None is returned. @arg raw_data: The data @type raw_data: byte string @arg filename: The intended name of the file @type filename: unicode @return: - filename ; The full path and name of the file written - None ; In case of an error @rtype: unicode """ # Dirty way to test if a file is valid, # Parse the file to see if it's a real LRG file. try: lrg.create_record(raw_data) except DOMException: self._output.addMessage(__file__, 4, "ERECPARSE", "Could not parse file.") return None # Explicit return on Error return self._write(raw_data, filename) #returns full path
def loadrecord(self, identifier): """ Load and parse a LRG file based on the identifier. :arg unicode identifier: The name of the LRG file to read. :returns: GenRecord.Record of LRG file or None in case of failure. :rtype: object """ # Make a filename based upon the identifier. filename = self._name_to_file(identifier) if not os.path.isfile(filename): # We can't find the file. filename = self.fetch(identifier) if filename is None: # Notify batch to skip all instance of identifier. self._output.addOutput('BatchFlags', ('S1', identifier)) # return None in case of error. return None # Now we have the file, so we can parse it. file_handle = bz2.BZ2File(filename, 'r') # Create GenRecord.Record from LRG file. record = lrg.create_record(file_handle.read()) file_handle.close() # We don't create LRGs from other sources, so id is always the same # as source_id. record.id = identifier record.source_id = identifier return record
def test_lrg_multiple_transcripts(settings, references): """ """ accession = references[0].accession filename = os.path.join(settings.CACHE_DIR, '%s.xml.bz2' % accession) file_handle = bz2.BZ2File(filename, 'r') record = create_record(file_handle.read()) file_handle.close() assert len(record.geneList[0].transcriptList) == 2
def test_lrg_basic(settings, references): """ """ accession = references[0].accession filename = os.path.join(settings.CACHE_DIR, '%s.xml.bz2' % accession) file_handle = bz2.BZ2File(filename, 'r') record = create_record(file_handle.read()) file_handle.close() assert [g.name for g in record.geneList] == ['COL1A1'] assert record.geneList[0].transcriptList[0].name == '1' assert len(record.geneList[0].transcriptList) == 1 assert record.geneList[0].transcriptList[0].CDS is not None assert record.organism == 'H**o sapiens'
def write(self, raw_data, filename): """ Write raw LRG data to a file. The data is parsed before writing, if a parse error occurs None is returned. :arg str raw_data: The data. :arg unicode filename: The intended name of the file. :returns: The full path and name of the file written, None in case of an error. :rtype: unicode """ # Dirty way to test if a file is valid, # Parse the file to see if it's a real LRG file. try: lrg.create_record(raw_data) except DOMException: self._output.addMessage(__file__, 4, 'ERECPARSE', 'Could not parse file.') # Explicit return on Error. return None # Returns full path. return self._write(raw_data, filename)
def write(self, raw_data, filename): """ Write raw LRG data to a file. The data is parsed before writing, if a parse error occurs None is returned. :arg str raw_data: The data. :arg unicode filename: The intended name of the file. :returns: The full path and name of the file written, None in case of an error. :rtype: unicode """ # Dirty way to test if a file is valid, # Parse the file to see if it's a real LRG file. try: lrg.create_record(raw_data) except DOMException: self._output.addMessage( __file__, 4, 'ERECPARSE', 'Could not parse file.') # Explicit return on Error. return None # Returns full path. return self._write(raw_data, filename)
def loadrecord(self, identifier): """ Load and parse a LRG file based on the identifier @arg identifier: The name of the LRG file to read @type identifier: unicode @return: record ; GenRecord.Record of LRG file None ; in case of failure @rtype: """ # Make a filename based upon the identifier. filename = self._nametofile(identifier) if not os.path.isfile(filename) : # We can't find the file. filename = self.fetch(identifier) if filename is None: # return None in case of error #Notify batch to skip all instance of identifier self._output.addOutput("BatchFlags", ("S1", identifier)) return None # Now we have the file, so we can parse it. file_handle = bz2.BZ2File(filename, "r") #create GenRecord.Record from LRG file record = lrg.create_record(file_handle.read()) file_handle.close() # We don't create LRGs from other sources, so id is always the same # as source_id. record.id = identifier record.source_id = identifier return record