當前位置: 首頁>>代碼示例>>Python>>正文


Python SeqIO.parse方法代碼示例

本文整理匯總了Python中Bio.SeqIO.parse方法的典型用法代碼示例。如果您正苦於以下問題:Python SeqIO.parse方法的具體用法?Python SeqIO.parse怎麽用?Python SeqIO.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Bio.SeqIO的用法示例。


在下文中一共展示了SeqIO.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: read_fasta

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def read_fasta(mirna_fasta_file, mrna_fasta_file):
    handle = open(mirna_fasta_file, "rU")
    mirna_list = list(SeqIO.parse(handle, "fasta"))
    handle.close()

    handle = open(mrna_fasta_file, "rU")
    mrna_list = list(SeqIO.parse(handle, "fasta"))
    handle.close()

    mirna_ids = []
    mirna_sequences = []
    mrna_ids = []
    mrna_sequences = []

    for i in range(len(mirna_list)):
        mirna_ids.append(str(mirna_list[i].id))
        mirna_sequences.append(str(mirna_list[i].seq))

    for i in range(len(mrna_list)):
        mrna_ids.append(str(mrna_list[i].id))
        mrna_sequences.append(str(mrna_list[i].seq))

    return (mirna_ids, mirna_sequences, mrna_ids, mrna_sequences) 
開發者ID:kipoi,項目名稱:models,代碼行數:25,代碼來源:bio_utils.py

示例2: encode_bio_sequence

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def encode_bio_sequence(fname, file_type="fasta", letters="ATCGN"):
  """
  Loads a sequence file and returns an array of one-hot sequences.

  Parameters
  ----------
  fname: str
    Filename of fasta file.
  file_type: str
    The type of file encoding to process, e.g. fasta or fastq, this
    is passed to Biopython.SeqIO.parse.
  letters: str
    The set of letters that the sequences consist of, e.g. ATCG.

  Returns
  -------
  np.ndarray: Shape (N_sequences, N_letters, sequence_length, 1).
  """

  from Bio import SeqIO

  sequences = SeqIO.parse(fname, file_type)
  return seq_one_hot_encode(sequences, letters) 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:25,代碼來源:genomics.py

示例3: count_records

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def count_records(fasta_file):
    """Count the number of records in a fasta file and return a list of
    recods id

    Args:
        fasta_file (string): the path to a fasta file

    Returns:
        list: a list of record ids
    """
    logger = logging.getLogger(__name__)
    record_list = []
    for record in SeqIO.parse(fasta_file, "fasta"):
        record_list.append(record.id)
    try:
        assert len(record_list) != 0
    except AssertionError as e:
        logger.error(
            'Failed to find records in genome(s) file:%s' % fasta_file)
        sys.exit(1)
    else:
        return record_list 
開發者ID:HadrienG,項目名稱:InSilicoSeq,代碼行數:24,代碼來源:util.py

示例4: READ_FASTA_ENTRY

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def READ_FASTA_ENTRY(file_name):
    fasta_sequences=[]
    sequence_name=[]
    full_names_dict={}

    sequences_dict={}

    
    if os.stat(file_name)[6]!=0: #not empty
       
        fh = open(file_name, "r")
        for record in SeqIO.parse(fh, "fasta"):
            short_name=str(record.id).split(' ')[0]
            sequences_dict[short_name]=str(record.seq)

        
    return sequences_dict



#------------------------------------------------------------------------------------------ 
開發者ID:uio-cels,項目名稱:NucDiff,代碼行數:23,代碼來源:ref_coord.py

示例5: READ_FASTA_ENTRY

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def READ_FASTA_ENTRY(file_name):
    fasta_sequences=[]
    sequence_name=[]
    full_names_dict={}

    sequences_dict={}

    
    if os.stat(file_name)[6]!=0: #not empty
       
        fh = open(file_name, "r")
        for record in SeqIO.parse(fh, "fasta"):
            short_name=str(record.id).split(' ')[0]
            sequence_name.append(short_name)
            full_names_dict[short_name]=str(record.id)

            fasta_sequences.append(str(record.seq))
            sequences_dict[short_name]=str(record.seq)

        
    return sequences_dict,fasta_sequences, sequence_name, full_names_dict 
開發者ID:uio-cels,項目名稱:NucDiff,代碼行數:23,代碼來源:general.py

