Replicate and rename archives - file-rename

i'm really new in python. I'm trying to replicate and archive and rename with the information from list in csv (Same archive .jpg). Basically i don't know how to paste the information from csv and use to rename the archive.
i've got this
import shutil
import sys
import os
# Abrir archivo de entrada y obtener las lineas del archivo
raw_csv = open(csv_path, "r")
csv_lines = raw_csv.readlines()
for line in raw_csv:()
filename = file.index()
shutil.copy('rename.jpg', '')
enter code here
if somebody can help me, i really appreciate it.

Related

how can i make this script suitable for converting excel files with more than one sheet inside?

import pandas as pd
from xlsx2csv import Xlsx2csv
from io import StringIO
def read_excel(path: str, sheet_name: str) -> pd.DataFrame:
buffer = StringIO() #to read and
Xlsx2csv(path, outputencoding="utf-8", sheet_name=sheet_name).convert(buffer)
buffer.seek(0)
df = pd.read_csv(buffer)
return df
how can i make this script suitable for converting excel files with more than one sheet inside? It works only for xlsx file with one sheet at the moment...
Do you really need to use xlsx2csv module? If not, you could try this with Pandas.
import pandas as pd
for sheet in ['Sheet1', 'Sheet2']:
df = pd.read_excel('sample.xlsx', sheetname=sheet)

Jython scripts doesn't work when executing in ODI

I have an ODI job with a procedure that have 3 Tasks. These tasks are coded in Jython technology. When I execute these scripts using Jython standalone in my PC are working fine, but when I run them from the ODI menu these doesn't make nothing.
The execution is marked as OK and I don't see any error logs in any window.
I checked that code works in jython standalone. Tried with paths using "/", using "\", my folder (Using windows in development mode) has all permissions available.
FILE_NAME = "FILES-100-*-000001.csv"
NAS_FOLDER = "/apps/dataflow/src/"
WORK_FOLDER = "/apps/dataflow/target/"
#Extraemos prefijo y sufijo del fichero a procesar
splitted_value = FILE_NAME.split("*")
prefix = splitted_value[0]
suffix = splitted_value[1]
#Obtenemos listado de ficheros de la ruta del NAS y movemos los que cumplan condiciones al directorio WORK
files = os.listdir(NAS_FOLDER)
for file in files:
if file.find(prefix) >= 0 and file.find(suffix) > 0:
print "Fichero origen: " + NAS_FOLDER+file + " | Fichero destino: " + WORK_FOLDER+file
try:
os.rename(NAS_FOLDER+file, WORK_FOLDER+file)
except:
print("No se ha podido mover el fichero: " + NAS_FOLDER+file)
I expect the files moved succesfully. (These with the correct name and not moved before). I expect see any logs or error info too.
Thanks in advance.

exporting seiral masseges to text file using pyserial

I'm new to python and I've write a simple code that reading lines from serial port and than write those lines to a text file. No errores occured, but the serial masseges did not appear in the text.
the code:
import serial
ser = serial.Serial('COM32', baudrate=115200, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS, xonxoff=1)
text = open("temptext1.txt", "a+")
while 1:
read_line = ser.readline()
print read_line
text.write(read_line)
Thnaks for the helpers, i siriously dont have a clue how to debug this.
Try below code.
import serial
import io
def getSerialLogs(comport, fileName='SerialLog.txt', baudrate=115200):
ser = serial.Serial(comport, baudrate, xonxoff =True, timeout=1)
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser, 1), encoding="utf-8")
with open(fileName, 'a') as f:
while ser.isOpen():
datastring = sio.readline()
f.write(datastring)

How to get sequence description from gi number through biopython?

I have a list of GI (genbank identifier) numbers. How can I get the Sequence description (as 'mus musculus hypothetical protein X') for each GI number so that I can store it in a variable and write it to a file?
Thanks for your help!
This is a script I wrote to pull the entire GenBank file for each genbank identifier in a file. It should be easy enough to change for your applications.
#This program will open a file containing NCBI sequence indentifiers, find the associated
#information and write the data to *.gb
import os
import sys
from Bio import Entrez
Entrez.email = "yourname#xxx.xxx" #Always tell NCBI who you are
try: #checks to make sure input file is in the folder
name = raw_input("\nEnter file name with sequence identifications only: ")
handle = open(name, 'r')
except:
print "File does not exist in folder! Check file name and extension."
quit()
outfile = os.path.splitext(name)[0]+"_GB_Full.gb"
totalhand = open(outfile, 'w')
for line in handle:
line = line.rstrip() #strips \n from file
print line
fetch_handle = Entrez.efetch(db="nucleotide", rettype="gb", retmode="text", id=line)
data = fetch_handle.read()
fetch_handle.close()
totalhand.write(data)
So, in case anybody else had that question, here is the solution:
handle=Entrez.esummary(db="nucleotide, protein, ...", id="gi or NCBI_ref number")
record=Entrez.read(handle)
handle.close()
description=record[0]["Title"]
print description
This will print the sequence description that corresponds to the identifier.

use pandas to retrieve files over FTP

I'm just getting to grips with pandas (which is awesome) and what I need to do is read in compressed genomics type files from ftp sites into a pandas dataframe.
This is what I tried and got a ton of errors:
from pandas.io.parsers import *
chr1 = 'ftp://ftp.ncbi.nih.gov/snp/organisms/human_9606/chr_rpts/chr_1.txt.gz'
CHR1 = read_csv(chr1, sep='\t', compression = 'gzip', skiprows = 10)
print type(CHR1)
print CHR1.head(10)
Ideally I'd like to do something like this:
from pandas.io.data import *
AAPL = DataReader('AAPL', 'yahoo', start = '01/01/2006')
The interesting part of this question is how to stream a (gz) file from ftp, which is discussed here, where it's claimed that the following will work in Python 3.2 (but won't in 2.x, nor will it be backported), and on my system this is the case:
import urllib.request as ur
from gzip import GzipFile
req = ur.Request(chr1) # gz file on ftp (ensure startswith 'ftp://')
z_f = ur.urlopen(req)
# this line *may* work (but I haven't been able to confirm it)
# df = pd.read_csv(z_f, sep='\t', compression='gzip', skiprows=10)
# this works (*)
f = GzipFile(fileobj=z_f, mode="r")
df = pd.read_csv(f, sep='\t', skiprows=10)
(*) Here f is "file-like", in the sense that we can perform a readline (read it line-by-line), rather than having to download/open the entire file.
.
Note: I couldn't get the ftplib library to readline, it wasn't clear whether it ought to.

Resources