How to use get_open_func method in autotest

Best Python code snippet using autotest_python

misc.py

Source:misc.py Github

copy

Full Screen

...16 """17 Returns the names and sequences for the given fasta file as a list of tuples (name, seq).18 """19 fasta_seqs = []20 with get_open_func(filename)(filename, 'rt') as fasta_file:21 name = ''22 sequence = ''23 for line in fasta_file:24 line = line.strip()25 if not line:26 continue27 if line[0] == '>': # Header line = start of new contig28 if name:29 fasta_seqs.append((name.split()[0], sequence.upper()))30 sequence = ''31 name = line[1:]32 else:33 sequence += line34 if name:35 fasta_seqs.append((name.split()[0], sequence.upper()))36 return fasta_seqs37def get_compression_type(filename):38 """39 Attempts to guess the compression (if any) on a file using the first few bytes.40 http://stackoverflow.com/questions/1304456241 """42 magic_dict = {'gz': (b'\x1f', b'\x8b', b'\x08'),43 'bz2': (b'\x42', b'\x5a', b'\x68'),44 'zip': (b'\x50', b'\x4b', b'\x03', b'\x04')}45 max_len = max(len(x) for x in magic_dict)46 unknown_file = open(filename, 'rb')47 file_start = unknown_file.read(max_len)48 unknown_file.close()49 compression_type = 'plain'50 for file_type, magic_bytes in magic_dict.items():51 if file_start.startswith(magic_bytes):52 compression_type = file_type53 if compression_type == 'bz2':54 sys.exit('Error: cannot use bzip2 format - use gzip instead')55 if compression_type == 'zip':56 sys.exit('Error: cannot use zip format - use gzip instead')57 return compression_type58def get_open_func(filename):59 if get_compression_type(filename) == 'gz':60 return gzip.open61 else: # plain text62 return open63REV_COMP_DICT = {'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G', 'a': 't', 't': 'a', 'g': 'c', 'c': 'g',64 'R': 'Y', 'Y': 'R', 'S': 'S', 'W': 'W', 'K': 'M', 'M': 'K', 'B': 'V', 'V': 'B',65 'D': 'H', 'H': 'D', 'N': 'N', 'r': 'y', 'y': 'r', 's': 's', 'w': 'w', 'k': 'm',66 'm': 'k', 'b': 'v', 'v': 'b', 'd': 'h', 'h': 'd', 'n': 'n', '.': '.', '-': '-',67 '?': '?'}68def complement_base(base):69 try:70 return REV_COMP_DICT[base]71 except KeyError:72 return 'N'...

Full Screen

Full Screen

find_unclassified.py

Source:find_unclassified.py Github

copy

Full Screen

...25 return args26def main():27 args = get_arguments()28 unclassified_reads = set()29 with get_open_func(args.cent_1)(args.cent_1, 'rt') as cent_1_file:30 for line in cent_1_file:31 parts = line.strip().split('\t')32 read_name, classification = parts[0], parts[1]33 if read_name == 'readID' or classification == 'unclassified':34 # include the header as well as unclassified reads35 unclassified_reads.add(read_name)36 with get_open_func(args.cent_2)(args.cent_2, 'rt') as cent_2_file:37 for line in cent_2_file:38 line = line.strip()39 parts = line.split('\t')40 read_name = parts[0]41 if read_name in unclassified_reads:42 print(line)43def get_compression_type(filename):44 """45 Attempts to guess the compression (if any) on a file using the first few bytes.46 http://stackoverflow.com/questions/1304456247 """48 magic_dict = {'gz': (b'\x1f', b'\x8b', b'\x08'),49 'bz2': (b'\x42', b'\x5a', b'\x68'),50 'zip': (b'\x50', b'\x4b', b'\x03', b'\x04')}51 max_len = max(len(x) for x in magic_dict)52 unknown_file = open(filename, 'rb')53 file_start = unknown_file.read(max_len)54 unknown_file.close()55 compression_type = 'plain'56 for file_type, magic_bytes in magic_dict.items():57 if file_start.startswith(magic_bytes):58 compression_type = file_type59 if compression_type == 'bz2':60 sys.exit('Error: cannot use bzip2 format - use gzip instead')61 if compression_type == 'zip':62 sys.exit('Error: cannot use zip format - use gzip instead')63 return compression_type64def get_open_func(filename):65 if get_compression_type(filename) == 'gz':66 return gzip.open67 else: # plain text68 return open69if __name__ == '__main__':...

Full Screen

Full Screen

racon_utils.py

Source:racon_utils.py Github

copy

Full Screen

...39 elif first_char == "@":40 return "FASTQ"41 else:42 raise ValueError("<E> get_sequence_file_type: File is neither FASTA or FASTQ")43def get_open_func(filename: str):44 """test which open function to use"""45 if get_compression_type(filename) == "gz":46 return gzip.open47 else: # plain text48 return open49def iterate_fasta(filename: str) -> []:50 """iterate fasta file"""51 if get_sequence_file_type(filename) != "FASTA":52 log("<E> iterate_fasta: Error: {} is not FASTA format".format(filename))53 raise StopIteration54 with get_open_func(filename)(filename, "rt") as fasta:55 for line in fasta:56 line = line.strip()57 if len(line) == 0:58 continue59 if not line.startswith(">"):60 continue61 name = line[1:].split()[0]62 sequence = next(fasta).strip()63 yield name, sequence64def iterate_fastq(filename: str) -> []:65 """iterate fastq file"""66 if get_sequence_file_type(filename) != "FASTQ":67 log("<E> iterate_fastq: Error: {} is not FASTQ format".format(filename))68 raise StopIteration69 with get_open_func(filename)(filename, "rt") as fastq:70 for line in fastq:71 line = line.strip()72 if len(line) == 0:73 continue74 if not line.startswith("@"):75 continue76 name = line[1:].split()[0]77 sequence = next(fastq).strip()78 _ = next(fastq)79 qualities = next(fastq).strip()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful