Let me summarize the facts as I understand them:
As a visiting researcher, you wrote some Python code that
substantially improved the process of collecting and/or processing
the research data. Another student then used this code without your
permission, and the supervisor did not take action when informed of
this.
After you returned home, the student and supervisor wrote a draft
paper based on the collected data, with the intent of publishing it
with you as the first author. They sent you a draft by email.
Throughout the process, you feel aggrieved because (1) the student
used your code without permission, (2) the supervisor was
uncommunicative, and (3) you provided the majority of the
contribution to the paper. Consequently, you are considering
withdrawing yourself from authorship of the paper.
I'm going to answer on the assumption that the above is accurate.
Someone used my code without my permission
To me, this is a surprising thing to be upset about. In my experience
doing research in Computer Science in the U.S. and collaborating with
others in Europe and Japan, it is standard practice to freely share code
among the team, and when ready, to release it publicly under an open
source license.
Code sharing is not just a matter of convenience or social culture, it
is important to the scientific process. Quoting
A survey of researchers’ code sharing and code reuse practices, and assessment of interactive notebook prototypes
by Cadwallader and Hrynaszkiewicz (PeerJ, 2022):
Sharing code improves reproducibility, especially when made available
before publication (Fernández-Juricic, 2021). Lack of source
code—along with raw data, and protocols—has been described as the
main barrier to computational reproducibility of published research
(Seibold et al., 2021).
Sharing and publication of code is not required, but it is expected, and
a different arrangement requires explicit discussion and negotiation
(both among the team and with the employing institutions), ideally in
advance of doing the work. Furthermore, when sharing is not the
intention, the code should carry some sort of notice to that effect.
If I were the collaborating student in your scenario, I would be
somewhat irritated that you had simply left the code in your private
home directory, rather than putting it into a shared repository and
proactively telling the rest of the team about it. (That
said, I still would not have looked into another user's directory
nor used what I found there without prior authorization;
that part is questionable.)
If I were the supervisor in your scenario, I would be confused about why
you were complaining about the student using your code. I think the
supervisor probably should have done a better job at working with you to
understand the issue, explain the local research culture, and come to
a mutually acceptable resolution.
They wrote a paper without me
First, let's review the criteria for authorship on scientific papers.
I'll quote
Guidance on Authorship in Scholarly or Scientific Publications
from the Yale Office of the Provost:
All co-authors should have been directly involved in all three of the
following:
planning and contribution to some component (conception, design,
conduct, analysis, or interpretation) of the work which led to the
paper or interpreting at least a portion of the results;
writing a draft of the article or revising it for intellectual content; and
final approval of the version to be published. All authors should
review and approve the manuscript before it is submitted for
publication, at least as it pertains to their roles in the project.
Some diversity exists across academic disciplines regarding acceptable
standards for substantive contributions that would lead to attribution
of authorship.
You already contributed data for point 1. You've now been sent a draft
to review, satisfying points 2 and 3. So you should be an author,
assuming you follow through by contributing to the draft.
You might feel that the paper is already "done"--it is not! You still
have plenty of opportunity to make major changes if you feel they are
appropriate and valuable. Personally, what I would do in this situation
is read the draft, give it a day, then imagine I was going to present
the work at a conference. What is the most valuable contribution? How
was this achieved? What might be good next steps? Having come up with
your own answers to these and other important questions, now go back to
the draft and ensure it conveys what you feel is important. Change as
much or as little as is required. Then be prepared to work with the
other authors to arrive at a paper you all are satisfied with.
I did all the work
To be blunt: no, you didn't.
At a minimum, the student and supervisor wrote the first draft. The
student also did data analysis; they did so, at least in part, by using
your code, but they still did that work. Data analysis is far more
than just running a script and blindly accepting the output. Whether
that student's contribution is precisely "equal" is unimportant, and
you're not in a position to accurately judge that anyway.
It seems to me that your collaborators are fairly acknowledging your
contributions by making you first author.
They didn't communicate enough
This part seems like a valid complaint. But remember that there are
likely significant cultural differences, and they are probably unsure of
exactly how to collaborate with a foreign researcher. None of the facts
I'm aware of in this situation suggest malice or disrespect.
Furthermore, improving communication can be done by either party. If
you think there's a problem in that regard, start by expressing that (in
a constructive way). Instead of addressing the problem, it seems like
you chose to work really hard on learning and coding, which of course
has its benefits, but in this case led to a build up of resentment.
Conclusions
For this publication, remain as first author, but be sure to earn it by
actively engaging during the writing process (points 2 and 3 of the
authorship criteria). Try to put the science ahead of your personal
misgivings regarding your collaborators.
Going forward, regarding code sharing, either adopt a different attitude
toward sharing, or make it clear to your collaborators and employers
ahead of time that you consider your code to be personal intellectual
property--but that will likely limit your opportunities. And when you
find yourself in a difficult work situation, don't just work harder
while ignoring the problem.