本文整理汇总了Python中Bio.SeqIO.read方法的典型用法代码示例。如果您正苦于以下问题:Python SeqIO.read方法的具体用法?Python SeqIO.read怎么用?Python SeqIO.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bio.SeqIO
的用法示例。
在下文中一共展示了SeqIO.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: seq
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def seq(self):
"""Seq: Get the Seq object from the sequence file, metadata file, or in memory"""
if self.sequence_file:
log.debug('{}: reading sequence from sequence file {}'.format(self.id, self.sequence_path))
tmp_sr = SeqIO.read(self.sequence_path, 'fasta')
return tmp_sr.seq
elif self.metadata_file:
log.debug('{}: reading sequence from metadata file {}'.format(self.id, self.metadata_path))
tmp_sr = SeqIO.read(self.metadata_path, 'uniprot-xml')
return tmp_sr.seq
else:
if not self._seq:
log.debug('{}: no sequence stored in memory'.format(self.id))
else:
log.debug('{}: reading sequence from memory'.format(self.id))
return self._seq
示例2: features
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def features(self):
"""list: Get the features from the feature file, metadata file, or in memory"""
if self.feature_file:
log.debug('{}: reading features from feature file {}'.format(self.id, self.feature_path))
with open(self.feature_path) as handle:
feats = list(GFF.parse(handle))
if len(feats) > 1:
log.warning('Too many sequences in GFF')
else:
return feats[0].features
elif self.metadata_file:
log.debug('{}: reading features from metadata file {}'.format(self.id, self.metadata_path))
tmp_sr = SeqIO.read(self.metadata_path, 'uniprot-xml')
return tmp_sr.features
else:
return self._features
示例3: metadata_path_unset
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def metadata_path_unset(self):
"""Copy features to memory and remove the association of the metadata file."""
if not self.metadata_file:
raise IOError('No metadata file to unset')
log.debug('{}: reading from metadata file {}'.format(self.id, self.metadata_path))
tmp_sr = SeqIO.read(self.metadata_path, 'uniprot-xml')
tmp_feats = tmp_sr.features
# TODO: should this be in separate unset functions?
self.metadata_dir = None
self.metadata_file = None
self.features = tmp_feats
if self.sequence_file:
tmp_sr = tmp_sr.seq
self.sequence_dir = None
self.sequence_file = None
self.seq = tmp_sr
示例4: fasta_files_equal
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def fasta_files_equal(seq_file1, seq_file2):
"""Check equality of a FASTA file to another FASTA file
Args:
seq_file1: Path to a FASTA file
seq_file2: Path to another FASTA file
Returns:
bool: If the sequences are the same
"""
# Load already set representative sequence
seq1 = SeqIO.read(open(seq_file1), 'fasta')
# Load kegg sequence
seq2 = SeqIO.read(open(seq_file2), 'fasta')
# Test equality
if str(seq1.seq) == str(seq2.seq):
return True
else:
return False
示例5: annotate_parents_for_tree
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def annotate_parents_for_tree(tree):
"""Annotate each node in the given tree with its parent.
>>> import io
>>> tree = Bio.Phylo.read(io.StringIO("(A, (B, C))"), "newick")
>>> not any([hasattr(node, "parent") for node in tree.find_clades()])
True
>>> tree = annotate_parents_for_tree(tree)
>>> tree.root.parent is None
True
>>> all([hasattr(node, "parent") for node in tree.find_clades()])
True
"""
tree.root.parent = None
for node in tree.find_clades(order="level"):
for child in node.clades:
child.parent = node
# Return the tree.
return tree
示例6: load_mask_sites
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def load_mask_sites(mask_file):
"""Load masking sites from either a BED file or a masking file.
Parameters
----------
mask_file: str
Path to the BED or masking file
Returns
-------
list[int]
Sorted list of unique zero-indexed sites
"""
if mask_file.lower().endswith(".bed"):
mask_sites = read_bed_file(mask_file)
else:
mask_sites = read_mask_file(mask_file)
print("%d masking sites read from %s" % (len(mask_sites), mask_file))
return mask_sites
示例7: prettify_alignment
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def prettify_alignment(aln):
'''
Converts all bases to uppercase and removes auto reverse-complement prefix (_R_).
This modifies the alignment in place.
Parameters
----------
aln : MultipleSeqAlign
Biopython Alignment
'''
for seq in aln:
seq.seq = seq.seq.upper()
# AlignIO.read repeats the ID in the name and description field
if seq.id.startswith("_R_"):
seq.id = seq.id[3:]
print("Sequence \"{}\" was reverse-complemented by the alignment program.".format(seq.id))
if seq.name.startswith("_R_"):
seq.name = seq.name[3:]
if seq.description.startswith("_R_"):
seq.description = seq.description[3:]
示例8: remove_exons
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def remove_exons(gff_filename,supercontig_filename,mode="all"):
'''Given a supercontig and corresponding annotation, remove the exon sequences. In "intron" mode, only return sequences specifically annotated as introns'''
exon_starts = []
exon_ends = []
gff = open(gff_filename).readlines()
for line in gff:
line = line.rstrip().split("\t")
if len(line) > 2:
if line[2] == "exon":
exon_starts.append(int(line[3]))
exon_ends.append(int(line[4]))
supercontig = SeqIO.read(supercontig_filename,'fasta')
exonless_contig = SeqRecord(Seq(''),id=supercontig.id)
start = 0
for exon in range(len(exon_starts)):
exonless_contig += supercontig[start:exon_starts[exon]-1]
start = exon_ends[exon]
exonless_contig += supercontig[start:]
exonless_contig.description = ''
return exonless_contig
示例9: __init__
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def __init__(self,in_obj,prefix):
if isinstance(in_obj[0],str):
self.filenames = in_obj
self.records = [SeqIO.read(x,'abi') for x in self.filenames]
self.prefix = prefix
elif isinstance(in_obj[0],SeqIO.SeqRecord):
self.records = in_obj
self.prefix = prefix
self.quals = {}
for rec in self.records:
self.quals[rec.name] = [ord(x) for x in rec.annotations["abif_raw"]["PCON1"]]
self.trimmed_coords = {}
for rec in self.records:
trim_seq = str(SeqIO.AbiIO._abi_trim(rec).seq)
start = str(rec.seq).index(trim_seq)
end = start+len(trim_seq)
self.trimmed_coords[rec.name] = list(range(start,end))
示例10: ref
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def ref(self, in_ref):
"""
Parameters
----------
in_ref : file name, str, Bio.Seq.Seq, Bio.SeqRecord.SeqRecord
reference sequence will read and stored a byte array
"""
read_from_file=False
if in_ref and isfile(in_ref):
for fmt in ['fasta', 'genbank']:
try:
in_ref = SeqIO.read(in_ref, fmt)
self.logger("SequenceData: loaded reference sequence as %s format"%fmt,1)
read_from_file=True
break
except:
continue
if not read_from_file:
raise TypeError('SequenceData.ref: reference sequence file %s could not be parsed, fasta and genbank formats are supported.')
if in_ref:
self._ref = seq2array(in_ref, fill_overhangs=False, word_length=self.word_length)
self.full_length = self._ref.shape[0]
self.compressed_to_full_sequence_map = None
self.multiplicity = None
示例11: __copyFileHandle
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def __copyFileHandle(self, result_handle, fname ):
"""
Copy the blast result to a file. The input file handle will be
empty afterwards! Use the returned string handle instead.
@param result_handle: file handle returned by NCBI* blast runners
@type result_handle: file
@param fname : absolute path to output file
@type fname : str
@return: a fresh 'file' (string) handle with the output
@rtype : cStringIO.StringI
"""
str_results = result_handle.read()
try:
save_file = open( fname, 'w' )
save_file.write( str_results )
save_file.close()
finally:
return cStringIO.StringIO( str_results )
示例12: metadata_path
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def metadata_path(self, m_path):
"""Provide pointers to the paths of the metadata file
Args:
m_path: Path to metadata file
"""
if not m_path:
self.metadata_dir = None
self.metadata_file = None
else:
if not op.exists(m_path):
raise OSError('{}: file does not exist!'.format(m_path))
if not op.dirname(m_path):
self.metadata_dir = '.'
else:
self.metadata_dir = op.dirname(m_path)
self.metadata_file = op.basename(m_path)
# Parse the metadata file using Biopython's built in SeqRecord parser
# Just updating IDs and stuff
tmp_sr = SeqIO.read(self.metadata_path, 'uniprot-xml')
parsed = parse_uniprot_xml_metadata(tmp_sr)
self.update(parsed, overwrite=True)
示例13: sequence_path
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def sequence_path(self, fasta_path):
"""Provide pointers to the paths of the FASTA file
Args:
fasta_path: Path to FASTA file
"""
if not fasta_path:
self.sequence_dir = None
self.sequence_file = None
else:
if not op.exists(fasta_path):
raise OSError('{}: file does not exist'.format(fasta_path))
if not op.dirname(fasta_path):
self.sequence_dir = '.'
else:
self.sequence_dir = op.dirname(fasta_path)
self.sequence_file = op.basename(fasta_path)
tmp_sr = SeqIO.read(fasta_path, 'fasta')
if self.name == '<unknown name>':
self.name = tmp_sr.name
if self.description == '<unknown description>':
self.description = tmp_sr.description
if not self.dbxrefs:
self.dbxrefs = tmp_sr.dbxrefs
if not self.features:
self.features = tmp_sr.features
if not self.annotations:
self.annotations = tmp_sr.annotations
if not self.letter_annotations:
self.letter_annotations = tmp_sr.letter_annotations
示例14: seq_record_loaded_from_file_example
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def seq_record_loaded_from_file_example(fasta_path):
"""Original SeqRecord loaded from sequence file"""
return SeqIO.read(fasta_path, "fasta")
示例15: xml_record_loaded_from_file_example
# 需要导入模块: from Bio import SeqIO [as 别名]
# 或者: from Bio.SeqIO import read [as 别名]
def xml_record_loaded_from_file_example(xml_path):
"""Original SeqRecord loaded from sequence file"""
return SeqIO.read(xml_path, "uniprot-xml")