[Tutor] R: Tutor Digest, Vol 134, Issue 36

2015-04-13 Thread jarod...@libero.it
At the moment I use this way to resolve my question:
 re.findall(r'(\w+):\W(\d+)',str(tp[0]))

However please gave me you suggestion on how to improve my ability to use  
regular expression on python
Thanks so much!


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Regular expression on python

2015-04-13 Thread jarod...@libero.it
Dear all.
I would like to extract from some file some data.
The line I'm interested is this:

Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward Only 
Surviving: 17315 (0.81%) Reverse Only Surviving: 6413 (0.30%) Dropped: 308617 
(14.51%)



 with open("255.trim.log","r") as p:
for i in p:
lines= i.strip("\t")
if lines.startswith("Input"):
tp = lines.split("\t")
print re.findall("Input\d",str(tp))

So I started to find ":" from the row:
 with open("255.trim.log","r") as p:
for i in p:
lines= i.strip("\t")
if lines.startswith("Input"):
tp = lines.split("\t")
print re.findall(":",str(tp[0]))

And I'm able to find, but when I try to take the number using \d not work. 
Someone can explain why?
How can extract the numbers from this row.?
thanks so much=

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Execution of local data

2015-01-27 Thread jarod...@libero.it
I create a  list of local  object: but I can't execute as object only as string:
ena = Rnaseq(options.configura, options.rst)


job_1 = ena.trimmomatic()

job_2 = ena.star()
job_3 = ena.wiggle()
job_4 = ena.rnaseqc()
job_5 = ena.picard_sort_sam()
job_6 = ena.cufflinks
job_7 = ena.merge_trimmomatic_stats()
#ena.write_out(job2)
cmdset=[]
for item in locals().keys():
if item.startswith('job_'):
cmdset.append(item)

cmdset.sort()
for i in range(0,len(cmdset)):
 ena.prepare_run(cmdset[i])

 for i in range(0,len(cmdset)):
cmd=cmdset[i]
print type(cmd)
   .: 






ù
How can use the object created?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] R: Tutor Digest, Vol 131, Issue 60 order loop from methos on class

2015-01-26 Thread jarod...@libero.it
dear all,
thanks so much!! I  explain better  my problem :http://pastebin.com/iiPZMi2U

this is my workflow. Take my data from readset an create  a command list
ena = Rnaseq()
The order of the self.step are the order I wan to to execute my analisys. 
So this is the order:
In [160]: ena.show()
1- trimmomatic
2- merge_trimmomatic_stats
3- star
4- picard_sort_sam
5- rnaseqc
6- wiggle
7- cufflinks
8- cuffquant
9- gq_seq_utils_exploratory_analysis_rnaseq

First aim is to write a code to write all the pipeline .
up to now I use this:
job1 = ena.trimming()
ena.prepare_run(job1)
ena.prepare_run(job2)
..
the other aim is to selcet a range number to execute i.e. 2-9 or 1-4...

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] R: Re: Tutor Digest, Vol 131, Issue 59 Order loop from methos on class (jarod...@libero.it)

2015-01-26 Thread jarod...@libero.it
Thanks so much!! Now I understood it is a stupid thing!
So, could you elpme to decompose the problem?
I initiazlizate the class with the file to use so all the function have all 
the parameters that I need.

At the moment I have in mind only to do this:
ena = Rna()
job1 = ena.trim()
job2 = ena.align()
It is no so elegant..



Any suggestion?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] order loop from methos on class

2015-01-26 Thread jarod...@libero.it


Dear All,
What is the best way to loop on methos on a class?

class Rna():
def trim():
...
def align():
...

ena = Rna()

ena.trim()
ena.aling()



Thanks for any suggestion!!!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] R: Re: Re: Re: Class learning

2015-01-23 Thread jarod...@libero.it
Thanks so much for clear explanation!!! So in this way work . 
In [38]: Test().x.__name__
Out[38]: 'x'
The decoratory proprerty dosen't help to create the class in fast way.. When 
it is advisable use @property?


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] R: Re: Re: Class learning

2015-01-23 Thread jarod...@libero.it
This is the all code: http://pastebin.com/nYGEiXY4
I don't know well which i meas . I suppose it is the name  of the class (self.
__name__).  So  the  name  it is present.
it is correct?
thanks for the patience!
M.



>Messaggio originale
>Da: danny@gmail.com
>Data: 23/01/2015 11.08
>A: "jarod...@libero.it"
>Cc: "Python Tutor Mailing List"
>Ogg: Re: Re: [Tutor] Class learning
>
>On Fri, Jan 23, 2015 at 12:37 AM, jarod...@libero.it  
wrote:
>> Thanks for the help and patience!
>> It is a function on the class so I suppose for read that function  list I
>> need self.steps Where I'm wrong?
>> @property
>> def steps(self):
>> return [
>>
>> self.trimmomatic,
>> self.merge_trimmomatic_stats,
>> self.star,
>> self.picard_sort_sam,
>> self.rnaseqc,
>> self.wiggle,
>> self.cufflinks,
>> self.gq_seq_utils_exploratory_analysis_rnaseq
>>
>> ]
>>
>
>
>
>Do each of these elements in this list support the operations you're
>performing on any single step?
>
>That is, the code that you have here:
>
>def show(self):
>ftp="\n".join([str(idx + 1) + "- " + step.__name__  for idx,
>step in enumerate(self.steps)])
>
>seems to assume that every step must have a '__name__' property.
>
>But do all of the steps that you've put in there support '__name__'?
>


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] R: Re: Class learning

2015-01-23 Thread jarod...@libero.it
Thanks for the help and patience!
It is a function on the class so I suppose for read that function  list I need 
self.steps Where I'm wrong?
@propertydef steps(self):return [   
 self.trimmomatic,
self.merge_trimmomatic_stats,self.star, 
   self.picard_sort_sam,self.rnaseqc,   
 self.wiggle,self.cufflinks,
self.gq_seq_utils_exploratory_analysis_rnaseq   
 ]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Class learning

2015-01-22 Thread jarod...@libero.it
Dear All
How can gave the attributes __name__ to a function? 
class Foo(object):

 
def __init__(self):
steps = {}
tmp = open("rnaseq.base.ini","rb")
config.readfp(tmp)
readsets = 
parse_illumina_readset_file("/home/mauro/Desktop/readset.csv")


@property
def steps(self):
return [

self.one,
self.two,
self.fmit,


]
def one(self):
a = 5
return a
def two(self):
b = 5
return b

def fmit(self):
c = 7
return c

#@property
def show(self):
ftp="\n".join([str(idx + 1) + "- " + step.__name__  for idx, step in 
enumerate(self.steps)])

print ftp
It is working

In [5]: F =  Foo()

In [6]: F.show()
1- one
2- two
3- fmit

Why if I define the data in the same way  I have this error?

 in ()
> 1 rna.show()

 in show(self)
261 #@property
262 def show(self):
--> 263 ftp="\n".join([str(idx + 1) + "- " + step.__name__  for 
idx, step in enumerate(self.steps)])
264 
265 print ftp

AttributeError: 'str' object has no attribute '__name__'
Here you find all the other code the principal are the 
same:http://pastebin.com/nYGEiXY4
rna = Rnaseq()
rna.show()
thanks so much!!

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Class errors

2015-01-22 Thread jarod...@libero.it
Dear All,

I created a class that invoke  from another file another class
 I get an error that I do not understand: gobal name Job is not defined
However If I see the class imported I found the class Job.
Any suggestion or example on class invoke another class

#job,py
class Jobs:
.

#trial.py

from core.job import *
class Second:
def __initi__:
tp = open("/tmp/file.txt")

def gus(self):
tr = Job()

thanks so much!1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning class code and function (Alan Gauld)

2015-01-21 Thread jarod...@libero.it
>I'd also question why you seem to have a function that has the class
>name in its name? Should that function not be a method of the class?
>Or is it part of some third party library perhaps?

Thanks for the clarification!! Could you please make an example of this two 
condition I still try to devolepe my skill on python study some good code. What 
is the best practice? 


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Learning class code and function

2015-01-20 Thread jarod...@libero.it
Dear all, I continue to try to understand some code:
class Tutto():

