def getInput(self): ''' Open a single .seq, .fasta, .fastq, .ztr, .scf, .ab1 file (or even a text file with a DNA sequence) and set variables accordingly. ''' #read the input if self.input_type in ['TXT', 'SEQ', 'SEQ.CLIPPED', None] and self.filename not in ['allseqs.txt']: f = open(self.filepath, 'r') input = f.read() f.close() self.setDNA(input.replace('\n', '')) elif self.input_type in ['AB1', 'ABI', 'ABIF']: ab1 = ABIreader.Trace(self.filepath, trimming=True) #optionally ', trimming=True' self.setDNA(ab1.seq) self.setQualVal(ab1.qual_val) self.setTrace([ab1.data['raw1'], ab1.data['raw2'], ab1.data['raw3'], ab1.data['raw4']]) #need to RC this too # elif self.input_type == 'ZTR': # print('Support for .ztr files has not yet been implemented') # elif self.input_type == 'SCF': # print('Support for .scf files has not yet been implemented') elif self.input_type is 'FASTA': id, seq = fasta.parseFile(self.filepath) #parse the fasta file. File should contain ONE entry self.setDNA(seq) elif self.input_type is 'FASTQ': id, seq, id2, qual_val = fastq.parse(self.filepath) #parse the fastq file. File should contain ONE entry self.setDNA(seq) self.setQualVal(qual_val) else: print('"%s" is not a .txt, .seq, .scf, .fasta, .fastq, .abif, .ab1, .abi or .ztr file' % self.filename)
def get_input(self): '''Open a single .seq, .fasta, .fastq, .scf or .ab1 file and set variables accordingly.''' parts = self.filepath.split('/') filename = parts.pop() #get filename self.name = filename path = '/'.join(parts) #path to file #establish type of input file if '.' in filename: self.input_type = filename.split('.').upper() else: self.input_type = None #establish orientation of DNA if filename[-2:].upper() == 'FW': self.SetOrientation('fw') elif filename[-2:].upper() == 'RV': self.SetOrientation('rv') else: raise TypeError, 'The last two characters of the filename (before the .) must specify whether the sequence is fw or rv. Pleace rename file %s accordingly' % filename #read the input if self.input_type in ['TXT', 'SEQ', None]: f = open(filepath, 'r') dna = f.read() self.SetDNA(dna.replace('\n', '')) #add an assert that there are only dna bases here f.close() elif self.input_type in ['AB1', 'ABI']): ab1 = ABIreader.Trace(filepath, trimming=False) #optionally ', trimming=True' self.SetDNA(ab1.seq) self.SetQualVal(ab1.qual_val) self.SetTrace([AB1Trace.data['raw1'], AB1Trace.data['raw2'], AB1Trace.data['raw3'], AB1Trace.data['raw4']]) #abi=dict(baseorder=ab1.data['baseorder'], qual_val=ab1.qual_val, G=str(AB1Trace.data['raw1']), A=str(AB1Trace.data['raw2']), T=str(AB1Trace.data['raw3']), C=str(AB1Trace.data['raw4'])) elif self.input_type == 'ABIF': print('Support for .abif files has not yet been implemented') elif self.input_type == 'ZTR': print('Support for .ztr files has not yet been implemented') elif self.input_type == 'SCF': print('Support for .scf files has not yet been implemented') elif fnmatch.fnmatch(filename, '*.fasta'): id, dna = fasta.parse(self.filepath) #parse the fasta file. File should contain ONE entry self.SetDNA(dna) elif fnmatch.fnmatch(filename, '*.fastq'): id, dna, id2, qual_val = fastq.parse(self.filepath) #parse the fastq file. File should contain ONE entry self.SetDNA(dna) self.SetQualVal(qual_val) else: raise TypeError, '"%s" is not a .txt, .seq, .scf, .fasta, .fastq, .abif, .abi or .ztr file' % filename
def getInput(self): ''' Open a single .seq, .fasta, .fastq, .ztr, .scf, .ab1 file (or even a text file with a DNA sequence) and set variables accordingly. ''' #read the input if self.input_type in ['TXT', None ] and self.filename not in ['allseqs.txt']: f = open(self.filepath, 'r') input = f.read() f.close() self.setDNA(input.replace('\n', '')) elif self.input_type in ['SEQ', 'SEQ.CLIPPED']: output = fasta.parseFile( self.filepath ) #parse the fasta file. File should contain ONE entry for item in output: id, seq = item self.setDNA(seq) elif self.input_type in ['AB1', 'ABI', 'ABIF']: ab1 = ABIreader.Trace(self.filepath, trimming=True) #optionally ', trimming=True' self.setDNA(ab1.seq) self.setQualVal(ab1.qual_val) self.setTrace([ ab1.data['raw1'], ab1.data['raw2'], ab1.data['raw3'], ab1.data['raw4'] ]) #need to RC this too # elif self.input_type == 'ZTR': # print('Support for .ztr files has not yet been implemented') # elif self.input_type == 'SCF': # print('Support for .scf files has not yet been implemented') elif self.input_type is 'FASTA': id, seq = fasta.parseFile( self.filepath ) #parse the fasta file. File should contain ONE entry self.setDNA(seq) elif self.input_type is 'FASTQ': id, seq, id2, qual_val = fastq.parse( self.filepath ) #parse the fastq file. File should contain ONE entry self.setDNA(seq) self.setQualVal(qual_val) else: print(( '"%s" is not a .txt, .seq, .scf, .fasta, .fastq, .abif, .ab1, .abi or .ztr file' % self.filename))
def getInput(self): """ Open a single .seq, .fasta, .fastq, .ztr, .scf, .ab1 file (or even a text file with a DNA sequence) and set variables accordingly. """ # read the input if self.input_type in ["TXT", None] and self.filename not in ["allseqs.txt"]: f = open(self.filepath, "r") input = f.read() f.close() self.setDNA(input.replace("\n", "")) elif self.input_type in ["SEQ", "SEQ.CLIPPED"]: output = fasta.parseFile(self.filepath) # parse the fasta file. File should contain ONE entry for item in output: id, seq = item self.setDNA(seq) elif self.input_type in ["AB1", "ABI", "ABIF"]: ab1 = ABIreader.Trace(self.filepath, trimming=True) # optionally ', trimming=True' self.setDNA(ab1.seq) self.setQualVal(ab1.qual_val) self.setTrace( [ab1.data["raw1"], ab1.data["raw2"], ab1.data["raw3"], ab1.data["raw4"]] ) # need to RC this too # elif self.input_type == 'ZTR': # print('Support for .ztr files has not yet been implemented') # elif self.input_type == 'SCF': # print('Support for .scf files has not yet been implemented') elif self.input_type is "FASTA": id, seq = fasta.parseFile(self.filepath) # parse the fasta file. File should contain ONE entry self.setDNA(seq) elif self.input_type is "FASTQ": id, seq, id2, qual_val = fastq.parse(self.filepath) # parse the fastq file. File should contain ONE entry self.setDNA(seq) self.setQualVal(qual_val) else: print('"%s" is not a .txt, .seq, .scf, .fasta, .fastq, .abif, .ab1, .abi or .ztr file' % self.filename)
def getInput(self): '''Open a single .seq, .fasta, .fastq, .ztr, .scf, .ab1 file (or even a text file with a DNA sequence) and set variables accordingly.''' parts = self.filepath.split('/') filename = parts.pop() #get filename path = '/'.join(parts)+'/' #path to file #establish type of input file if '.' in filename: self.input_type = filename.split('.')[-1].upper() print('type', self.input_type) else: self.input_type = None #read the input if self.input_type in ['TXT', 'SEQ', None] and filename not in ['allseqs.txt']: #establish orientation of DNA if filename.split('.')[0][-2:].upper() == 'FW': self.setOrientation('fw') elif filename.split('.')[0][-2:].upper() == 'RV': self.setOrientation('rv') else: raise TypeError, 'The last two characters of the filename (before the .) must specify whether the sequence is fw or rv. Pleace rename file %s accordingly' % filename self.setName(filename) f = open(self.filepath, 'r') input = f.read() f.close() if self.getOrientation() == 'fw': self.setDNA(input.replace('\n', '')) elif self.getOrientation() == 'rv': self.setDNA(DNA.RC(input.replace('\n', ''))) self.setRC(True) elif self.input_type in ['AB1', 'ABI', 'ABIF']: #establish orientation of DNA if filename.split('.')[0][-2:].upper() == 'FW': self.setOrientation('fw') elif filename.split('.')[0][-2:].upper() == 'RV': self.setOrientation('rv') else: raise TypeError, 'The last two characters of the filename (before the .) must specify whether the sequence is fw or rv. Pleace rename file %s accordingly' % filename self.setName(filename) ab1 = ABIreader.Trace(self.filepath, trimming=True) #optionally ', trimming=True' if self.getOrientation() == 'fw': self.setDNA(ab1.seq) self.setQualVal(ab1.qual_val) #need to RC this too self.setTrace([ab1.data['raw1'], ab1.data['raw2'], ab1.data['raw3'], ab1.data['raw4']]) #need to RC this too #abi=dict(baseorder=ab1.data['baseorder'], qual_val=ab1.qual_val, G=str(AB1Trace.data['raw1']), A=str(AB1Trace.data['raw2']), T=str(AB1Trace.data['raw3']), C=str(AB1Trace.data['raw4'])) elif self.getOrientation() == 'rv': self.setDNA(DNA.RC(ab1.seq)) self.setQualVal(ab1.qual_val) #need to RC this too self.setTrace([ab1.data['raw1'], ab1.data['raw2'], ab1.data['raw3'], ab1.data['raw4']]) #need to RC this too #abi=dict(baseorder=ab1.data['baseorder'], qual_val=ab1.qual_val, G=str(AB1Trace.data['raw1']), A=str(AB1Trace.data['raw2']), T=str(AB1Trace.data['raw3']), C=str(AB1Trace.data['raw4'])) self.setRC(True) # elif self.input_type == 'ZTR': # print('Support for .ztr files has not yet been implemented') # elif self.input_type == 'SCF': # print('Support for .scf files has not yet been implemented') elif fnmatch.fnmatch(filename, '*.fasta'): self.setName(filename) id, dna = fasta.parseFile(self.filepath) #parse the fasta file. File should contain ONE entry self.setDNA(dna) #establish orientation of DNA if filename.split('.')[0][-2:].upper() == 'FW': self.setOrientation('fw') elif filename.split('.')[0][-2:].upper() == 'RV': self.setOrientation('rv') else: raise TypeError, 'The last two characters of the filename (before the .) must specify whether the sequence is fw or rv. Pleace rename file %s accordingly' % filename elif fnmatch.fnmatch(filename, '*.fastq'): self.setName(filename) id, dna, id2, qual_val = fastq.parse(self.filepath) #parse the fastq file. File should contain ONE entry self.setDNA(dna) self.setQualVal(qual_val) #establish orientation of DNA if filename.split('.')[0][-2:].upper() == 'FW': self.setOrientation('fw') elif filename.split('.')[0][-2:].upper() == 'RV': self.setOrientation('rv') else: raise TypeError, 'The last two characters of the filename (before the .) must specify whether the sequence is fw or rv. Pleace rename file %s accordingly' % filename else: pass print('"%s" is not a .txt, .seq, .scf, .fasta, .fastq, .abif, .ab1, .abi or .ztr file' % filename)