示例6: _read_reference

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def _read_reference(self, reference):
        """Read in the reference from the file into a dictionary.

        Parameters
        ----------
        reference: str
            Path to the reference.

        Returns
        -------
        reference: dict
            Dictionary with chromosome - sequence mapping.
        """

        if reference is None:
            self._reference = None
        else:
            self._reference = {}

            with open(reference) as reference_fp:
                for record in SeqIO.parse(reference_fp, "fasta"):
                    self._reference[record.id] = list(record.seq) 
開發者ID:phe-bioinformatics,項目名稱:PHEnix,代碼行數:24,代碼來源:__init__.py

示例7: fetch_names

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def fetch_names(id_list):
    organism_names = {}

    # Doing 100 by 100 to make sure requests to NCBI are not too big
    for i in range(0, len(id_list), 100):
        j = i + 100
        if j >= len(id_list):
            j = len(id_list)

        sys.stderr.write(
            "Fetching entries from %s to %s from GenBank\n" % (i, j))
        sys.stderr.flush()
        result_handle = Entrez.efetch(db=db, rettype="gb", id=id_list[i:j])

        # Populate result per organism name
        for record in parse(result_handle, 'genbank'):
            # Using NCBI name, which should match accession number passed
            organism_names[record.name] = record.annotations['organism']

    return organism_names 
開發者ID:phageParser,項目名稱:phageParser,代碼行數:22,代碼來源:organism_name_update.py

示例8: addspacerstodict

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def addspacerstodict(gendict, sfile):
    spacerrecords = SeqIO.parse(sfile, 'fasta')
    for record in spacerrecords:
        accessions = record.name.split('|')
        sequence = str(record.seq)
        for acc in accessions:
            acc_elems = acc.split('_')
            order = acc_elems[-1]
            acc_id = '_'.join(acc_elems[:-1])
            try:
                if 'Spacers' in gendict[acc_id]:
                    gendict[acc_id]['Spacers'][order] = sequence
                else:
                    gendict[acc_id]['Spacers'] = {order: sequence}
            except KeyError:
                print('Error on accession id:  %s' % acc_id)
    return gendict 
開發者ID:phageParser,項目名稱:phageParser,代碼行數:19,代碼來源:populate.py

示例9: compare_outputs

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def compare_outputs(reference_db, test_db, out_name):
    reference_ids = {}
    print('Expect the following sequences to be predicted to be eukaryotic:')
    for record in SeqIO.parse(reference_db, "fasta"):
        reference_ids[record.id] = 0
        print(record.id)

    #Check for enexptected output
    print('The following sequences were predicted to be eukaryotic:')
    for record in SeqIO.parse(test_db, "fasta"):
        print(record.id)
        if record.id not in reference_ids:
            print('\nUnexpected scaffold %s in %s' % (record.id, out_name))
            return True
        else:
            reference_ids[record.id] = 1

    #Check for missing output
    for scaffold in reference_ids:
        if reference_ids[scaffold] is 0:
            print('\nMissing scaffold %s in %s' % (scaffold, out_name))
            return True
    return False 
開發者ID:patrickwest,項目名稱:EukRep,代碼行數:25,代碼來源:EukRep_tests.py

示例10: find_gaps

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def find_gaps(input_filename):
    # Load the original FASTA sequence.
    fasta = SeqIO.parse(input_filename, "fasta")

    for record in fasta:
        gap_start = None  # Not in a gap

        for i in _range(len(record)):

            if record.seq[i].upper() == "N":
                if gap_start is None:
                    gap_start = i
            else:
                if gap_start is not None:
                    print("\t".join(map(str, (record.id, gap_start, i))))
                    gap_start = None

        if gap_start is not None:
            print("\t".join(map(str, (record.id, gap_start, len(record))))) 
開發者ID:EichlerLab,項目名稱:smrtsv2,代碼行數:21,代碼來源:find_fasta_gaps.py

示例11: _align_proteins_to_hmm

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def _align_proteins_to_hmm(self, protein_sequences, hmm_file):
        '''hmmalign proteins to hmm, and return an alignment object

        Parameters
        ----------
        protein_sequences: generator / list of tuple(name,sequence) objects
        from SeqReader().

        '''
        cmd = "hmmalign '{}' /dev/stdin".format(hmm_file)
        output = extern.run(cmd, stdin=''.join([
            ">{}\n{}\n".format(s[0], s[1]) for s in protein_sequences]))
        protein_alignment = []
        for record in SeqIO.parse(StringIO(output), 'stockholm'):
            protein_alignment.append(AlignedProteinSequence(record.name, str(record.seq)))
        if len(protein_alignment) > 0:
            logging.debug("Read in %i aligned sequences e.g. %s %s" % (
                len(protein_alignment),
                protein_alignment[0].name,
                protein_alignment[0].seq))
        else:
            logging.debug("No aligned sequences found for this HMM")
        return protein_alignment 