def __init__(self):
print "Ok"
   #@property
def readsets(self,nome):
self.nome = nome
self._readsets = parse_tutto_readset_file(self.nome)
return self._readsets

Why If uncomment the decorator the code not work:

p = Tutto()

p.readsets("/home/mauro/Desktop/readset.csv")

TypeError: readsets() takes exactly 2 arguments (1 given)

thanks so muc? Could you suggest me some readings for better understand class 
structure?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to use a function

2015-01-19 Thread jarod...@libero.it
Dear All,
I would like to understand how work this funcion:

def parse_illumina_readset_file(illumina_readset_file):
readsets = []
samples = []

log.info("Parse readset " + illumina_readset_file + " ...")
readset_csv = csv.DictReader(open(illumina_readset_file, 'rb'), 
delimiter='\t')
for line in readset_csv:
sample_name = line['Sample']
sample_names = [sample.name for sample in samples]
if sample_name in sample_names:
# Sample already exists
sample = samples[sample_names.index(sample_name)]
else:
# Create new sample
sample = Sample(sample_name)
samples.append(sample)

# Create readset and add it to sample
readset = IlluminaReadset(line['Readset'], line['RunType'])

# Readset file paths are either absolute or relative to the readset file
# Convert them to absolute paths
for format in ("BAM", "FASTQ1", "FASTQ2"):
if line.get(format, None):
line[format] = os.path.expandvars(line[format])
if not os.path.isabs(line[format]):
line[format] = 
os.path.dirname(os.path.abspath(os.path.expandvars(illumina_readset_file))) + 
os.sep + line[format]
line[format] = os.path.normpath(line[format])

readset._bam = line.get('BAM', None)
readset.fastq1 = line.get('FASTQ1', None)
readset.fastq2 = line.get('FASTQ2', None)
readset._library = line.get('Library', None)
readset._run = line.get('Run', None)
readset._lane = line.get('Lane', None)
readset._adaptor1 = line.get('Adaptor1', None)
readset._adaptor2 = line.get('Adaptor2', None)
readset._quality_offset = int(line['QualityOffset']) if 
line.get('QualityOffset', None) else None
readset._beds = line['BED'].split(";") if line.get('BED', None) else []

readsets.append(readset)
sample.add_readset(readset)

log.info(str(len(readsets)) + " readset" + ("s" if len(readsets) > 1 else 
"") + " parsed")
log.info(str(len(samples)) + " sample" + ("s" if len(samples) > 1 else "") 
+ " parsed\n")
return readsets


parser_illumina_readset_file("~/Desktop/file.csv")

dir()

I can't found the readsets list. Someone could please help me? 
thanks so much!




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parse files and create sqlite3 db (Alan Gauld)

2014-12-03 Thread jarod...@libero.it
thanks so much,here you have the error:
---
NameError Traceback (most recent call last)
 in ()
 43 status = line[-4:] # 
and overall status pass/warn/fail
 44 sql = "insert into 
fastqc_summary(fileid,module,status,total,duplicate) values(?,?,?,?,?);"
---> 45 data = (fileid,module,
status,total,dup)
 46 cursor.execute(sql,
data)
 47 elif (line[:2] != ">>" and line
[:2] != "##"): # grab details under each module

NameError: name 'total' is not defined
The problem It is I need to write only if exist that names and values.
So from the original file each time I have this rows:
##FastQC0.10.1
>>Basic Statistics  pass
#MeasureValue   
FilenameR05_CTTGTA_L004_R1_001.fastq.gz 
File type   Conventional base calls 
EncodingSanger / Illumina 1.9   
Total Sequences 27868496
Filtered Sequences  0   
Sequence length 50  
%GC 50  
>>END_MODULE
So they need to be defined. So know I need to do: if  Total and if Filename 
and Total then do the script?



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Parse files and create sqlite3 db

2014-12-03 Thread jarod...@libero.it
Dear all
I aattach the file I want to parse and I wanto to create a sqlite database.
The problem is I'm not able to create in the right way because there is some 
logic problems on my script. I have  this code:


import sqlite
import sqlite3
import os

# Creates or opens a file called mydb with a SQLite3 DB
db = sqlite3.connect('Fastqcd_completo.db')
cursor = db.cursor()
create_table_sql = """
create table fastqc_summary (
fileid varchar,
module varchar,
status varchar,
total int,
duplicate varchar
);"""
cursor.execute(create_table_sql)
create_table_sql2="""
create table fastqc_details (
id serial primary key,
fileid varchar,
module varchar,
col1 varchar,
ocols varchar
);
"""
cursor.execute(create_table_sql2)
db.commit()

for root, dirs, files in 
os.walk("/home/mauro/Desktop/LAVORO_CRO/2014/Statitica_RNAseqalign/FASTQC_completo/fastqcdecembre/"):
 # walk a r
for name in files:
if (name == "fastqc_data.txt"):
fileid = name # use string slicing here if you only want part of the
 
with open(os.path.join(root,name),"r") as p: # automatically close 
the file when done
for i in p:
line =i.strip()

if "Filename" in line:
fileid = line.split()[1]
if "Total Sequence" in line:
total = line.split()[2]

if "Total Duplicate" in line:
dup = line.split()[3]

if (line[:2] == ">>" and line[:12] != ">>END_MODULE"):
module = line[2:-5] # grab module name
status = line[-4:] # and overall status pass/warn/fail
sql = "insert into 
fastqc_summary(fileid,module,status,total,duplicate) values(?,?,?,?,?);"
data = (fileid,module,status,total,dup)
cursor.execute(sql,data)
elif (line[:2] != ">>" and line[:2] != "##"): # grab 
details under each module
cols = line.split("\t")
col1 = cols[0]
ocols = "|".join(cols[1:])
sql = "insert into 
fastqc_details(fileid,module,col1,ocols) values(?,?,?,?);"
data = (fileid,module,col1,ocols)
cursor.execute(sql,data)
db.commit()


So the problem is how to excatct only some parts of the files. In red are the 
point of the problems. The say the Filename are not defined On the file atached 
I want to take this part and use for create the database:
##FastQC0.10.1
>>Basic Statisticspass
#MeasureValue
FilenameR05_CTTGTA_L004_R1_001.fastq.gz
File typeConventional base calls
EncodingSanger / Illumina 1.9
Total Sequences27868496
Filtered Sequences0
Sequence length50
%GC50
>>END_MODULE
How can I resolve this problem? I need to use the number of rows?
bw,



##FastQC0.10.1
>>Basic Statistics  pass
#MeasureValue   
FilenameR05_CTTGTA_L004_R1_001.fastq.gz 
File type   Conventional base calls 
EncodingSanger / Illumina 1.9   
Total Sequences 27868496
Filtered Sequences  0   
Sequence length 50  
%GC 50  
>>END_MODULE
>>Per base sequence quality pass
#Base   MeanMedian  Lower Quartile  Upper Quartile  10th Percentile 90th 
Percentile
1   32.90529076273079   34.031.034.031.034.0
2   33.100253167591106  34.033.034.031.034.0
3   33.219579520904176  34.034.034.031.034.0
4   36.53049856009452   37.037.037.035.037.0
5   36.441143289540996  37.037.037.035.037.0
6   36.400846174117184  37.037.037.035.037.0
7   36.38746253116781   37.037.037.035.037.0
8   36.36443940139432   37.037.037.035.037.0
9   38.22529985112939   39.039.039.037.039.0
10  38.215059327205886  39.039.039.037.039.0
11  38.252484848841505  39.039.039.037.039.0
12  38.22672156401982   39.039.039.037.039.0
13  38.164828234720666  39.039.039.037.039.0
14  39.76166327741547   41.040.041.038.041.0
15  39.765876098947 41.040.041.038.041.0
16  39.74199730764086   41.040.041.037.041.0
17  39.07676352538006   41.040.041.036.041.0
18  39.42998348385934   41.039.041.036.041.0
19  39.57992178695255   41.040.041.037.041.0
20  39.438335638923604  41.040.041.037.041.0
21  39.54068827395637   41.040.041.037.041.0
22  39.464387565084245  41.040

Re: [Tutor] Subprocess how to use?

