Hot answers tagged

6

You can specify send to stdout using out='-' in the Biopython wrapper. from Bio.Blast.Applications import NcbiblastnCommandline import pandas as pd cline = NcbiblastnCommandline(query='seq.fna', subject='seq2.fna', outfmt=6, out='-') output = cline()[0].strip() rows = [line.split() for line in output.splitlines()] cols = ['qseqid', 'sseqid', 'pident', '...


6

Your setup: import pandas as pd dict1 = {0:['chr1','chr1','chr1','chr1','chr2'], 1:[1, 100, 150, 900, 1], 2:[100, 200, 500, 950, 100], 3:['feature1', 'feature2', 'feature3', 'feature4', 'feature4'], 4:[0, 0, 0, 0, 0], 5:['+','+','-','+','+']} df1 = pd.DataFrame(dict1) print(df1) ## 0 1 2 3 4 5 ## 0 chr1 1 100 ...


4

I don't think Pandas has this implemented functionality out-of-the-box. Even if it did, solutions not designed specifically for bioinformatics probably rarely handle intervals on different chromosomes correctly unless you split the intervals by chromosome first. Pandas does handle intervals (see docs for the Interval and IntervalIndex classes), but I've ...


3

# pip install pyranges or conda install -c bioconda pyranges import pyranges as pr g1 = pr.from_string("""Chromosome Start End chr1 222 223 chr1 223 224 chr1 233 234 chr1 235 236 chr1 2237 238 chr1 2123 2124 chr2 244 245""") g2 = pr.from_string("""Chromosome Start End chr1 221 223 chr1 230 ...


2

As mentioned by OP, another option is to use pybedtools, which in my opinion is pretty convenient for people already familiar with BedTools. Let's even say df1's format is slightly different than df2: import pandas as pd dict1 = {0: ['chr1', 'chr1', 'chr1', 'chr1', 'chr2'], 1: [1, 100, 150, 900, 1], 2: [100, 200, 500, 950, 100], 3: ['...


2

I implemented pandas "Intervals" and ... it should be a few lines, clearly there are limitations. For non-overlapping data it is very cool however. It will work for overlapping data, BUT if the data you are using as the interval data is overlapping, it falls over. It could work if an independent (non-overlapping) interval was constructed. Anyway, the point ...


2

Just to clarify, when I asked you to share some of your files, I meant to share them in a way that I can reproduce your issue from start to finish. You read from at least four different files in a quadruple for-loop and I'm pretty sure your goal could be achieved much more straightforwardly than your current implementation. Without a reproducible example, I ...


2

The manual says fields in a tabular output file are space-delimited. It should be fairly straightforward to load a space-delimited file in pandas. From the manual: --tblout <f> Save a simple tabular (space-delimited) file summarizing the per-target output, with one data line per homologous target model found.


1

cluster_0 to cluster_12 are just strings. they cannot be the names of arrays or matrices. Strings can only be used in print statements and string processing statements. The correct way to define an array or matrix is as follows: call the arrays as: cluster[0] to cluster[12] then, assign: for i in range(12): cluster[i] = gene_list.gene[...


1

solution from @sören: I came up with this solution for my problem: from Bio.KEGG import REST as kegg def _get_kegg(kegg_id): kegg_output = kegg.kegg_get(kegg_id).read() results = {} for line in kegg_output.split('\n'): splits = line.split() if not line.startswith(' '): if len(splits) > 0: key = ...


Only top voted, non community-wiki answers of a minimum length are eligible