def test_sbol(self): # feat = os.path.join(TEST_DATA, 'pEGBAn11.gb') # print feat.genbank_file seq = read(os.path.join(TEST_DATA, 'pEGBAn11.gb'), 'gb') fhand = open('/tmp/sbol.xml', 'w') fhand.write(convert_to_sbol(seq)) fhand.close()
def test_single_contig(self): record = read(fspath(self.data / "U00096-3.fasta"), "fasta") with (self.data / "U00096-3.fasta.chopped.fasta").open() as f: expected = list(parse(f, "fasta")) with tempfile.NamedTemporaryFile(mode="rt", suffix=".fna") as tmp: orthoani._chop(record, tmp.name, 1020) actual = list(parse(tmp, "fasta")) for actual_record, expected_record in zip(actual, expected): self.assertEqual(actual_record.seq, expected_record.seq)
def reference(ctx, verbose, primer_begin, primer_end, start_codon, end_codon, reference, input, output): numeric_level = get_verbosity_level(verbose) logging.basicConfig(level=numeric_level) click.echo("Creating reference library with primer {}{}-->{}{}".format( primer_begin, start_codon * "N", end_codon * -1 * "N", primer_end)) reference_seq = str(read(reference, "fasta").seq) reference_library = ReferenceLibrary(primer_begin, primer_end, reference_seq, start_codon, end_codon) reference_library.apply(input) reference_library.to_json(output)
def feature_sbol(request, uniquename): user = request.user print(uniquename) try: feat = Feature.objects.get(uniquename=uniquename) except Feature.DoesNotExist: feat = None if feat is None: return Http404 if (feat.is_public or (user.is_staff or user == feat.owner)): seq = read(feat.genbank_file, 'gb') response = HttpResponse(convert_to_sbol(seq), content_type='xml/plain') filename = seq.name + '.xml' response['Content-Disposition'] = 'attachment; ' response['Content-Disposition'] += 'filename="{0}"'.format(filename) return response else: return HttpResponseForbidden
matrix_file = arguments['--matrix'] with open(matrix_file, 'r') as matrix_file: matrice_dict = substitution_matrices.read(matrix_file) aligner.substitution_matrix = matrice_dict else: aligner.match_score = int(arguments['--matchscore']) aligner.mismatch_score = int(arguments['--mismatchscore']) aligner.open_gap_score = int(arguments['--opengapscore']) aligner.extend_gap_score = int(arguments['--extendgapscore']) out_file = arguments['-o'] input_file_format = arguments['--informat'] if len(input_files) == 2: sequences = [ read(input_file, input_file_format) for input_file in input_files ] first = sequences[0] second = sequences[1] elif len(input_files) == 1: sequences = parse(input_files[0], input_file_format) first = next(sequences) second = next(sequences) else: raise (RuntimeError( 'Please provide exactly 1 or 2 sequences in each file')) score = aligner.score(first.seq, second.seq) print(f'Maximum score: {score}') alignments = aligner.align(first.seq, second.seq) with open(out_file, 'w') as out_file:
info = { "resistance": resistance, # "name": id_, "id": id_, # "type": type_, "location": row.find("b").text.strip().replace(" / ", ""), "addgene_id": row.find("a").get("href").strip("/"), } # get the ZIP sequence for path in ("{} cor.gbk", "{}.gbk", "{}.gb"): if archive.exists(path.format(id_)): break with archive.open(path.format(id_), encoding="latin-1") as f: rec = f.read().replace("Exported File", "Exported ") gb_archive = CircularRecord(read(six.StringIO(rec), "gb")) # get the AddGene sequences page url = "https://www.addgene.org/{}/sequences/".format(info["addgene_id"]) with session.get(url) as res: soup = bs.BeautifulSoup(res.text, "html.parser") # get the addgene full sequence gb_url = soup.find("a", class_="genbank-file-download").get("href") with requests.get(gb_url) as res: gb = info["gb"] = CircularRecord(read(io.StringIO(res.text), "gb")) if id_ == "pICSL30008": gb = gb.reverse_complement(True, True, True, True, True, True, True) # elif id_ == "pICSL50004": # gb_archive = gb_archive.reverse_complement(True, True, True, True, True, True, True)
def setUpClass(cls): cls.data = pathlib.Path(__file__).parent / "data" cls.r1, cls.r2 = map(lambda p: read(fspath(p), "fasta"), cls.data.glob("1852379.*.fna"))
def main(): seq = read(sys.argv[1], 'fasta') qual = read(sys.argv[2], 'qual') seq.letter_annotations = qual.letter_annotations write(seq, sys.stdout, 'fastq')
# "type": type_, "location": row.find("b").text.strip().replace(" / ", ""), "addgene_id": row.find("a").get("href").strip("/"), } # get the online full sequence if id_ in FULL_SEQUENCES: # Load the AddGene sequences page and get the full sequence with requests.get(FULL_SEQUENCES[id_]) as res: soup = bs.BeautifulSoup(res.text, "html.parser") section = soup.find("section", id="depositor-full") gb_url = soup.find("a", class_="genbank-file-download").get('href') # Get the Genbank file with requests.get(gb_url) as res: gb = CircularRecord(read(io.StringIO(res.text), "gb")) # get the pBP-SJM901 sequence and patch it elif id_.startswith("pBP-SJM"): # get pBP-SJM # Load the AddGene sequences page and get the full sequence with requests.get(FULL_SEQUENCES["pBP-SJM901"]) as res: soup = bs.BeautifulSoup(res.text, "html.parser") section = soup.find("section", id="depositor-full") gb_url = soup.find("a", class_="genbank-file-download").get('href') # Get the Genbank file with requests.get(gb_url) as res: gb = CircularRecord(read(io.StringIO(res.text), "gb")) # replace the target sequence gb.seq = Seq(
# Update the progress bar it.set_description(id_) # extract info info = { "resistance": resistance, # "name": id_, "id": id_, # "type": type_, "location": row.find("b").text.strip().replace(" / ", ""), "addgene_id": row.find("a").get("href").strip("/"), } # get the ZIP sequence with archive.open("{}.gb".format(id_)) as f: gb_archive = CircularRecord(read(f, "gb")) pref, _ = BB_PREFIX.search(gb_archive).span() gb_archive <<= pref - 1 # get the AddGene sequences page url = "https://www.addgene.org/{}/sequences/".format( info["addgene_id"]) with session.get(url) as res: soup = bs.BeautifulSoup(res.text, "html.parser") # No full sequence available, but it's actually almost the same # as DVK_EF, so we can simply patch the sequence and it will be # fine if id_ in ("DVK_AE", "DVK_AF"): # Load the DVK_EF page and find the GenBank file link
"location": row.find("b").text.strip().replace(" / ", ""), "addgene_id": row.find("a").get("href").strip("/"), } # get the AddGene sequences page url = "https://www.addgene.org/{}/sequences/".format( info["addgene_id"]) with session.get(url) as res: soup = bs.BeautifulSoup(res.text, "html.parser") # get the addgene full sequence section = soup.find("section", id="addgene-full") gb_url = section.find("a", class_="genbank-file-download").get("href") with requests.get(gb_url) as res: gbd = info["gb_depositor"] = CircularRecord( read(io.StringIO(res.text), "gb")) # get the AddGene plasmid page url = "https://www.addgene.org/{}/".format(info["addgene_id"]) with session.get(url) as res: soup = bs.BeautifulSoup(res.text, "html.parser") # get the deposited record section = soup.find("ul", class_="addgene-document-list") gb_url = section.find("a").get("href") with requests.get(gb_url) as res: gba = info["gb_addgene"] = CircularRecord( read(io.StringIO(res.text), "gb")) # Sanity check if len(gba) != len(gbd):