2014-11-06 Thread jarod...@libero.it
Dear All thanks  so much for the suggestion !!!

One thing is not clear to me: How can write more safe string to send on 
subprocess.Popen() without %s? What is the best way to do this?

thanks so much!

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Subprocess how to use?

2014-11-05 Thread jarod...@libero.it
Dear All,


I need to use external program from my scirpt.
code = "intersectBed -a %s -b /database/Refseq_Gene2.bed  -wa -wb|cut -f 
4,8|uniq > tmp.tmp1"%("gene5.tmp.bed")
code2 = "intersectBed -a %s -b /database/Refseq_Gene2.bed -wa -wb|cut -f 
4,8|uniq > tmp.tmp2"%("gene3.tmp.bed")
proc = []
p = subprocess.Popen(code,shell=True)
proc.append(p)
time.sleep(1) # seconds
p = subprocess.Popen(code2,shell=True)
proc.append(p)
time.sleep(1)
print 
>>sys.stderr,'-'
print >>sys.stderr,"Waiting for Star Fusion Annotate to finish running..."
for p in proc:
p.communicate()
print 
>>sys.stderr,'-'


What append I don't habve any error however the file are truncated.
So I try to use subprocess.call 

 p = subprocess.call(shlex.split(code),stdout = subprocess.PIPE, stderr = 
subprocess.STDOUT, shell = False)
 but with p.comunicate I have this error:

 ('\n* ERROR: Unrecognized parameter: -wb|cut *\n* ERROR: 
Unrecognized parameter: > *\n* ERROR: Unrecognized parameter: tmp.tmp1 
*\n\nTool:bedtools intersect (aka intersectBed)\nVersion: 
v2.21.0-5-g479a2fc\nSummary: Report overlaps between two feature 
files.\n\nUsage:   bedtools intersect [OPTIONS] -a  -b 
\n\n\t\tNote: -b may be followed with multiple databases and/or 
\n\t\twildcard (*) character(s). \nOptions: \n\t-abam\tThe A input file is in 
BAM format.  Output will be BAM as well.\n\n\t-ubam\tWrite uncompressed BAM 
output. Default writes compressed BAM.\n\n\t-bed\tWhen using BAM input (-abam), 
write output as BED. The default\n\t\tis to write output in BAM when using 
-abam.\n\n\t-wa\tWrite the original entry in A for each 
overlap.\n\n\t-wb\tWrite the original entry in B for each overlap.\n\t\t- 
Useful for knowing _what_ A overlaps. Restricted by -f and 
-r.\n\n\t-loj\tPerform a "left outer join". That is, for each feature in 
A\n\t\treport each overlap with B.  If no overlaps are found, \n\t\treport a 
NULL feature for B.\n\n\t-wo\tWrite the original A and B entries plus the 
number of base\n\t\tpairs of overlap between the two features.\n\t\t- Overlaps 
restricted by -f and -r.\n\t\t  Only A features with overlap are 
reported.\n\n\t-wao\tWrite the original A and B entries plus the number of 
base\n\t\tpairs of overlap between the two features.\n\t\t- Overlapping 
features restricted by -f and -r.\n\t\t  However, A features w/o overlap are 
also reported\n\t\t  with a NULL B feature and overlap = 0.\n\n\t-u\tWrite the 
original A entry _once_ if _any_ overlaps found in B.\n\t\t- In other words, 
just report the fact >=1 hit was found.\n\t\t- Overlaps restricted by -f and 
-r.\n\n\t-c\tFor each entry in A, report the number of overlaps with B.\n\t\t- 
Reports 0 for A entries that have no overlap with B.\n\t\t- Overlaps restricted 
by -f and -r.\n\n\t-v\tOnly report those entries in A that have _no overlaps_ 
with B.\n\t\t- Similar to "grep -v" (an homage).\n\n\t-f\tMinimum overlap 
required as a fraction of A.\n\t\t- Default is 1E-9 (i.e., 1bp).\n\t\t- FLOAT 
(e.g. 0.50)\n\n\t-r\tRequire that the fraction overlap be reciprocal for A and 
B.\n\t\t- In other words, if -f is 0.90 and -r is used, this requires\n\t\t  
that B overlap 90% of A and A _also_ overlaps 90% of B.\n\n\t-s\tRequire same 
strandedness.  That is, only report hits in B\n\t\tthat overlap A on the _same_ 
strand.\n\t\t- By default, overlaps are reported without respect to 
strand.\n\n\t-S\tRequire different strandedness.  That is, only report hits in 
B\n\t\tthat overlap A on the _opposite_ strand.\n\t\t- By default, overlaps are 
reported without respect to strand.\n\n\t-split\tTreat "split" BAM or BED12 
entries as distinct BED intervals.\n\n\t-sorted\tUse the "chromsweep" algorithm 
for sorted (-k1,1 -k2,2n) input.\n\n\t-g\tProvide a genome file to enforce 
consistent chromosome sort order\n\t\tacross input files. Only applies when 
used with -sorted option.\n\n\t-header\tPrint the header from the A file prior 
to results.\n\n\t-nobuf\tDisable buffered output. Using this option will cause 
each line\n\t\tof output to be printed as it is generated, rather than 
saved\n\t\tin a buffer. This will make printing large output files 
\n\t\tnoticeably slower, but can be useful in conjunction with\n\t\tother 
software tools and scripts that need to process one\n\t\tline of bedtools 
output at a time.\n\n\t-names\tWhen using multiple databases, provide an alias 
for each that\n\t\twill appear instead of a fileId when also printing the DB 
record.\n\n\t-filenames\tWhen using multiple databases, show each complete 
filename\n\t\t\tinstead of a fileId when also printing the DB 
record.\n\n\t-sortout\tWhen using multiple databases, sort the output DB 
hits\n\t\t\tfor each record.\n\n\t-iobuf\tFollow with desired integer size of 
read buffer.\n\t\tOptional

[Tutor] R: re question on array

2014-10-30 Thread jarod...@libero.it
Dear All,
Sorry for my bad presentation of my problem!!
I have this tipe of input:
A file with a long liste of gene ad the occurence for sample:

geneSamples
FUS SampleA
TP53SampleA
ATF4SampleB
ATF3SampleC
ATF4SampleD
FUS SampleE
RORASampleE
RORASampleC

WHat I want to obtain is amtrix where I have the occurence for sample.
SampleA SampleB SampleC SampleD SampleE
FUS 1   0   0   0   1
TP531   0   0   0   0
ATF40   1   1   0
ATF30   0   1   0   0
RORA0   0   1   0   

In that way I count count the occurence in fast way!

At the moment I only able to do the list of the rownames and the sample names. 
Unfortunately I don't know how to create this matrix.
Cold you help me ?
Thanks for the patience and the help




>Messaggio originale
>Da: tutor-requ...@python.org
>Data: 30/10/2014 6.41
>A: 
>Ogg: Tutor Digest, Vol 128, Issue 74
>
>Send Tutor mailing list submissions to
>   tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>   https://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
>You can reach the person managing the list at
>   tutor-ow...@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
>   1. Re: Would somebody kindly... (Steven D'Aprano)
>   2. Re: Would somebody kindly... (Dave Angel)
>   3. question  on array Operation (jarod...@libero.it)
>   4. Re: question  on array Operation (Peter Otten)
>   5. Re: question  on array Operation (Alan Gauld)
>   6. Re: question  on array Operation (Steven D'Aprano)
>   7. Re: Would somebody kindly... (Clayton Kirkwood)
>
>
>--
>
>Message: 1
>Date: Wed, 29 Oct 2014 23:04:18 +1100
>From: Steven D'Aprano 
>To: tutor@python.org
>Subject: Re: [Tutor] Would somebody kindly...
>Message-ID: <20141029120417.ga26...@ando.pearwood.info>
>Content-Type: text/plain; charset=us-ascii
>
>On Tue, Oct 28, 2014 at 04:13:19PM -0700, Clayton Kirkwood wrote:
>> Explain this double speak(>:
>> 
>> [pair for pair in values if key == pair[0]]
>
>Translated to a regular for-loop:
>
>result = []
>for pair in values:
>if key == pair[0]:
>result.append(pair)
>
>
>It iterates over the sequence `values`, extracting something called 
>`pair`. If the first item of `pair` == key, then the pair is placed in 
>the resulting list.
>
>py> values = [ ('a', 1), ('b', 2), ('a', 5), ('c', 7)]
>py> key = 'a'
>py> [pair for pair in values if key == pair[0]]
>[('a', 1), ('a', 5)]
>
>
>-- 
>Steven
>
>
>--
>
>Message: 2
>Date: Wed, 29 Oct 2014 08:29:56 -0400 (EDT)
>From: Dave Angel 
>To: tutor@python.org
>Subject: Re: [Tutor] Would somebody kindly...
>Message-ID: 
>Content-Type: text/plain; charset=UTF-8
>
>"Clayton Kirkwood"  Wrote in message:
>> 
>> 
>> !-Original Message-
>> !From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On
>> !Behalf Of Dave Angel
>> !Sent: Tuesday, October 28, 2014 6:34 PM
>> !To: tutor@python.org
>> !Subject: Re: [Tutor] Would somebody kindly...
>> !
>> !
>> !>
>> ! Explain this double speak(>:
>> !>  [pair for pair in values if key == pair[0]]
>> !
>> !>  I understand the ?for pair in values?. I assume the first  ?pair?
>> !> creates the namespace
>> !
>> !The namespace question depends on the version of Python. Python  2.x
>> !does not do any scoping.
>> !
>> !But in version 3.x, the variable pair will go away.
>> !
>> !So please tell us the version you're asking about.
>> 
>> I am using 3.4.1.
>> 
>
>Have you somehow configured your email program to use exclamation
> points for quoting instead of the standard greater-than symbol?
> "!" instead of ">" ? If so, do you mind changing it
> back?
>
>In 3.4.1, let's consider the following code.
>
>thingie = 2
>mylist = [(2,55), "charlie", [2, "item2", 12]]
>x = [78 for item in mylist if item[0] == thingie]
>
>What will happen in the list comprehension, and what will be the
> final value of x ?
>
>First an anonymous list object will be created.  This eventually
> will be bou

[Tutor] question on array Operation

2014-10-29 Thread jarod...@libero.it
Dear All,

I have a long matrix where I have the samples (1to n) and then I have (1to j 
)elements.
I would like to count how many times  each j element are present on each 
samples.

So the question is which is the best algoritm for obtain the results. The 
result I want is a table like that.



A,B,D,E,F
AA,1,0,1,0
BB1,1,1,1
CC0,0,1,0
DD01,0,1,0


Do you have any suggestion on how to do this?  only using a loop like:

A is a list with some names A=[AA,BB,ZZ,TT,NN]

if AA in A:
print 1
else :
print 0

thanks in advance for any help
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] python draw christman tree using loops

2014-10-19 Thread jarod...@libero.it

Dear All,
or improve my understanding o python I would like to learn how to draw simple
figures using loops.
I start from this code in java:
import java.util.Scanner;

public class Eserc2_8 {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
// Altezza del triangolo
int altezza = s.nextInt();
   
for (int riga = 1; riga <= altezza; riga++) {
int i = 0;
while (ihttps://mail.python.org/mailman/listinfo/tutor


[Tutor] Regular expression

2014-09-23 Thread jarod...@libero.it
Hi there!!

I need to read this file:

pippo.count :
 10566 ZXDC
   2900 ZYG11A
   7909 ZYG11B
   3584 ZYX
   9614 ZZEF1
  17704 ZZZ3


This file present a use space on the begin then they have a number and the a 
word.
 p =re.compile("\s+\d+")
with open("pippo.count") as p:
for i in p:
lines =i.rstrip("\n").split("\t")
print t.findall(str(lines))
out:

['994']
['  10428']
['   1810']
['   4880']
['   8905']



How can extract only the number and the work in array? Thanks for any help
jarod
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Re subprocess

2014-09-11 Thread jarod...@libero.it
Thanks for the suggestion and corrections.
I don't put the else staement onf if log_file but now I realize my mistake
I have 3 comand to do:
step_1_out =["STAR --genomeDir /home/sbsuser/databases/Starhg19/GenomeDir/ --
runMode alignReads --readFilesIn %s   %s  --runThreadN 12  --readFilesCommand 
zcat "%(dx[i],sn[i])]
step_2_out = ["STAR --runMode genomeGenerate --genomeDir  %s  --
genomeFastaFiles ~/databases/bowtie2Database/hg19.fa --sjdbFileChrStartEnd  %
sSJ.out.tab --sjdbOverhang 49   --runThreadN 12" %(tx[i],tx[i])]
step_3_out =["STAR --genomeDir %s --runMode alignReads --readFilesIn %s   %s  
--runThreadN 12  --readFilesCommand zcat "%(Pos2,dx,sn)]

So I need to run one step a time. cmd is the comand (step_1_out) e pi is the  
directory of the files.


def run(cmd,pi):
import subprocess
import time
import logging

logging.basicConfig(level=logging.DEBUG,format="%(asctime)s - %(name)s 
- %
(levelname)s - %(message)s")

#logging.debug(" Running pipelines: %s" % (cmd))
# setup logging

tou = "log.txt"
logfh = open(tou, "r+")


p1 = 
subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=logfh,
cwd=pi)

#logging.info(" Running pipelines: %s" % (cmd))
while True:
if p1.poll() is None:
time.sleep(120)
pass
if p1.poll()==0:
print 'Finish this step.'
logging.info("###: %s %s" % 
(cmd,time.ctime()))
break
if p1.poll() is not None and p1.poll() != 0:
raise Exception('Not working please check the error')
# end logging

logfh.close()

return  0

I don't understand where is the  error in the code above. 

If I change the code in this way seems work
def run(cmd,pi):
import subprocess
import time
import logging

logging.basicConfig(level=logging.DEBUG,format="%(asctime)s - 
%(name)s - %
(levelname)s - %(messag
e)s")

#logging.debug(" Running pipelines: %s" % (cmd))
# setup logging
log_file = "None"
tou = "og.txt"
logfh = open(tou, "r+")



p1 = 
subprocess.Popen(cmd,shell=True,stdout=logfh,stderr=logfh,cwd=pi)
p1.wait()


#logging.info(" Running pipelines: %s" % (cmd))


return  0

Someone can explain to me when we neet to choose wait or pool?
Thanks for the help
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Re subprocess

2014-09-10 Thread jarod...@libero.it
If I follow the exmple I have this type of error:
File "./RNA_prova.py", line 73, in run
for line in p1.stdout():
TypeError: 'NoneType' object is not callable


This is the class I use:
def run(cmd,pi):
import subprocess
import time
import logging

logging.basicConfig(level=logging.DEBUG,format="%(asctime)s - 
%(name)s - %
(levelname)s - %(message)s")

#logging.debug(" Running pipelines: %s" % (cmd))
# setup logging
log_file = "None"
tou = "file"+"_.log.txt"
if log_file is not None:
logfh = open(tou, "w")

else:
logfh = None
print 
""


p1 = 
subprocess.Popen(cmd,shell=True,stdout=logfh,stderr=logfh,cwd=pi)

#logging.info(" Running pipelines: %s" % (cmd))

for line in p1.stdout():
process(line)

p1.stdout.close()
if p.wait() != 0:
raise Exception 
# end logging
if logfh is not None:
logfh.close()

return  0

How can be sure the process start finish before to proced with the other 
comands?
thanks in advance for any help!



>Messaggio originale
>Da: tutor-requ...@python.org
>Data: 09/09/2014 17.05
>A: 
>Ogg: Tutor Digest, Vol 127, Issue 27
>
>Send Tutor mailing list submissions to
>   tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>   https://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
>You can reach the person managing the list at
>   tutor-ow...@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
>   1. Re: Good approach regarding classes attributes (Joel Goldstick)
>   2. Re: Understand subprocess poll (Peter Otten)
>   3. Re: Understand subprocess poll (jarod...@libero.it)
>   4. Re: Good approach regarding classes attributes (Sydney Shall)
>
>
>--
>
>Message: 1
>Date: Tue, 9 Sep 2014 10:05:09 -0400
>From: Joel Goldstick 
>Cc: "tutor@python.org" 
>Subject: Re: [Tutor] Good approach regarding classes attributes
>Message-ID:
>   
>Content-Type: text/plain; charset=UTF-8
>
>On Tue, Sep 9, 2014 at 10:02 AM, Sydney Shall  
wrote:
>> On 09/09/2014 15:44, Peter Otten wrote:
>>
>> Sydney Shall wrote:
>>
>> On 08/09/2014 18:39, Alan Gauld wrote:
>>
>> On 08/09/14 15:17, Juan Christian wrote:
>>
>> One tiny tweak...
>>
>> class User():
>>
>> You don't need the parens after User. You don;t have any superclasses
>> so they do nothing. Python convention for an empty parent list is just
>> to leave the parens off:
>>
>> class User:
>>
>> A simple question from a newbie, in response to this surprise.
>> Is it not helpful to always put (object) as the parent, if the class is
>> not itself a sub-class?
>>
>> The answer differs between Python 2 and 3. In Python 3
>>
>> class C: # preferred in Python 3
>> pass
>>
>> and
>>
>> class C(object):
>> pass
>>
>> are the same, so there is no point adding the explicit object inheritance.
>>
>> In Python 2 however
>>
>> class C:
>> pass
>>
>> will create a "classic class" whereas
>>
>> class C(object): # preferred in Python 2
>> pass
>>
>> is a "newstyle class". The most notable difference between these is that
>> properties work correctly only with newstyle classes. Therefore making all
>> your classes "newstyle" is a good idea.
>>
>> And while I am writing, what does OP stand for in this list?
>>
>> Original Poster, as Leam says.
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>> Thanks Peter, most helpful.
>> I was taught with Python 2.7, so  now I understand the advice.
>>
>>
>> --
>> Sydney Shall
>>
>> ___

Re: [Tutor] Understand subprocess poll

2014-09-09 Thread jarod...@libero.it
Thanks for yhe help!
The comand run is this 

the class created are this:
def run(cmd,pi):
import subprocess
import time
import logging

logging.basicConfig(level=logging.DEBUG,format="%(asctime)s - 
%(name)s - %
(levelname)s - %(messag
e)s")

#logging.debug(" Running pipelines: %s" % (cmd))
# setup logging
log_file = "None"
tou = "file"+"_.log.txt"
if log_file is not None:
logfh = open(tou, "w")

else:
logfh = None
print 
""


p1 = 
subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=logfh,
cwd=pi)

#logging.info(" Running pipelines: %s" % (cmd))
while True:
if p1.poll() is None:
time.sleep(3)
pass
if p1.poll()==0:
print 'Finish this step.'
logging.info("###: %s %s" % 
(cmd,time.ctime()))
break
if p1.poll() is not None and p1.poll() != 0:
raise Exception('Not working please check the 
error')
# end logging
if logfh is not None:
logfh.close()

return  0


step_2_out =["~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --genomeDir 
/home/sbsuser/d
atabases/Starhg19/GenomeDir/ --runMode alignReads --readFilesIn %s   %s  --
runThreadN 12  --readFilesCommand zcat
 "%(dx,sn)]

The problems  is the script end the process but not  allign all the data. If I 
use the comand line the same code the process work.
How can resolve this issue?




>Messaggio originale
>Da: tutor-requ...@python.org
>Data: 09/09/2014 16.02
>A: 
>Ogg: Tutor Digest, Vol 127, Issue 26
>
>Send Tutor mailing list submissions to
>   tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>   https://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
>You can reach the person managing the list at
>   tutor-ow...@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
>   1. Re: Good approach regarding classes attributes (Sydney Shall)
>   2. Re: Good approach regarding classes attributes (leam hall)
>   3. Re: Understand subprocess poll (Wolfgang Maier)
>   4. Re: Good approach regarding classes attributes (Peter Otten)
>   5. Re: Good approach regarding classes attributes (Juan Christian)
>   6. Re: Good approach regarding classes attributes (Sydney Shall)
>
>
>--
>
>Message: 1
>Date: Tue, 09 Sep 2014 15:09:32 +0200
>From: Sydney Shall 
>To: tutor@python.org
>Subject: Re: [Tutor] Good approach regarding classes attributes
>Message-ID: <540efc0c.3000...@virginmedia.com>
>Content-Type: text/plain; charset="windows-1252"; Format="flowed"
>
>On 08/09/2014 18:39, Alan Gauld wrote:
>> On 08/09/14 15:17, Juan Christian wrote:
>>
>> One tiny tweak...
>>
>>> class User():
>>
>> You don't need the parens after User. You don;t have any superclasses 
>> so they do nothing. Python convention for an empty parent list is just 
>> to leave the parens off:
>>
>> class User:
>>
>A simple question from a newbie, in response to this surprise.
>Is it not helpful to always put (object) as the parent, if the class is 
>not itself a sub-class?
>And while I am writing, what does OP stand for in this list?
>
>
>-- 
>Sydney Shall
>-- next part --
>An HTML attachment was scrubbed...
>URL: <http://mail.python.
org/pipermail/tutor/attachments/20140909/ebcdb792/attachment-0001.html>
>
>--
>
>Message: 2
>Date: Tue, 9 Sep 2014 09:14:39 -0400
>From: leam hall 
>To: tutor 
>Subject: Re: [Tutor] Good approach regarding classes attributes
>Message-ID:
>   
>Content-Type: text/plain; charset=UTF-8
>
>On Tue, Sep 9, 2014 at 9:09 AM, Sydney Shall  wrote:
>
>> And while I am writing, what does OP stand for in this list?
>
>"Original Poster". So I understand. Won't answer the Pytho

[Tutor] Understand subprocess poll

2014-09-09 Thread jarod...@libero.it
Dear all!!
I want to use subprocess for run some programs But I need to be sure the
program end before continue with the other:

subprocess.call("ls")
cmd1 = i
p1 = subprocess.Popen(cmd1,shell=True,stdout=subprocess.PIPE)

while True:
if p1.poll() is None:
time.sleep(3)

pass
if p1.poll()==0:
print '#'
break
if p1.poll() is not None and p1.poll() != 0:
raise Exception('Error building Alignment using star with hg19
database')



This are not working. How can I do?
thanks in advance for the precious help
bw,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] how to be sure the process are ended

2014-09-09 Thread jarod...@libero.it


>Messaggio originale
>Da: jarod...@libero.it
>Data: 08/09/2014 18.15
>A: 
>Ogg: how to be sure the process are ended
>
>Dear all!!
>I want to use subprocess for run some programs But I need to be sure the 
>program end before continue with the other:
>
>subprocess.call("ls")
>   cmd1 = i
>   p1 = 
> subprocess.Popen(cmd1,shell=True,stdout=subprocess.PIPE)
>   
>   while True:
>   if p1.poll() is 
> None:
>   
> time.sleep(3)
>   
>   pass
>   if p1.poll()==0:
>   print 
> '#'
>   break
>   if p1.poll() is 
> not None and p1.poll() != 0:
>   raise 
> Exception('Error building Alignment using star with hg19 
>database')
>
>
>
>This are not working. How can I do?
>thanks in advance for the precious help
>bw,
>


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] python pipeline

2014-09-01 Thread jarod...@libero.it
Dear all,
I'll try to write a pipeline starting from a csv file where I write the name 
and the path of my files.
example.csv
Name,FASTQ1,FASTQ2,DIRECTORY
sampleA,A_R1_.fastq.gz,A_R2_.fastq.gz,108,~/FASTQ/
sampleB,B_R1_.fastq.gz,B_R2_.fastq.gz,112,~/FASTQ/



On that list I need to send each time 3 different script whic are depend one 
to the other. So I need to run1 and only whe it finisched start the second and 
then the 3.
One of the problems teach script write the output only in the same directory 
where I launch the program so I need to create. I set the output directory and 
the I want to obtain  this folder view
.
├── sampleA
│   ├── ref.txt
│   └── second
└── sampleB
├── ref.txt
└── second
I have problems on how to move in different folder  and how can use subprocess 
for execute all.
Any idea in how can I do this?

def Staralign(file,pos):
import subprocess

global Path 
global Read1
global Read2
global Nome
global label
Read1 = []
Read2 = []
Nome = []
Path = []
label = []
with open(file) as p:
for i in p:
lines = i.rstrip("\n").split(",")
if lines[0] != "Name":
Path.append(lines[10])
Nome.append(lines[0])
Read1.append(lines[7])
Read2.append(lines[8])
out = open("toRun.sh","w")
out.write("#!/bin/bash\n")
global pipe
pipe =[]
dizionario = {}
for i in range(len(Nome)):
dx =str("".join(Path[i])+ "/"+ "".join(Read1[i]))
sn =str("".join(Path[i])+"/"+"".join(Read2[i]))
if not os.path.exists(pos+"/"+i):
os.makedirs(pos+"/"+i)
print >>out, "cd " + pos +"\n"

print  
>>out,"~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --genomeDir 
/home/sbsuser/databases/Starhg19/GenomeDir/ --runMode alignReads --readFilesIn 
"+ dx  +" "+ ""+ sn +"   --runThreadN 12  --readFilesCommand zcat " +"\n"
step_1_out 
=["~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --genomeDir 
/home/sbsuser/databases/Starhg19/GenomeDir/ --runMode alignReads --readFilesIn %
s   %s  --runThreadN 12  --readFilesCommand zcat "%(dx,dn)]
print  >>out,"cd " +"  $PWD"+"/"+ "hg19_second/" +"\n"

print  
>>out,"~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --runMode 
genomeGenerate --genomeDir"+"  $PWD"+"/"+ "hg19_second/  --genomeFastaFiles 
~/databases/bowtie2Database/hg19.fa --sjdbFileChrStartEnd " +"$PWD"+"/"+ "SJ.
out.tab" +" --sjdbOverhang 49   --runThreadN 12" +"\n"

pipe.append("~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --genomeDir 
/home/sbsuser/databases/Starhg19/GenomeDir/ --runMode alignReads --readFilesIn 
"+ dx  +" "+  ""+ sn +"   --runThreadN 12  --readFilesCommand zcat ")
print  >>out,"cd  .." + "\n"
print  
>>out,"~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --genomeDir"+ 
"  $PWD"+"/"+ "hg19_second/GenomeDir/  --runMode alignReads --readFilesIn "+ 
dx  +" "+ ""+ sn +"   --runThreadN 12  --readFilesCommand zcat " +"\n"
dizionario.setdefault()
#   return Nome,Path,Read1,Read1

This isthe function I wrote but with this way I'm only able to write a bash 
script..







___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] R: Tutor Digest, Vol 125, Issue 71

2014-07-23 Thread jarod...@libero.it
Thanks so much!!

>Messaggio originale
>Da: tutor-requ...@python.org
>Data: 23/07/2014 8.10
>A: 
>Ogg: Tutor Digest, Vol 125, Issue 71
>
>Send Tutor mailing list submissions to
>   tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>   https://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
>You can reach the person managing the list at
>   tutor-ow...@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
>   1. How to show dictionary item non present on file
>  (jarod...@libero.it)
>   2. Re: How to show dictionary item non present on file
>  (Steven D'Aprano)
>   3. Re: How to show dictionary item non present on file (Peter Otten)
>   4. Getting a directory listing with Python to MySQL (Eric Dannewitz)
>   5. Re: Getting a directory listing with Python to MySQL (Danny Yoo)
>   6. Re: Getting a directory listing with Python to MySQL
>  (Steven D'Aprano)
>   7. Re: Getting a directory listing with Python to MySQL
>  (Eric Dannewitz)
>
>
>------
>
>Message: 1
>Date: Tue, 22 Jul 2014 13:10:18 +0200 (CEST)
>From: "jarod...@libero.it" 
>To: tutor@python.org
>Subject: [Tutor] How to show dictionary item non present on file
>Message-ID:
>   <253805423.250161406027418296.JavaMail.defaultUser@defaultHost>
>Content-Type: text/plain;charset="UTF-8"
>
>Hin there!!!
>
>I have a niave question on dictionary analysis: 
>If you have a dictionary like this:
>diz
>Out[8]: {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}
>
>and you have a list and you want to know which  keys are not present on my 
>dictionary the code are simple.
>for i in diz.keys():
>   ...: if i in mitico:
>   ...: print "NO"
>   ...: else:
>   ...: print i
>   ...: 
>NO
>
>But I havethis problem I have a file and I want to know which elements are 
not 
>present on my file from dictionary.
> more data.tmp 
>jack   1
>pippo  1
>luis   1
>frate  1
>livio  1
>frank  1
>
>
>with open("data.tmp") as p:
>for i in p:
>lines= i.strip("\n").split("\t")
>if not diz.has_key(lines[0]):
>   : print i
>   : 
>pippo  1
>
>luis   1
>
>frate  1
>
>livio  1
>
>The output I want is to have :
>ralph and 'elenour.. how can I do this?
>thanks in advance!
>
>
>
>--
>
>Message: 2
>Date: Tue, 22 Jul 2014 21:32:47 +1000
>From: Steven D'Aprano 
>To: tutor@python.org
>Subject: Re: [Tutor] How to show dictionary item non present on file
>Message-ID: <20140722113247.GO9112@ando>
>Content-Type: text/plain; charset=us-ascii
>
>On Tue, Jul 22, 2014 at 01:10:18PM +0200, jarod...@libero.it wrote:
>
>> But I havethis problem I have a file and I want to know which elements are 
not 
>> present on my file from dictionary.
>>  more data.tmp 
>> jack 1
>> pippo1
>> luis 1
>> frate1
>> livio1
>> frank1
>> 
>> 
>> with open("data.tmp") as p:
>> for i in p:
>> lines= i.strip("\n").split("\t")
>> if not diz.has_key(lines[0]):
>>: print i
>>: 
>> pippo1
>> luis 1
>> frate1
>> livio1
>> 
>> The output I want is to have :
>> ralph and 'elenour.. how can I do this?
>
>You are doing the comparison the wrong way: you are saying:
>
>for each line in the file:
>is the line in the dict?
>if no, print the line
>
>
>What you want is:
>
>for each key in the dict:
>is the key in the file?
>if no, print the key
>
>
>It is not easy to try searching the file directly, so we copy the lines 
>from the file into a set:
>
>lines = set()
>with open("data.tmp") as the_file:
>for line in the_file:
>line = line.strip().split("\t")[0]
>lines.add(line)
>
>
>Here is a shorter way to do the same thing:
>
>with open("data.tmp") as the_file:
>lines = set([line.strip().split("\t")[0] for line in the_file])
>
>
>Now you can walk through the dict:
>
>for name in diz:
>  

[Tutor] How to show dictionary item non present on file

2014-07-22 Thread jarod...@libero.it
Hin there!!!

I have a niave question on dictionary analysis: 
If you have a dictionary like this:
diz
Out[8]: {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}

and you have a list and you want to know which  keys are not present on my 
dictionary the code are simple.
for i in diz.keys():
   ...: if i in mitico:
   ...: print "NO"
   ...: else:
   ...: print i
   ...: 
NO

But I havethis problem I have a file and I want to know which elements are not 
present on my file from dictionary.
 more data.tmp 
jack1
pippo   1
luis1
frate   1
livio   1
frank   1


with open("data.tmp") as p:
for i in p:
lines= i.strip("\n").split("\t")
if not diz.has_key(lines[0]):
   : print i
   : 
pippo   1

luis1

frate   1

livio   1

The output I want is to have :
ralph and 'elenour.. how can I do this?
thanks in advance!

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] R: Tutor Digest, Vol 125, Issue 49

2014-07-16 Thread jarod...@libero.it
Hi there!!!
I have a file  with this data
['uc002uvo.3 ', 'uc001mae.1']
['uc010dya.2 ', 'uc001kko.2']
['uc003ejx.2 ', 'uc010yfr.1']
['uc001bhk.2 ', 'uc003eib.2']
['uc001znc.2 ', 'uc001efn.2']
['uc002ycq.2 ', 'uc001vnh.2']
['uc001odf.1 ', 'uc002mwd.2']
['uc010jkn.1 ', 'uc010luk.1']
['uc003uhf.3 ', 'uc010tqd.1']
['uc002rue.3 ', 'uc001tex.2']
['uc011dtt.1 ', 'uc001lkv.1']
['uc003yyt.2 ', 'uc003mkl.2']
['uc003pkv.2 ', 'uc003ytw.2']
['uc010bhz.2 ', 'uc002kbt.1']
['uc001wnj.2 ', 'uc009wtj.1']
['uc011lyh.1 ', 'uc003jvb.2']
['uc002awj.1 ', 'uc009znm.1']
['uc010bft.2 ', 'uc002cxz.1']
['uc011mar.1 ', 'uc001lvb.1']
['uc001oxl.2 ', 'uc002lvx.1']

I want to replace of the things after the dots, so I want to have  a file with 
this output:

['uc002uvo ', 'uc001mae']
['uc010dya ', 'uc001kko']
...

I try to use regular expression but I have  a strange output

with open("non_annotati.csv") as p:
for i in p:
lines= i.rstrip("\n").split("\t")
mit = re.sub(r'(\.\d$)','',lines[0])
mit2 = re.sub(r'(\.\d$)','',lines[1])
print mit,mit2


uc003klv.2  uc010lxj
uc001tzy.2  uc011kzk
uc010qdj.1  uc001iku
uc004coe.2  uc002vmf
uc002dvw.2  uc004bxn
uc001dmp.2  uc001dmo
uc002rqd.2  uc010ynl
uc010cvm.1  uc002qjc
uc003ewy.3  uc003hgx
uc002ejy.2  uc003mvb
uc002fou.1  uc010ilx
uc003vhf.2  uc010qlo
uc003mix.2  uc010tdt
uc002nez.1  uc003wxe
uc011cpu.1  uc002keg
uc001ovu.2  uc011dne
uc010zfg.1  uc001jvq
uc010jlf.2  uc011azi
uc001ors.3  uc001vzx
uc010tyt.1  uc003vih
uc010fde.2  uc002xgq
uc010bit.1  uc003zle
uc010xcb.1  uc010wsg
uc011acg.1  uc009wlp
uc002bnj.2  uc004ckd


Where is the error? what is wrong in my regular expression code? 


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to create a dictionary for ount elements

2014-06-04 Thread jarod...@libero.it
Dear all thanks for your suggestion!!!
Thanks to your suggestion I create this structure:with open("prova.csv") as p:
for i in p:
lines =i.rstrip("\n").split("\t")
   ...: print lines
   ...: 
['programs ', 'sample', 'gene', 'values']
['program1', 'sample1', 'TP53', '2']
['program1', 'sample1', 'TP53', '3']
['program1', 'sample2', 'PRNP', '4']
['program1', 'sample2', 'ATF3', '3']
['program2', 'sample1', 'TP53', '2']
['program2', 'sample1', 'PRNP', '5']
['program2', 'sample2', 'TRIM32', '4']
['program2', 'sample2', 'TLK1', '4']

In [4]: with open("prova.csv") as p:
for i in p:
lines =i.rstrip("\n").split("\t")
dizlines
diz

In [4]: with open("prova.csv") as p:
for i in p:
lines =i.rstrip("\n").split("\t")
line = (lines[0],lines[1])
   ...: diz.setdefault(line,set()).add(lines[2])
   ...: 

In [5]: diz
Out[5]: 
{('program1', 'sample1'): {'TP53'},
 ('program1', 'sample2'): {'ATF3', 'PRNP'},
 ('program2', 'sample1'): {'PRNP', 'TP53'},
 ('program2', 'sample2'): {'TLK1', 'TRIM32'},
 ('programs ', 'sample'): {'gene'}}


So what I want to do is to use intersect between the keys recursively:
s = diz[('program2', 'sample1']
   : 
   : 
KeyboardInterrupt

In [14]: s = diz[('program2', 'sample1')]

In [15]: s
Out[15]: {'PRNP', 'TP53'}

In [16]: a
Out[16]: {'ATF3', 'PRNP'}

In [17]: s.inte
s.intersection s.intersection_update  

In [17]: s.intersection(a)
Out[17]: {'PRNP'}

How can Have a intersect of all my dictionary and from ('program1', 'sample1') 
vs ('program1', 'sample2')...
I want to count  how many genes are common
Thanks in advance  for your help!


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to create a dictionary for ount elements

2014-06-03 Thread jarod...@libero.it
HI there!!!
I have  afile like this:
file.txt
programssample  gene
program1sample1 TP53
program1sample1 TP53
program1sample2 PRNP
program1sample2 ATF3
program2sample1 TP53
program2sample1 PRNP
program2sample2 TRIM32
program2sample2 TLK1
program2sample2 KIT


with open("prova.csv") as p:
for i in p:
   ...: lines = i.rstrip("\n").split("\t")
   ...: print lines 
   ...: 
['programs ', 'sample', 'gene', 'values']
['program1', 'sample1', 'TP53', '2']
['program1', 'sample1', 'TP53', '3']
['program1', 'sample2', 'PRNP', '4']
['program1', 'sample2', 'ATF3', '3']
['program2', 'sample1', 'TP53', '2']
['program2', 'sample1', 'PRNP', '5']
['program2', 'sample2', 'TRIM32', '4']
['program2', 'sample2', 'TLK1', '4']


I want to create a dictionary with set data with the names of the genes:

example:
dic = {}


dic['program1-sample1] = set(TP53)
dic['program1-sample2] = set(TP53,PRNP,ATF3)

So If I have a dictionary like that I can compare two set  I will compare the 
capacity of the programs in function of the gene show.
Thanks in advance for your help!


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How parse files in function of number of lines

2014-05-28 Thread jarod...@libero.it
Dear all!
I have two example files:
tmp.csv:
namevalue   root
mark34  yes

tmp2.csv
namevalue   root


I want to print a different text if I have more than one row and if I have 
only one row. My code is this:
with open("tmp.csv") as p:
header =p.next()
for i in p:
print i
g = ()
if not g:
print  header
mark34  yes

no

I want to obtain only where I have only the header the header string? How can 
I do this?Thnks for your great patience and help!

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] R: Tutor Digest, Vol 123, Issue 65

2014-05-27 Thread jarod...@libero.it
Thanks so much for the help! and suggestions I not use dictionary because I  
have some items are repeated inside the list


>Messaggio originale
>Da: tutor-requ...@python.org
>Data: 27/05/2014 12.00
>A: 
>Ogg: Tutor Digest, Vol 123, Issue 65
>
>Send Tutor mailing list submissions to
>   tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>   https://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
>You can reach the person managing the list at
>   tutor-ow...@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
>   1. Help on  best way to check resence of item inside list
>  (jarod...@libero.it)
>   2. Re: Help on  best way to check resence of item inside list
>  (Mark Lawrence)
>
>
>--
>
>Message: 1
>Date: Tue, 27 May 2014 10:05:30 +0200 (CEST)
>From: "jarod...@libero.it" 
>To: tutor@python.org
>Subject: [Tutor] Help on  best way to check resence of item inside
>   list
>Message-ID: <975274200.13645911401177930495.JavaMail.actor@webmail48>
>Content-Type: text/plain;charset="UTF-8"
>
>Dear All
>
>clubA= ["mary","luke","amyr","marco","franco","lucia", "sally","genevra","
>electra"]
>clubB= ["mary","rebecca","jane","jessica","judit","sharon","lucia", "sally","
>Castiel","Sam"]
>
>I have a list of names that I would to annotate  in function of presence in
>different clubs:
>
>my input files is a long file where I have this :
>
>mary
>luke
>luigi
>jane
>jessica
>rebecca
>luis
>?
>
>with open("file.in") as p:
>mit = []
>for i in p:
>   lines =i.strip("\n").split("\t")
>   if  (lines[0] in clubA:
>  G =lines[-1] +["clubA"]
>   else:
>   G = lines[-1] +["no"]  
>mit.append(G)
>  
>
>for i in mit:
>   if i.strip("\n").split("\t")[0] in clubB:
> G =lines[-1] +["clubB"]
>   else:
>   G = lines[-1] +["no"]  
>  finale.append(G)
>###
>I just wonder if is appropriate to use a loops to check if is present the
>value on a list. Is it the right way? I can use a dictionary because I have
>many repeated names.
>
>In the end I wan to have
>
>
>mary  clubA clubB
>luke clubA
>luigi  no
>Thanks in advance for any help
>
>
>--
>
>Message: 2
>Date: Tue, 27 May 2014 09:48:27 +0100
>From: Mark Lawrence 
>To: tutor@python.org
>Subject: Re: [Tutor] Help on  best way to check resence of item inside
>   list
>Message-ID: 
>Content-Type: text/plain; charset=UTF-8; format=flowed
>
>On 27/05/2014 09:05, jarod...@libero.it wrote:
>> Dear All
>>
>> clubA= ["mary","luke","amyr","marco","franco","lucia", "sally","genevra","
>> electra"]
>> clubB= ["mary","rebecca","jane","jessica","judit","sharon","lucia", 
"sally","
>> Castiel","Sam"]
>>
>> I have a list of names that I would to annotate  in function of presence in
>> different clubs:
>>
>> my input files is a long file where I have this :
>>
>> mary
>> luke
>> luigi
>> jane
>> jessica
>> rebecca
>> luis
>> ?
>>
>> with open("file.in") as p:
>> mit = []
>> for i in p:
>> lines =i.strip("\n").split("\t")
>> if  (lines[0] in clubA:
>>G =lines[-1] +["clubA"]
>> else:
>> G = lines[-1] +["no"]
>> mit.append(G)
>>
>>
>> for i in mit:
>> if i.strip("\n").split("\t")[0] in clubB:
>>   G =lines[-1] +["clubB"]
>> else:
>> G = lines[-1] +["no"]
>>finale.append(G)
>> ###
&g

[Tutor] Help on best way to check resence of item inside list

2014-05-27 Thread jarod...@libero.it
Dear All

clubA= ["mary","luke","amyr","marco","franco","lucia", "sally","genevra","
electra"]
clubB= ["mary","rebecca","jane","jessica","judit","sharon","lucia", "sally","
Castiel","Sam"]

I have a list of names that I would to annotate  in function of presence in
different clubs:

my input files is a long file where I have this :

mary
luke
luigi
jane
jessica
rebecca
luis
à

with open("file.in") as p:
mit = []
for i in p:
   lines =i.strip("\n").split("\t")
   if  (lines[0] in clubA:
  G =lines[-1] +["clubA"]
   else:
   G = lines[-1] +["no"]  
mit.append(G)
  

for i in mit:
   if i.strip("\n").split("\t")[0] in clubB:
 G =lines[-1] +["clubB"]
   else:
   G = lines[-1] +["no"]  
  finale.append(G)
###
I just wonder if is appropriate to use a loops to check if is present the
value on a list. Is it the right way? I can use a dictionary because I have
many repeated names.

In the end I wan to have


mary  clubA clubB
luke clubA
luigi  no
Thanks in advance for any help
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Help merge files using python

2013-11-13 Thread jarod...@libero.it
Hi I want to merge many files like this:
#file1
A   10
B   20
C   30
#file2
B   45
Z   10
#file1
A   60
B   70
C   10

I want to obtain

A 10 0 60
B 20 45 70
C 30 0 10
Z 0 10 0

I try to do like this:
 f = os.listdir(".")
for i in f:
 T =open(i,"r")
for r in t.readlines():
print r

Could you please help me to understand how to use the right procedure in 
python?Thanks a lot!
bw


Messaggio originale
>Da: tutor-requ...@python.org
>Data: 23/10/2013 1.43
>A: 
>Ogg: Tutor Digest, Vol 116, Issue 58
>
>Send Tutor mailing list submissions to
>   tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>   https://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
>You can reach the person managing the list at
>   tutor-ow...@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
>   1. Re: Beginner Question (Andy McKenzie)
>   2. Re: Beginner Question (Dave Angel)
>   3. comma in an assignment (Key, Gregory E (E S SF RNA FSF 1 C))
>   4. Howto handle pictures with pyqt (Ulrich Goebel)
>   5. Re: Beginner Question (Sven Hennig)
>
>
>--
>
>Message: 1
>Date: Tue, 22 Oct 2013 13:26:08 -0400
>From: Andy McKenzie 
>To: "tutor@python.org" 
>Subject: Re: [Tutor] Beginner Question
>Message-ID:
>   
>Content-Type: text/plain; charset="iso-8859-1"
>
>On Tue, Oct 22, 2013 at 10:25 AM, Sven Hennig wrote:
>
>> Hello, I would like to learn a programming language and have decided to
>> use Python. I have some programming experience and doing well in Python.
>> What really causes me problems is OOP.
>> I'm just dont get it... I'm missing a really Practical example. In every
>> book I've read are the examples of such Class Dog and the function is bark
>> . Has anyone an OOP example for me as it is really used in real code, so
>> I can better understand the concept? I do not know why this is so hard for
>> me.
>>
>> Greetings
>> Sven
>>
>>
>The actual code I have is in PHP, so it's not exactly useful to post here,
>but I can give you an outline of a class I used and found useful.  The
>class was created to help me manipulate network subnets in an interface to
>handle DHCP and DNS on a server.
>
>class subnet:
>
>   def __init__(cidr):
>  # Do some stuff with the CIDR notation of the subnet (1.2.3.0/24syntax)
>
>  def netmask:
> # Calculate the netmask and return it (ie, 255.255.255.0)
>
>   def first_ip:
>  # Calculate and return the first IP in the range.
>
>   def last_ip:
>  # Calculate and return the last IP in the range
>
>   def number_of_addresses:
>  # Calculate the number of usable addresses in the range and return
>that value
>
>The benefit to me was that I could create an instance of the subnet object
>for a group (say, "lab_1"), and then pull out various information.  Calling
>"lab_1.first_ip()" returns the first possible IP address.  That was a lot
>more readable and a lot more concise than something like "first_ip(
>1.2.3.0/24)".
>
>
>I hope this helps!
>
>Andy
>-- next part --
>An HTML attachment was scrubbed...
>URL: 
>
>--
>
>Message: 2
>Date: Tue, 22 Oct 2013 17:55:29 + (UTC)
>From: Dave Angel 
>To: tutor@python.org
>Subject: Re: [Tutor] Beginner Question
>Message-ID: 
>Content-Type: text/plain; charset=US-ASCII
>
>On 22/10/2013 10:25, Sven Hennig wrote:
>
>>  Hello, I would like to learn a programming language and have decided to 
use
>> Python. I have some programming experience and doing well in Python. What
>> really causes me problems is OOP.
>> I'm just dont get it... I'm missing a really Practical example. In every
>> book I've read are the examples of such Class Dog and the function is bark. 
Has
>> anyone an OOP example for me as it is really used in real code, so I can
>> better understand the concept? I do not know why this is so hard for me.
>>
>
>What you may not realize is you're already doing OOP, just by using the
>standard library.  When you open a file (or many other things that can
>produce a stream of bytes), you get an instance of class file.  When you
>use that instance, you're calling methods of that instance.  So when you
>say:
>
>infile = open("myfile.txt,"r")
>data = infile.readline()
>
>you're doing object oriented programming.  You don't have to know what
>kind of thing "infile" is, you just have to know it has methods read(),
>readline(), close(), etc.
>
>When you want to write your own classes, or when you want to make a new
>class that's related but different from one of the thousands that are
>standard, that's when it gets interesting.  As Alan says, GUI is one
>place where you'll be wrting your own clas

[Tutor] Read and write list on I file

2013-01-26 Thread jarod...@libero.it
HI there!!!
I have a file like this:

12345-2 ppp
12389-4

i
...

I want to read  this file and organize in different way: The second number
present  after "-" mean the times are ripetuted the elements..so in the 
example
In the end I want to  have this result

12345-1 ppp
12345-2 ppp
12389-1

i
12389-2

i
12389-3

i
12389-4

i
Someone have a suggestion how to do this simple task.. I write some code but
don't do all the think I want.

import re

f = open("file.txt","r")

for item in f:
 if re.match(r'['0-9]',item):
  line=iteme.strip.split("\t")
  num = line[0].split("-")
  key = num[0]
  vl = in(num[1])
  for i in range(1,vl):
 

   else:
   print all line"





thanks in advance for any help!

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor