Best Python code snippet using sure_python
detect_format.py
Source: detect_format.py
1#!/usr/bin/python2# Filename: detect_format.py3import csv4import re5import os6import sys7from optparse import OptionParser8# A bit of path manipulation to import autozip.py from ../utils/9GETEV_MAIN_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))10if not GETEV_MAIN_PATH in sys.path:11 sys.path.insert(1, GETEV_MAIN_PATH)12del GETEV_MAIN_PATH13from utils import autozip14MAX_LINES_CHECKED = 10015def detect_format(file_input):16 """Detect the genetic data format of a file.17 Takes a path to a file, or a string generator (e.g. a filehandle).18 Tries to match one of the following:19 23ANDME: 23andme (microarray genotyping)20 CGIVAR: Complete Genomics var file21 deCODEme: deCODEme (microarray genotyping)22 GFF: General Feature Format23 VCF: Variant Call Format (only tested for 23andme exome data)24 """25 looks_like = dict()26 if isinstance(file_input, str):27 try:28 f_in = autozip.file_open(file_input, 'r')29 except AssertionError:30 f_in = autozip.file_open(file_input, 'r', 'deCODEme_scan.csv')31 print "deCODEme archive (deCODEme) detected"32 looks_like['deCODEme'] = True33 else:34 f_in = file_input35 line_count = 036 for line in f_in:37 line_count += 138 if any([looks_like[x] for x in looks_like.keys()]):39 break 40 if line_count > MAX_LINES_CHECKED:41 break42 # Check comment lines, if they exist, for information on file type.43 if re.match('#', line):44 if re.match(r'#TYPE.*VAR-ANNOTATION', line):45 print "Complete Genomics var file format (CGIVAR) detected"46 looks_like['CGIVAR'] = True47 if re.match(r'##gff-version', line):48 print "General Feature Format (GFF) detected"49 looks_like['GFF'] = True50 if re.match(r'# This data file generated by 23andMe', line):51 print "23andme microarray genotyping data (23ANDME) detected"52 looks_like['23ANDME'] = True53 if re.match(r'##fileformat=VCFv4', line):54 print "Variant Call Format (VCF) detected"55 looks_like['VCF'] = True56 # Look at other lines and decide based on their format.57 tsv_data = line.split('\t')58 csv_data = list(csv.reader([line]))[0]59 if ( len(csv_data) > 5 and60 re.match(r'rs', csv_data[0]) and61 re.match(r'[ACGT]', csv_data[1]) and62 re.match(r'[0-9]', csv_data[3]) and63 re.match(r'[+-]', csv_data[4]) and64 re.match(r'[ACGT]', csv_data[5]) ):65 print "deCODEme microarray genotyping data (deCODEme) guessed"66 looks_like['deCODEme'] = True67 if ( len(csv_data) > 3 and68 re.match(r'rs', csv_data[0]) and69 re.match(r'[0-9]', csv_data[2]) and70 re.match(r'[ACGT]', csv_data[3]) ):71 print "Family Tree DNA genotyping data (FTDNA) guessed"72 looks_like['FTDNA'] = True73 if ( len(tsv_data) > 3 and74 re.match(r'rs', tsv_data[0]) and 75 re.match(r'[0-9]', tsv_data[2]) and76 re.match(r'[ACGT][ACGT]', tsv_data[3]) ):77 print "23andme microarray genotyping data (23ANDME) guessed"78 looks_like['23ANDME'] = True79 if ( len(tsv_data) > 6 and80 re.match(r'chr', tsv_data[3]) and 81 re.match(r'[0-9]', tsv_data[4]) and 82 re.match(r'[0-9]', tsv_data[5]) and83 (tsv_data[6] == "no-call" or tsv_data[6] == "ref") ):84 print "Complete Genomics var file format (CGIvar) guessed"85 looks_like['CGIVAR'] = True86 if ( len(tsv_data) > 6 and87 re.match(r'[0-9]', tsv_data[3]) and88 re.match(r'[0-9]', tsv_data[4]) and89 tsv_data[6] == "+" ):90 print "General Feature Format (GFF) guessed"91 looks_like['GFF'] = True92 if ( len(tsv_data) > 7 and93 re.match(r'[0-9]', tsv_data[1]) and94 re.match(r'[ACGT]', tsv_data[3]) and95 re.match(r'[ACGT]', tsv_data[4]) and96 len(tsv_data[7].split(';')) > 2 ):97 print "Variant Call Format (VCF) guessed"98 looks_like['VCF'] = True99 100 if isinstance(file_input, str):101 f_in.close()102 if any([looks_like[x] for x in looks_like.keys()]):103 return [x for x in looks_like.keys() if looks_like[x]][0]104 else:105 return 'UNKNOWN'106def main():107 # Parse options108 usage = ("\n%prog -i inputfile\n"109 "%prog < inputfile")110 parser = OptionParser(usage=usage)111 parser.add_option("-i", "--input", dest="inputfile",112 help="Read genetic data from INFILE", metavar="INFILE")113 options, args = parser.parse_args()114 # Handle input115 if sys.stdin.isatty(): # false if data is piped in116 var_input = options.inputfile117 else:118 var_input = sys.stdin119 # Handle output120 format_type = detect_format(var_input)121 print format_type122if __name__ == "__main__":...
test_standardcomparator.py
Source: test_standardcomparator.py
...14 comp1 = InteratomicDistanceComparator(n_top=3,15 pair_cor_cum_diff=0.03,16 pair_cor_max=0.7,17 dE=0.3)18 assert comp1.looks_like(a1, a2)19 comp2 = InteratomicDistanceComparator(n_top=3,20 pair_cor_cum_diff=0.03,21 pair_cor_max=0.7,22 dE=0.15)23 assert not comp2.looks_like(a1, a2)24 comp3 = InteratomicDistanceComparator(n_top=3,25 pair_cor_cum_diff=0.02,26 pair_cor_max=0.7,27 dE=0.3)28 assert not comp3.looks_like(a1, a2)29 hard_E_comp = EnergyComparator(dE=1.0)30 assert hard_E_comp.looks_like(a1, a2)31 soft_E_comp = EnergyComparator(dE=.01)32 assert not soft_E_comp.looks_like(a1, a2)33 set_raw_score(a1, .1)34 set_raw_score(a2, .27)35 rs_comp = RawScoreComparator(0.15)36 assert not rs_comp.looks_like(a1, a2)37 comp1 = SequentialComparator([hard_E_comp, rs_comp], [0, 0])38 assert not comp1.looks_like(a1, a2)39 comp2 = SequentialComparator([hard_E_comp, rs_comp], [0, 1])...
Check out the latest blogs from LambdaTest on this topic:
Ever came across the situation where you really need to open a web page fast and it’s taking forever because of slow internet speed? May be someone in your network is downloading a torrent choking the bandwidth?
In today’s scenario, software testing has become an important entity across every domain for the benefits it offers. We have already explored a lot about software testing in general in our post need of software testing.
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Mobile Testing Tutorial.
Before development of a project begins, the project manager’s job is to determine which methodology should be used for the project life cycle. The 2 most popular methodologies are
In human physiology, vision plays a major role as 83% of the information humans perceive is via sight. So, your website should never lack in visual appeal. In web design, this is even more important. Every new iteration of design leaves some minor deviations. Sometimes, these minor visual deviations can be very hard to fix or unknowingly break the whole user experience. Hence, it is necessary to make sure that your website provides a perfect and working interface design to the user.
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!!