Best Python code snippet using autotest_python
misc.py
Source: misc.py
...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'...
find_unclassified.py
Source: find_unclassified.py
...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__':...
racon_utils.py
Source: racon_utils.py
...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()...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!