開發者ID:wwood,項目名稱:singlem,代碼行數:25,代碼來源:pipe.py

示例12: main

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def main(args):
    for record in SeqIO.parse(args.infile, 'fasta'):
        if args.discard:
            if sum([1 for rx in args.discard if re.match(rx, record.id)]) > 0:
                continue

        subseqcounter = 0
        printlog(args.debug, "DEBUG: convert to upper case", record.id)
        sequence = str(record.seq).upper()
        printlog(args.debug, "DEBUG: split seq by Ns", record.id)
        subseqs = [ss for ss in re.split('[^ACGT]+', sequence) if len(ss) > args.minlength]
        printlog(args.debug, "DEBUG: print subseqs", record.id)
        for subseq in subseqs:
            subseqcounter += 1
            subid = '{:s}_chunk_{:d}'.format(record.id, subseqcounter)
            subrecord = SeqRecord(Seq(subseq), subid, '', '')
            SeqIO.write(subrecord, args.outfile, 'fasta') 
開發者ID:kevlar-dev,項目名稱:kevlar,代碼行數:19,代碼來源:prep-genome.py

示例13: filter_se_fastq_by_qual

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def filter_se_fastq_by_qual(fastq_filename,output_filename=None,min_bp_quality=20,min_single_bp_quality=0):

        if fastq_filename.endswith('.gz'):
                fastq_handle=gzip.open(fastq_filename)
        else:
                fastq_handle=open(fastq_filename)

        if not output_filename:
                output_filename=fastq_filename.replace('.fastq','').replace('.gz','')+'_filtered.fastq.gz'

        try:
            fastq_filtered_outfile=gzip.open(output_filename,'w+')

            for record in SeqIO.parse(fastq_handle, "fastq"):
                if np.array(record.letter_annotations["phred_quality"]).mean()>=min_bp_quality \
                and np.array(record.letter_annotations["phred_quality"]).min()>=min_single_bp_quality:
                    fastq_filtered_outfile.write(record.format('fastq'))
        except:
                raise Exception('Error handling the fastq_filtered_outfile')


        return output_filename 
開發者ID:lucapinello,項目名稱:CRISPResso,代碼行數:24,代碼來源:CRISPRessoCORE.py

示例14: filter_se_fastq_by_qual

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def filter_se_fastq_by_qual(fastq_filename,output_filename=None,min_bp_quality=20,min_single_bp_quality=0):

        if fastq_filename.endswith('.gz'):
                fastq_handle=gzip.open(fastq_filename)
        else:
                fastq_handle=open(fastq_filename)

        if not output_filename:
                output_filename=fastq_filename.replace('.fastq','').replace('.gz','')+'_filtered.fastq.gz'

        try: 
            fastq_filtered_outfile=gzip.open(output_filename,'w+')

            for record in SeqIO.parse(fastq_handle, "fastq"):
                if np.array(record.letter_annotations["phred_quality"]).mean()>=min_bp_quality \
                and np.array(record.letter_annotations["phred_quality"]).min()>=min_single_bp_quality:
                    fastq_filtered_outfile.write(record.format('fastq'))
        except:
                raise Exception('Error handling the fastq_filtered_outfile')

 
        return output_filename 
開發者ID:lucapinello,項目名稱:CRISPResso,代碼行數:24,代碼來源:CRISPRessoCountCORE.py

示例15: pasa_transcript2gene

# 需要導入模塊: from Bio import SeqIO [as 別名]
# 或者: from Bio.SeqIO import parse [as 別名]
def pasa_transcript2gene(input):
    # modify kallisto ouput to map gene names to each mRNA ID so you know what locus they have come from
    mRNADict = {}
    # since mRNA is unique, parse the transcript file which has mRNAID geneID in header
    with open(input, 'r') as transin:
        for line in transin:
            if line.startswith('>'):
                line = line.rstrip()
                line = line.replace('>', '')
                cols = line.split(' ')
                mRNAID = cols[0]
                geneID = cols[1]
                location = cols[-1]
                if not mRNAID in mRNADict:
                    mRNADict[mRNAID] = (geneID, location)
    return mRNADict 
開發者ID:nextgenusfs,項目名稱:funannotate,代碼行數:18,代碼來源:update.py


注:本文中的Bio.SeqIO.parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。